0

In my code I load a 32-bit-depth PNG file (1 pixel 4 byte) into a byte array like this:

//Pick a file
OpenFileDialog FileValaszto = new OpenFileDialog();
FileValaszto.ShowDialog();

//Create BitmapImage
BeolvasottKep = new BitmapImage(new Uri(FileValaszto.FileName));

//Create byte array
stride = BeolvasottKep.PixelWidth * 4;
int size = BeolvasottKep.PixelHeight * stride;
MyPixelsArray = new byte[size];
BeolvasottKep.CopyPixels(pixels, stride, 0);

After I finish manipulating the pixels in "MyPixelsArray" I would like to save its data back into a new PNG image file. Only I can't...

I spent more than a day searching the net but there is no solution to this exact problem. Any help would be highly appreciated. Thanks!

Manish Singh
  • 934
  • 1
  • 12
  • 27
  • If you are trying to resize your image, this link maybe helps you http://stackoverflow.com/questions/1922040/resize-an-image-c-sharp – Rumpelstinsk Oct 07 '16 at 08:46
  • Can you explain what do you exactly want to achieve? – Pikoh Oct 07 '16 at 08:53
  • What I want to achieve: 1,Load a PNG file into a bytearray (done) 2, Manipulate this byte array thus changing the picture (done) 3, Save this byte array back into a PNG file on the harddrive. (NOT done, hence the question) – Truckerguy Oct 07 '16 at 08:59
  • 1
    Edit your question and add why you can't. Is it throwing any exception? Does it not compile? Is the result PNG wrong? – Pikoh Oct 07 '16 at 09:55
  • Why not edit the byte of the Bitmap in a LockBits routine?? – TaW Oct 07 '16 at 11:13

1 Answers1

0

Not tested but might work. Try it i hope it help you

 //Pick a file
        OpenFileDialog FileValaszto = new OpenFileDialog();
         FileValaszto .ShowDialog();

        //Create BitmapImage
        BeolvasottKep = new BitmapImage(new Uri(FileValaszto.FileName));

        //Create byte array
        stride = BeolvasottKep.PixelWidth * 4;
        int size = BeolvasottKep.PixelHeight * stride;

        MemoryStream ms = new System.IO.MemoryStream(stride);
        Image i = Image.FromStream(ms);
Manish Singh
  • 934
  • 1
  • 12
  • 27