J
Jeroen Ceuppens
I created new bitmap file, bitmapdata, now a want the pixeldata that are in
the array bytes[] put into the bmpData, what should I change in the code
unsafe? there is something wrong with p[0] = (byte)(bytes[0]); is makes all
the pixel in some color..........
// this code will be replace by a COM who gets a byte array
Stream stream = File.Open(@"d:\ImageWeftIllum.bmp", FileMode.Open);
bytes=new byte[stream.Length];
stream.Read(bytes,0,(int)stream.Length);
mem= new MemoryStream(bytes);
//
Bitmap bmp = new Bitmap(640,480);
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width,
bmp.Height),
ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int stride = bmpData.Stride;
System.IntPtr Scan0 = bmpData.Scan0;
unsafe
{
byte * p = (byte *)(void *)Scan0;
int nOffset = stride - bmp.Width*3;
int nWidth = bmp.Width * 3;
for(int y=0;y < bmp.Height;++y)
{
for(int x=0; x < nWidth; ++x )
{
p[0] = (byte)(bytes[0]);
++p;
}
p += nOffset;
}
}
bmp.UnlockBits(bmpData);
pictureBox1.Image=bmp;
the array bytes[] put into the bmpData, what should I change in the code
unsafe? there is something wrong with p[0] = (byte)(bytes[0]); is makes all
the pixel in some color..........
// this code will be replace by a COM who gets a byte array
Stream stream = File.Open(@"d:\ImageWeftIllum.bmp", FileMode.Open);
bytes=new byte[stream.Length];
stream.Read(bytes,0,(int)stream.Length);
mem= new MemoryStream(bytes);
//
Bitmap bmp = new Bitmap(640,480);
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width,
bmp.Height),
ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int stride = bmpData.Stride;
System.IntPtr Scan0 = bmpData.Scan0;
unsafe
{
byte * p = (byte *)(void *)Scan0;
int nOffset = stride - bmp.Width*3;
int nWidth = bmp.Width * 3;
for(int y=0;y < bmp.Height;++y)
{
for(int x=0; x < nWidth; ++x )
{
p[0] = (byte)(bytes[0]);
++p;
}
p += nOffset;
}
}
bmp.UnlockBits(bmpData);
pictureBox1.Image=bmp;