Image Manipulation c#

Total Post:183


 1756  View(s)
Rate this:

I have the following code which takes an array of bytes which i generated and writes them out to this bitmap. If i set the pixel format to Format4bppIndexed, then i get a readable image repeating width wise 4 times, if i set it to Format1bppIndexed(which is the correct setting) then i get one big unreadable image.

The image was a decoded Jbig2 image , i know the bytes are correct i can't seem to figure out how to get it into a 1bpp readable format.

Does anyone have any advice on that matter

        Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format1bppIndexed);

        //Create a BitmapData and Lock all pixels to be written          

        BitmapData bmpData = bitmap.LockBits(

                             new Rectangle(0, 0, bitmap.Width, bitmap.Height),

                             ImageLockMode.WriteOnly, bitmap.PixelFormat);

        //Copy the data from the byte array into BitmapData.Scan0

        Marshal.Copy(newarray, 0, bmpData.Scan0, newarray.Length);

        //Unlock the pixels


  1. Re: Image Manipulation c#

    Hi Ankita,

    I used the WPF classes instead of the GDI and wrote the code like this

    var bitmap = new WriteableBitmap(width, height, 96, 96,          
    System.Windows.Media.PixelFormats.BlackWhite, null);
    bitmap.WritePixels(new System.Windows.Int32Rect(0, 0, width, height), newarray, stride, 0);    
    MemoryStream stream3 = new MemoryStream();
    var encoder = new TiffBitmapEncoder ();

      Modified On Apr-04-2018 02:25:28 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.