简体   繁体   English

使用ImageTools c#wp8将可写位图转换为Png

[英]Convert Writable Bitmap to Png with ImageTools c# wp8

ive been stuck on this problem for a few days now. 我已经在这个问题上停留了几天。 So ive got this WritableBitmap object which i am using to render out an image (not yet saved), I can use .SaveJpeg to save it as a jpeg file but i need the image to be in png to save the transperency. 因此,我得到了这个WritableBitmap对象,我正在使用它来渲染图像(尚未保存),我可以使用.SaveJpeg将其另存为jpeg文件,但是我需要将图像保存为png来保存透明性。 Here is the code where im creating the WritableBitmap 这是我创建WritableBitmap的代码

var customTile = new PayClock2();
customTile.Measure(new Size(336, 336));
customTile.Arrange(new Rect(0, 0, 336, 336));

var bmp = new WriteableBitmap(336, 365);
bmp.Render(customTile, null);
bmp.Invalidate();

I have tried using ImageTools library, but i cant seem to convert WritableBitmap to Bitmap for it 我尝试使用ImageTools库,但似乎无法将WritableBitmap转换为Bitmap

            var img = bmp.ToImage();

            var encoder = new PngEncoder();
            using (var stream = new IsolatedStorageFileStream(filename, System.IO.FileMode.Create, isf))
            {
                encoder.Encode(img, stream);
                stream.Close();
            }

Any guys here successfully saved A Writable Bitmap to Png before? 之前有人成功将可写位图保存到Png吗?

Thanks in advance 提前致谢

It is quite easy with Tool Stack Png library - http://toolstack.com/libraries/pngwriter With it you can simply call extension method .WritePng() and done. 它与工具集巴库很简单- http://toolstack.com/libraries/pngwriter有了它,你可以简单地调用扩展方法.WritePng()和完成。 I have used it in all projects where I needed to save png files and always without problem. 我已经在所有需要保存png文件的项目中使用了它,并且始终没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM