从奇怪的BitmapSource黑色BMP输出 - 任何想法? [英] Strange bmp black output from BitmapSource - any ideas?

查看:270
本文介绍了从奇怪的BitmapSource黑色BMP输出 - 任何想法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与BGRA字节的图像的byte []数组,我从中产生的BitmapSource像这样:

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

这将显示一个WPF图像元素的罚款。但是,当我再尝试创建从一个的BitmapSource文件:

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

我得到了奇怪的输出取决于所使用的EN codeR:BMP给出了图像的中心的一点点,也许10×10像素的图像黑色,PNG的海洋做同样没有黑色。显示区域看起来就像图像被一个缩略图轮廓裁剪(只是形容visula效应)此外,如果你再打开画图整个画面是存在的,显示的PNG,而不是为BMP版本(IrfanView无法配合这两个文件之一)

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?

推荐答案

你在传递什么样的BitmapEn $ C $铬?你有没有尝试PngBitmapEn codeR?

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

这篇关于从奇怪的BitmapSource黑色BMP输出 - 任何想法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆