---
title: "Image Manipulation c#"  
description: "Image Manipulation c#"  
author: "Anonymous User"  
published: 2014-01-30  
updated: 2014-01-30  
canonical: https://www.mindstick.com/forum/1919/image-manipulation-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Image Manipulation c#

I have the following code which [takes an array](https://www.mindstick.com/forum/157801/write-a-javascript-program-that-takes-an-array-of-numbers-and-returns-the-highest-number) of bytes which i generated and writes them out to this [bitmap](https://www.mindstick.com/forum/1924/find-image-format-using-bitmap-object-in-c-sharp). If i set the [pixel](https://www.mindstick.com/interview/33859/how-to-create-pixel-counter-in-javascipt) [format](https://www.mindstick.com/forum/162083/how-to-convert-ost-files-into-pst-format) to Format4bppIndexed, then i get a readable [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) 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](https://yourviews.mindstick.com/view/87536/what-are-ghosts-jobs-and-how-to-figure-out-them) out how to get it into a 1bpp readable format.

Does [anyone](https://www.mindstick.com/articles/23207/how-to-find-the-best-fit-job-for-anyone) have any [advice](https://yourviews.mindstick.com/view/50528/filament-advice-5-things-to-consider-before-you-buy-a-filament) 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](https://www.mindstick.com/forum/33877/char-array-to-byte-array-conversion-and-convert-back-again-to-char-arrray) into BitmapData.Scan0

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

//Unlock the pixels

bitmap.UnlockBits(bmpData);

## Replies

### Reply by Pravesh Singh

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);
```


---

Original Source: https://www.mindstick.com/forum/1919/image-manipulation-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
