Strange bmp black output from BitmapSource - any ideas?

ⅰ亾dé卋堺 提交于 2019-12-12 04:06:15

问题


I have a byte[] array with the bgra bytes of an image, from which I produce a BitmapSource like so:

BitmapSource bmsOut = BitmapSource.Create(
iPixelWidth, iPixelHeight, 96, 96, PixelFormats.Bgra32, null, bytOutput, iStride);      

this displays fine on an wpf Image element. HOWEVER, when I then try to create a file from the BitmapSource:

private void mtdSave(BitmapSource bitmapSource, string path, BitmapEncoder encoder)
          {
              using (var stream = new FileStream(path, FileMode.Create))
              {
                  encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
                  encoder.Save(stream);
              }
          }

I get strange output dependent on the encoder used: bmp gives a little, maybe 10x10 pixel image of the centre of the image in a sea of black, png does the same without the black. The displayed area looks as if the picture has been cropped by a thumbnail outline (just to describe the visula effect) Furthermore, if you then open the png in Paint the whole picture is there and displayed, but not for the bmp version (Irfanview cannot cope with either of the files)

What is going on? What am I missing?


回答1:


What kind of BitmapEncoder are you passing in? Did you try a PngBitmapEncoder?



来源:https://stackoverflow.com/questions/8881830/strange-bmp-black-output-from-bitmapsource-any-ideas

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!