在 Silverlight 中获取 .png 像素数据
我们有一个 Silverlight 应用程序需要加载许多 .png 文件。 我们可以正常加载图像,但 Silverlight 不支持从 Image 类读取像素数据。
谁能建议一个简单的解决方案来获取这些数据? 我们当前最好的选择是第三方 .png 加载库,但我们很难找到合适的库。
We have a Silverlight application that needs to load a number of .png files. We can load the images OK, but Silverlight doesn't support reading the pixel data from the Image class.
Can anyone suggest a simple solution for getting at this data? Our current best bet would be a third party .png loading library, but we are having trouble finding a suitable one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Silverlight 中没有用于执行基于像素的图像操作/生成的内置类。 您需要实现自己的 PNG 编码器/解码器,该编码器/解码器适用于包含图像信息的字节数组。 Joe Stegman 已经实现了一种这样的编码器,您应该检查一下。 他在 http://blogs.msdn.com/ 上获得了大量有关 Silverlight 中“可编辑图像”的重要信息jstegman/。 他所做的事情包括对图像应用滤镜、生成曼德尔布罗等等。
本博客讨论了 JPEG Silverilght 编码器 (FJCore),您可以使用它来调整大小和重新压缩照片客户端大小:http://fluxcapacity.net/2008/07/14/fjcore-to-the-rescue/
另一个工具是“Fluxify”,它可以让您使用 Silverilght 2 调整照片大小和上传照片。可以在 http://fluxtools.net/ 找到
所以是的,客户端图像处理绝对可以在 Silverilght 中完成2. 黑客快乐!
There is no built in classes for doing pixel based imagine manipulation/generation i n Silverlight. You need to implement your own PNG Encoder/Decoder that works on an byte array containing the image information. Joe Stegman has implemented one such encoder you should check out. He got lots of great information about "editable images" in Silverlight over at http://blogs.msdn.com/jstegman/. He does things like applying filters to images, generating mandlebrots and more.
This blog discuss a JPEG Silverilght Encoder (FJCore) you can use to resize and recompress photos client size: http://fluxcapacity.net/2008/07/14/fjcore-to-the-rescue/
Another tool is "Fluxify" which lets you resize and upload photos using Silverilght 2. Can be found over at http://fluxtools.net/
So yes, client side image processing can definitely be done in Silverilght 2. Happy hacking!
PNG解码很难找到。
我为 MSDN 写了一篇文章,其中包括我从 Joe Stegman、FluxCapacity 和其他一些人那里拼凑而成的一些开源代码。 它包括 PNG 解码(以及 GIF、JPG 和 BMP),供本线程中正在寻找该解码的人使用。
http://www.microsoft.com/youshapeit/msdn/ ExpertKnowledge/2008-10/InnovateWithSilverlight2.aspx
如果您不关心我在 Silverlight 上的实现,那么您可以直接转到我针对 PNG 解码所做的修改:http://sourceforge.net/projects/pr2/
干杯!
更新:看起来他们不再在网站上提供源代码,所以我在这里重新发布了内容:
http://dimebrain.com/2009/ 01/innovate-with-silverlight-2-article-code-available.html
PNG decoding is hard to find.
I wrote an article for MSDN that includes some open source code I cobbled together from Joe Stegman, FluxCapacity, and a few others. It includes PNG decoding (as well as GIF, JPG, and BMP) for those in this thread that are looking for that.
http://www.microsoft.com/youshapeit/msdn/ExpertKnowledge/2008-10/InnovateWithSilverlight2.aspx
If you don't care for my implementation of it for Silverlight, then you can go straight to what I modified for PNG decoding: http://sourceforge.net/projects/pr2/
Cheers!
Update: It looks like they no longer offer the source code on the site, so I re-posted the content here:
http://dimebrain.com/2009/01/innovate-with-silverlight-2-article-code-available.html
谢谢 - 我看过乔·斯特格曼的博客。 很方便,但是他没有的解码器是PNG的。 我们使用 PNG 是因为我们需要透明度。 Fluxtools 链接似乎也已损坏。
我仍在寻找(未成功)可以放入 Silverlight 的 PNG 解码器。
Thanks - I've seen the Joe Stegman blog. It's very handy, but the decoder he doesn't have is a PNG one. We're using PNGs as we need transparency. The fluxtools link seems to be broken too.
I'm still looking (unsuccessfully) for a PNG decoder I can drop into Silverlight.
一种可能(根据情况)更容易的选择是分别保存颜色数据和透明度数据,然后在加载图像后以编程方式将透明度应用到图像。 这样,您可以将图像保存为表示 Alpha 通道的 8 位 gif,再加上 jpg 或 bmp 或其他颜色数据。
One option that may (depending on circumstances) be easier is to save the color data and transparency data separately, then programmatically apply the transparency to the image once you have it loaded. That way, you could save the image as a 8-bit gif representing the alpha channel, plus a jpg or bmp or whatever for the color data.
Dimebrain - 您提供的 msdn 链接没有指向源代码的有效链接 - 您有机会找到有效源代码的链接吗?
Dimebrain - that msdn link you provided doesn't have a valid link to the sourcecode - any chance you have a link to the source that works?