string Convert(string inFileName,string outFilename )
{
System.IO.FileStream outFile,inFile;
int j;
outFile=new System.IO.FileStream(outFileName,System.IO.FileMode.Create,System.IO.FileAccess.Write) ;
string str= "0605041582000064F00000480E01";
outFile.Write(str); inFile=new System.IO.FileStream(inFileName,System.IO.FileMode.Open,System.IO.FileAccess.Read) ; if(inFile==null)//本判断可能有问题
{
System.Console.Write(inFileName+" Input File Open Error!\n");
return "";
} int b; for( b = 0;b < 14;b++)
{
if(inFile.Length>118+36*(13-b))
{
inFile.Position=118+36*(13-b);
//BEGIN
byte[] tmp=new byte[4];
for(int i = 0;i < 9; i++)
{
if(inFile.Read(tmp,0,4)>0)
{
int tmpHex = Str2Hex(tmp.ToString()); //可以直接写入,本语句多余
outFile.Write(tmp,0,4);
//fprintf(outFile, "%02x", tmpHex);//直接写入字节流即可,不必要使用
}
else
break;
}
//END
//以上BEGIN和END之间的语句可以使用下面的语句:
//
//byte[] tmp=new byte[36];
//int readLen=inFile.Read(tmp,0,36);
//if(readLen>0)
// outFile.Write(tmp,0,readLen);
//
//代替
}
} outFile.Close();
inFile.Close();
System.IO.FileStream otbstr=new System.IO.FileStream(outFileName,System.IO.FileMode.Open,System.IO.FileAccess.Read); if(otbstr==null)//本判断可能有问题
{
System.Console.Write(OutFileName+" Input File Open Error!\n");
return "";
} //BEGIN
byte[] buffer=new byte[280];
int i;
byte ch; ch = otbstr.ReadByte();
for( i=0; (i < 280 ) && ( otbstr.Position<otbstr.Length); i++ )
{
buffer[i] = ch;
ch = otbstr.ReadByte();
}
//END
//上面BEGIN和END之间的代码可以简单的使用:otbstr.Read(buffer,0,buffer.Length);实现 System.Console.WriteLine(buffer.ToString());
otbstr.Close(); return buffer.ToString();
} int Str2Hex(string str)
{
int hex = 0;
for(int i = 3; i >= 0; i--)
{
int lowByte = ((int)(str.Substring(i,1)))%16;
hex += lowByte * pow(2, 8 - ( i + 1 ) * 2); //pow功能不明
int highByte = ((int)(str.Substring(i,1)))/16;
hex += highByte * pow( 2, 8 - ( i + 1 ) * 2 + 1); //pow功能不明
}
return hex;
}
[STAThread]
static void Main(string[] args) //C#中的主函数,只有一个参数,必须是静态的
{
string infilename = "test3.bmp";
string outfilename = "bmp2yyr";
Convert(infilename, outfilename);
}
{
System.IO.FileStream outFile,inFile;
int j;
outFile=new System.IO.FileStream(outFileName,System.IO.FileMode.Create,System.IO.FileAccess.Write) ;
string str= "0605041582000064F00000480E01";
outFile.Write(str); inFile=new System.IO.FileStream(inFileName,System.IO.FileMode.Open,System.IO.FileAccess.Read) ; if(inFile==null)//本判断可能有问题
{
System.Console.Write(inFileName+" Input File Open Error!\n");
return "";
} int b; for( b = 0;b < 14;b++)
{
if(inFile.Length>118+36*(13-b))
{
inFile.Position=118+36*(13-b);
//BEGIN
byte[] tmp=new byte[4];
for(int i = 0;i < 9; i++)
{
if(inFile.Read(tmp,0,4)>0)
{
int tmpHex = Str2Hex(tmp.ToString()); //可以直接写入,本语句多余
outFile.Write(tmp,0,4);
//fprintf(outFile, "%02x", tmpHex);//直接写入字节流即可,不必要使用
}
else
break;
}
//END
//以上BEGIN和END之间的语句可以使用下面的语句:
//
//byte[] tmp=new byte[36];
//int readLen=inFile.Read(tmp,0,36);
//if(readLen>0)
// outFile.Write(tmp,0,readLen);
//
//代替
}
} outFile.Close();
inFile.Close();
System.IO.FileStream otbstr=new System.IO.FileStream(outFileName,System.IO.FileMode.Open,System.IO.FileAccess.Read); if(otbstr==null)//本判断可能有问题
{
System.Console.Write(OutFileName+" Input File Open Error!\n");
return "";
} //BEGIN
byte[] buffer=new byte[280];
int i;
byte ch; ch = otbstr.ReadByte();
for( i=0; (i < 280 ) && ( otbstr.Position<otbstr.Length); i++ )
{
buffer[i] = ch;
ch = otbstr.ReadByte();
}
//END
//上面BEGIN和END之间的代码可以简单的使用:otbstr.Read(buffer,0,buffer.Length);实现 System.Console.WriteLine(buffer.ToString());
otbstr.Close(); return buffer.ToString();
} int Str2Hex(string str)
{
int hex = 0;
for(int i = 3; i >= 0; i--)
{
int lowByte = ((int)(str.Substring(i,1)))%16;
hex += lowByte * pow(2, 8 - ( i + 1 ) * 2); //pow功能不明
int highByte = ((int)(str.Substring(i,1)))/16;
hex += highByte * pow( 2, 8 - ( i + 1 ) * 2 + 1); //pow功能不明
}
return hex;
}
[STAThread]
static void Main(string[] args) //C#中的主函数,只有一个参数,必须是静态的
{
string infilename = "test3.bmp";
string outfilename = "bmp2yyr";
Convert(infilename, outfilename);
}
解决方案 »
- CuteEditor不可用,怎么办?在Page_Load里response.write后就可以用了,不知为什么?
- 利用operator声明且仅声明了“==”,有什么错误 么 ?
- 多线程填充DATAGRRIVIEW遇到问题
- 怎么识别SQL server数据库语句? ?
- 关于 TextBox 数据绑定到 INT 类型 时的困难
- 弱弱的问一个关于Get访问器的问题?
- 怎么把摄象头捕捉到的每一桢存在磁盘中
- 100分求解,遇到一个极度奇怪的问题~~~!!!
- 把C/C++中的结构体(包含位域,即冒号用法)转换成C#中的结构体。
- CustomCalendarItem locked属性没有效果
- 请大家注意[散分]的问题.
- 十万火急!各位大虾,在web页面中有没有可能不让BUTTON按钮不刷新页面,(在线等待.....)
{
System.IO.FileStream outFile,inFile;
int j; outFile=new System.IO.FileStream(outFileName,System.IO.FileMode.Create,System.IO.FileAccess.Write) ;
string str= "0605041582000064F00000480E01";
outFile.Write(str); inFile=new System.IO.FileStream(inFileName,System.IO.FileMode.Open,System.IO.FileAccess.Read) ; if(inFile==null)//本判断可能有问题
{
System.Console.Write(inFileName+" Input File Open Error!\n");
return "";
} int b; for( b = 0;b < 14;b++)
{
if(inFile.Length>118+36*(13-b))
{
inFile.Position=118+36*(13-b);
//BEGIN
byte[] tmp=new byte[4];
for(int i = 0;i < 9; i++)
{
if(inFile.Read(tmp,0,4)>0)
{
int tmpHex = Str2Hex(tmp.ToString()); //可以直接写入,本语句多余
outFile.Write(tmp,0,4);
//fprintf(outFile, "%02x", tmpHex);//直接写入字节流即可,不必要使用
}
else
break;
}
//END
//以上BEGIN和END之间的语句可以使用下面的语句:
//
//byte[] tmp=new byte[36];
//int readLen=inFile.Read(tmp,0,36);
//if(readLen>0)
// outFile.Write(tmp,0,readLen);
//
//代替
}
} outFile.Close();
inFile.Close(); System.IO.FileStream otbstr=new System.IO.FileStream(outFileName,System.IO.FileMode.Open,System.IO.FileAccess.Read); if(otbstr==null)//本判断可能有问题
{
System.Console.Write(OutFileName+" Input File Open Error!\n");
return "";
} //BEGIN
byte[] buffer=new byte[280];
int i;
byte ch; ch = otbstr.ReadByte();
for( i=0; (i < 280 ) && ( otbstr.Position<otbstr.Length); i++ )
{
buffer[i] = ch;
ch = otbstr.ReadByte();
}
//END
//上面BEGIN和END之间的代码可以简单的使用:otbstr.Read(buffer,0,buffer.Length);实现 System.Console.WriteLine(buffer.ToString()); otbstr.Close(); return buffer.ToString();
}int Str2Hex(string str)
{
int hex = 0;
for(int i = 3; i >= 0; i--)
{
int lowByte = ((int)(str.Substring(i,1)))%16;
hex += lowByte * pow(2, 8 - ( i + 1 ) * 2); //pow功能不明
int highByte = ((int)(str.Substring(i,1)))/16;
hex += highByte * pow( 2, 8 - ( i + 1 ) * 2 + 1); //pow功能不明
}
return hex;
}
[STAThread]
static void Main(string[] args) //C#中的主函数,只有一个参数,必须是静态的
{
string infilename = "test3.bmp";
string outfilename = "bmp2yyr";
Convert(infilename, outfilename);
}
这样,还是要使用下面的代码:byte[] tmp=new byte[4];
for(int i = 0;i < 9; i++)
{
if(inFile.Read(tmp,0,4)>0)
{
int tmpHex = Str2Hex(tmp.ToString()); //可以直接写入,本语句多余
outFile.Write(tmp,0,4);
//fprintf(outFile, "%02x", tmpHex);//直接写入字节流即可,不必要使用
}
else
break;
}不过要修改为:byte[] tmp=new byte[4];
for(int i = 0;i < 9; i++)
{
if(inFile.Read(tmp,0,4)>0)
{
string tmpHex = Str2Hex(tmp.ToString()).ToString();
tmpHex="0000".Substring(1,4-tmpHex.Length)+tmpHex;
outFile.Write(tmpHex.ToCharArray(),0,4);
//fprintf(outFile, "%02x", tmpHex);//直接写入字节流即可,不必要使用
}
else
break;
}