读取图片的DLL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlTypes;
using System.Drawing;
using System.IO;
namespace NJ_MF_ClassLib
{
public class tif
{
//private System.Windows.Forms.PictureBox pictureBox1;
public static byte[] tiftojpg(byte[] _bin)
{
// System.Windows.Forms.PictureBox picbox = new System.Windows.Forms.PictureBox();
// System.IO.BinaryReader binReader = new System.IO.BinaryReader();
// binReader.Read();
// Stream s = new MemoryStream();
// SqlBytes bytes = new SqlBytes(_bin);
// System.IO.File.WriteAllBytes(@"C:\a.bin", newBin);
// StreamWriter sw = new StreamWriter(@"C:\1.txt", true);
// sw.WriteLine("111111111111");
// sw.WriteLine(_bin.Length.ToString());
// memorystream.Read(byteFileflag,0,2);
// byteFileflag.Equals(0x4949);
// picbox.Image = System.Drawing.Image.FromStream(s);
// System.IO.File.WriteAllBytes(@"C:\a.bin", newBin);
// bmp2.Save(@"C:\test.jpg");
//----------------------------------------------
if (_bin == null)
return _bin;
byte[] newBin = new byte[_bin.Length-7];
Array.Copy(_bin,7, newBin, 0,newBin.Length);
byte[] byteFileflag = new byte[2];
Array.Copy(newBin, 0, byteFileflag, 0, 2);
byte byteFlag = byteFileflag[0];
if (byteFlag == 0x49)
{
MemoryStream memorystream = new MemoryStream(newBin);
memorystream.Position = 0;
MemoryStream retMemoryStream = new MemoryStream();
Bitmap bmp = new Bitmap(memorystream);
bmp.Save(retMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] retBinary = new byte[retMemoryStream.Length];
retMemoryStream.Position = 0;
retMemoryStream.Read(retBinary, 0, (int)retMemoryStream.Length);
retMemoryStream.Close();
retMemoryStream.Dispose();
memorystream.Close();
memorystream.Dispose();
return retBinary;
}
else
{
return newBin;
}
}
static int IndexOf(byte[] s, byte[] pattern)
{
int slen = s.Length;
int plen = pattern.Length;
for (int i = 0; i <= slen - plen; i++)
{
for (int j = 0; j < plen; j++)
{
if (s[i + j] != pattern[j]) goto next;
}
return i;
next: ;
}
return -1;
}
}
}