简体   繁体   中英

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. Here is the code where im creating the 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

            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?

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. I have used it in all projects where I needed to save png files and always without problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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