简体   繁体   English

如何在wp7中保存透明背景的位图图像

[英]How to save bitmap image with transparent background in wp7

Hello Everyone I am new to wp7. 大家好,我是wp7的新手。

My issue is I'm saving bitmap image but the background of the image is not Transparent. 我的问题是我正在保存位图图像,但图像的背景不是透明的。 See my code below: 请参阅下面的代码:

IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(fileName);

var bitmap = new WriteableBitmap(500, 700);
bitmap.Render(paint, null);
bitmap.Invalidate();

WriteableBitmap wb = new WriteableBitmap(bitmap);

wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
fileStream.Close();

How can I save a bitmap image with a transparent background ? 如何使用透明背景保存位图图像?

JPEG files do not allow transparency. JPEG文件不允许透明。 GIF and PNG formats do. GIF和PNG格式。

So what you may do is save files into PNG or GIF formats. 所以你可以做的是将文件保存为PNG或GIF格式。 Take a look at the ImageTools library on Codeplex . 看看Codeplex上的ImageTools库 Using this library it is quite easy to save your bitmap data into a format that keeps the transparency information. 使用此库可以非常轻松地将位图数据保存为保持透明度信息的格式。

The post is a bit old, but Jaime Rodriguez wrote an example using this library: http://blogs.msdn.com/b/jaimer/archive/2010/11/23/working-with-gif-images-in-windows-phone.aspx . 帖子有点旧,但是Jaime Rodriguez用这个库写了一个例子: http//blogs.msdn.com/b/jaimer/archive/2010/11/23/working-with-gif-images-in-windows -phone.aspx I would have posted the interesting bit of code here, but unfortunately Skydrive is blocked by my proxy :-) 我会在这里发布有趣的代码,但不幸的是Skydrive被我的代理阻止了:-)

You may be interested in checking out the differences between the three formats I mentioned above in a dated but still valid article on SitePoint: http://www.sitepoint.com/gif-png-jpg-which-one-to-use/ 您可能有兴趣查看我在上面提到的三种格式之间的差异,这些格式在SitePoint的日期但仍然有效的文章中: http//www.sitepoint.com/gif-png-jpg-which-one-to-use/

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

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