my job for c#
public static void ACADIconPreview(String strFile , PictureBox picBox )
{
int Num1 = 1;
Image imgVal1 = null;
System.IO.FileStream fs = new FileStream(strFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
BinaryReader r = new BinaryReader(fs);
// Get the image position in the DWG file
long l = byte.Parse("D", NumberStyles.AllowHexSpecifier);
r.BaseStream.Seek(l, SeekOrigin.Begin);
int imgPos = r.ReadInt32 ();
r.BaseStream.Seek(imgPos, SeekOrigin.Begin);
// Image sentinel to check if the image data
// is not corrupted
Encoding unicode = Encoding.Unicode;
Byte[] imgBSentinel = { byte.Parse("1F", NumberStyles.AllowHexSpecifier),
byte.Parse("25", NumberStyles.AllowHexSpecifier),
byte.Parse("6D", NumberStyles.AllowHexSpecifier),
byte.Parse("7", NumberStyles.AllowHexSpecifier), byte.Parse("D4", NumberStyles.AllowHexSpecifier),
byte.Parse("36", NumberStyles.AllowHexSpecifier), byte.Parse("28", NumberStyles.AllowHexSpecifier),
byte.Parse("28", NumberStyles.AllowHexSpecifier), byte.Parse("9D", NumberStyles.AllowHexSpecifier), byte.Parse("57", NumberStyles.AllowHexSpecifier),
byte.Parse("CA", NumberStyles.AllowHexSpecifier),
byte.Parse("3F", NumberStyles.AllowHexSpecifier), byte.Parse("9D", NumberStyles.AllowHexSpecifier),
byte.Parse("44", NumberStyles.AllowHexSpecifier), byte.Parse("10", NumberStyles.AllowHexSpecifier),
byte.Parse("2B", NumberStyles.AllowHexSpecifier)
};
// Read Image sentinel
Byte[] imgCSentinel = new Byte[16];
imgCSentinel = r.ReadBytes(16);
// if image sentinel is correct
if (imgBSentinel.ToString() == imgCSentinel.ToString())
{
// Get image size
int imgSize = r.ReadInt32 ();
// Get number of images present
Byte imgPresent = r.ReadByte();
// header
int imgHeaderStart = 0;
int imgHeaderSize = 0;
// bmp data
int imgBmpStart = 0;
int imgBmpSize = 0;
bool bmpDataPresent = false;
// wmf data
int imgWmfStart , imgWmfSize ;
bool wmfDataPresent = false;
// get each image present
for(int Iint = 0 ; Iint < imgPresent; Iint++)
{
Byte imgCode = r.ReadByte();
switch(imgCode)
{
case 1:
// Header data
imgHeaderStart = r.ReadInt32 ();
imgHeaderSize = r.ReadInt32();
break;
case 2:
// bmp data
imgBmpStart = r.ReadInt32();
imgBmpSize = r.ReadInt32();
bmpDataPresent = true;
break;
case 3:
// wmf data
imgWmfStart = r.ReadInt32();
imgWmfSize = r.ReadInt32();
wmfDataPresent = true;
break;
default:
break;
}
}
if (bmpDataPresent)
{
r.BaseStream.Seek(imgBmpStart, SeekOrigin.Begin);
Byte[] tempPixelData =new byte[imgBmpSize + 14];
// indicate it is a bit map
tempPixelData[0] = byte.Parse("H42", CultureInfo.InvariantCulture);
tempPixelData[1] = byte.Parse("H4D", CultureInfo.InvariantCulture);
// offBits
tempPixelData[10] = byte.Parse("H36", CultureInfo.InvariantCulture);
tempPixelData[11] = byte.Parse("H4", CultureInfo.InvariantCulture);
Byte[] tempBuffData = new byte[imgBmpSize] ;
tempBuffData = r.ReadBytes(imgBmpSize);
tempBuffData.CopyTo(tempPixelData, 14);
MemoryStream memStream = new MemoryStream(tempPixelData);
Bitmap bmp = new Bitmap(memStream);
Size szBmp = new System.Drawing.Size();
szBmp.Width = picBox.Width;
szBmp.Height = picBox.Height;
Bitmap bmpResize = new Bitmap(bmp, szBmp) ;
picBox.Image = bmpResize;
}
// read imgWmfSize wmf data
if (wmfDataPresent)
{}
Byte[] imgESentinel = {byte.Parse("E0", NumberStyles.AllowHexSpecifier),
byte.Parse("DA", NumberStyles.AllowHexSpecifier), byte.Parse("92", NumberStyles.AllowHexSpecifier),
byte.Parse("F8", NumberStyles.AllowHexSpecifier), byte.Parse("2B", NumberStyles.AllowHexSpecifier),
byte.Parse("C9", NumberStyles.AllowHexSpecifier), byte.Parse("D7", NumberStyles.AllowHexSpecifier),
byte.Parse("D7", NumberStyles.AllowHexSpecifier), byte.Parse("62", NumberStyles.AllowHexSpecifier),
byte.Parse("A8", NumberStyles.AllowHexSpecifier), byte.Parse("35", NumberStyles.AllowHexSpecifier),
byte.Parse("C0", NumberStyles.AllowHexSpecifier), byte.Parse("62", NumberStyles.AllowHexSpecifier),
byte.Parse("BB", NumberStyles.AllowHexSpecifier), byte.Parse("EF", NumberStyles.AllowHexSpecifier),
byte.Parse("D4", NumberStyles.AllowHexSpecifier)};
imgCSentinel = r.ReadBytes(16);
// if image sentinel is correct
if (imgESentinel.ToString() == imgCSentinel.ToString())
{}
}
fs.Close();
}