c# - 字节数组到png文件

时间:2016-10-07 08:43:04

标签: c# arrays png

在我的代码中,我将一个32位深度的PNG文件(1像素4字节)加载到一个字节数组中,如下所示:

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

在完成“MyPixelsArray”中的像素操作后,我想将其数据保存回新的PNG图像文件中。只有我不能......

我花了一天多的时间搜索网络,但没有解决这个问题的方法。任何帮助将受到高度赞赏。谢谢!

1 个答案:

答案 0 :(得分:0)

未经测试但可能有效。 试试吧我希望它可以帮到你

 //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);
相关问题