Bitmaps are dword aligned. You must account for these dword boundaries with
every scanline that you copy.
For example:
// bitmaps are upside down
IntPtr startOfScanline =
(IntPtr)(d.Scan0.ToInt32()+((d.Height-1-scanlineNo)*d.Stride));
[quoted text, click to view] "Matteo" <matteo.piccioni@katamail.com> wrote in message
news:1148466161.073253.19230@j73g2000cwa.googlegroups.com...
> Hi,
> i sent image byte via bt from j2me phone to c# application,
> after i have to create image using this code:
>
> ...
> byte[] pixels
> ...
>
> Bitmap bmp = new Bitmap(160, 120, PixelFormat.Format8bppIndexed);
>
> BitmapData d = bmp.LockBits(new Rectangle(0, 0, 160, 120),
> ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
>
> // image data is pixel
> Marshal.Copy(pixels, 0, d.Scan0, pixels.Length);
>
> bmp.UnlockBits(d);
>
> // Grey-Scale Palette works
> /*
> ColorPalette cp = bmp.Palette;
> for (int i = 0; i < cp.Entries.Length; i++)
> cp.Entries[i] = Color.FromArgb(i, i, i);
> bmp.Palette = cp;
> */
>
> this.pictureBox1.Image = bmp;
>
> bmp.Save("C:\\img.bmp");
>
> -----------------
>
> The image that i save has all wrong color...
> If i use other than Format8bppIndexed i have smaller size image
> repeated on 160x120 pixel with color wrong too
>
> Can someone helps me?
>
> (sorry for bad english)
>
> Thanks
>