views:

1407

answers:

5

Hi all,

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.

+3  A: 

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!

Jonas Follesø
Unfortunately it appears that http://fluxtools.net is now a link farm.
Chui Tey
A: 

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.

George Sealy
A: 

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.

sep332
+2  A: 

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

Daniel Crenna
Hi, The link you your article isn't working anymore. Is there any other location I can find it? Thanks.
Sorskoot
Hi, it's updated now. Looks like it went to the archive bucket pretty quickly.
Daniel Crenna
A: 

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?