简体   繁体   English

将BitmapImage转换为WritableBitmap Windows Phone 8.1 RT(运行时)

[英]Convert BitmapImage to WritableBitmap Windows phone 8.1 RT(runtime)

I need to gray scale a image before it gets displayed. 我需要对图像进行灰度显示。 Image is coming from server. 图像来自服务器。 I used BitmapImage as a Source of Image. 我使用BitmapImage作为图像Source I am able to show image using BitmapImage . 我可以使用BitmapImage显示图像。

Now I need to grayscale image, for that I found that WritableBitmap can be used to convert it to grayscale. 现在我需要对图像进行灰度处理,为此我发现WritableBitmap可用于将其转换为灰度。 I used WritableBitmapEx.WinRT library for gray scale. 我将WritableBitmapEx.WinRT库用于灰度。

but the issue is I am not able to convert BitmapImage to WritableBitmap in WinRT. 但是问题是我无法在WinRT中将BitmapImage转换为WritableBitmap

Any suggestions are welcome. 欢迎任何建议。

Thanks 谢谢

Use a WriteableBitmap instead of the BitmapImage to begin with. 首先使用WriteableBitmap而不是BitmapImage。 Other than access to the PixelBuffer they can be used almost identically. 除了访问PixelBuffer以外,它们几乎可以完全相同地使用。

You can't directly extract the pixels from a BitmapImage. 您不能直接从BitmapImage中提取像素。 All of the reasonable methods to "convert" a BitmapImage to a WritableBitmap get the data from the original source. 所有将BitmapImage“转换”为WritableBitmap的合理方法均从原始源获取数据。 If you can't get the original UriSource (since you loaded from stream) and don't have the stream available to reload from you're out of luck. 如果您无法获得原始的UriSource(因为您是从流中加载的),并且没有流可用于从中重新加载,那么您很不走运。

The only other (ugly) option is to snapshot the Image with RenderTargetBitmap 唯一的其他选择(丑陋)是使用RenderTargetBitmap对图像进行快照

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

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