Home > DeveloperSection > Forums > Image Manipulation c#
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    January-30-2014 11:00 PM

 C# C# 
Ratings:


 1 Reply(s)
 879  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

        bitmap.UnlockBits(bmpData);



Pravesh Singh

Total Post:411

Points:2881
Posted on    January-30-2014 11:27 PM

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 ();

encoder.Frames.Add(BitmapFrame.Create(bitmap));

encoder.Save(stream3);


Don't want to miss updates? Please click the below button!

Follow MindStick