Image processing in Silverlight 2 - silverlight

Is it possible to do image processing in silverlight 2.0?
What I want to do is take an image, crop it, and then send the new cropped image up to the server. I know I can fake it by clipping the image, but that only effects the rendering of the image. I want to create a new image.
After further research I have answered my own question. Answer: No. Since all apis would be in System.Windows.Media.Imaging and that namespace does not have the appropriate classes in Silverlight
I'm going to use fjcore. http://code.google.com/p/fjcore/
Thanks Jonas

Well, you can actually do local image processing in Silverlight 2... But there are no built in classes to help you. But you can load any image into a byte array, and start manipulating it, or implement your own image encoder.
Joe Stegman 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 definetly be done in Silverilght 2. Happy hacking!

I know this doesn't directly answer your question, but what if you do all of the clipping on the client side to crop the image, then send the server the original image and the coordinates for clipping. Then on the server side, which will probably more suited for image manipulation like this (e.g. PHP it's very easy) you'll do the actual cropping of the image and storing the cropped version.

There is first-class support for bitmap surfaces in Silverlight 3: http://blogs.msdn.com/kaevans/archive/2009/03/20/some-silverlight-3-goodness-using-writeablebitmap.aspx

Related

Using 3D photos in silverlight?

I want use photos captured by 3D cameras in Silverlight 3 or 4.
I want use that photos like in maps.google.com. Is it possible to do with silverlight and if yes is there any book, tutorial, video or anything alse, from which I can learn how to use tham.
Thanks.
It is possible to convert a stereoscopic images to an Anaglyph in Silverlight.
Have a watch of this video from Mix10 Moving at 60fps. You want to be 55 minutes into the video (its mainly about video but the principles are the same).
Unfortunately Eric doesn't provide any access to the pixel shader in question.
Check this demo out. It comes with full source code:
http://www.evanjohnston.com/post/Silverlight-4-Webcams-to-the-3rd-Dimension.aspx
They use two webcams and red- and green-filter pixel shaders to separate the streams. Of course the same can be used for static images.
It can be done with panoramic images.
Here is example for cylindric images.

Display 360 Image in Silverlight 3.0 (Not Panorama)

I have a lot of images taken from a 360 camera which I would like to be able to display in Silverlight 3. They are NOT regular panorama images. The camera which took the image actually creates a distorted jpeg that becomes undistorted once wrapped around a sphere as a texture. I have desktop software that will allow viewing of the image (not just side-to-side, but straight up, down, etc.) and I need to try to get the same functionality in Silverlight. It is very similar to Google StreetView.
What I think I need is to create a sphere, wrap the jpeg on the sphere as a texture, then put the "camera" inside the sphere. I doubt this is possible in Silverlight, but perhaps there is a way to simulate this?
So far, Google searches aren't bringing anything up. Can anyone point me in the right direction to figure out how to do this? Are there any existing projects that do this?
An example of a typical image is here.
These might help you out (probably not). They are 3d engines for silverlight, but they will probably wrap the image outside of the sphere instead of inside, which is probably what you need.
Kit3D http://www.codeplex.com/Kit3D
Balder http://www.codeplex.com/Balder
Another, possibly more promising option, would be to use javascript. So far you've probably researched how to do this in Silverlight, but you might do some similar searching for using javascript for this. There may be an option out there already, and since Silverlight can interopt with Javascript, you might be in luck.
Your gonna have to map the texture to a sphere then, like you said. But afaik silverlight 3 doesn't support hardware accelerated 3d.
So your options are:
Try and find a silverlight software 3d library (Like this)
Write your own software rasterizer (multi page guide)
Hope this helps
You might want to try cropping a window from the image and display it. if the user want to go right, move the window right and crop. if the user wants to go left, move the window left and crop. to zoom out, expand the window, to zoom in make the window smaller. if you move the frame far right then stitch the image data from the left side.
You might need to modify the image to eliminate the distortion, this shouldn't be too hard and depends on the camera lens focal length.
Don't try mapping the image to a sphere, it is much harder.
At https://hdviewsl.codeplex.com it says that HD View SL (Silverlight version) supports
"orthographic (2D), with wrapping for 360-degree panoramas"
Also you could try to port PtViewer source code to Silverlight from Java if no one else has
UPDATE:
VRLight might be the solution in your case:
http://vrlight.thecloudsite.net/
http://vrlight.thecloudsite.net/tutorial.html
http://ivrpa.org/blog/3651/vrlight_vredit_20
Its author (Jurgen Eidt) is also making cPicture (http://cpicture.thecloudsite.net/index.en.html), if you can't find him from the VRLight site, try from the cPicture one, or try from his blog at IVRPA website (http://ivrpa.org/blog/3651), which seems to have recent posts

Need example of Flex or silverlight application that enables interactive drawing on a video

I am trying to evaluate which technology is best for my needs.
I need to display a video I get from some remote device, and let a user
interactively draw on it lines, polygons etc.
I searched and couldn't find any existing applications with this ability
(all the flash applications only displayed video).
Could anyone point me to such an application?
I haven't seen a specific app that allows you to do that, but I can tell you it would be fairly trivial to build it in Flex. You would simply create a transparent Sprite over the video clip, then use the Drawing API bound to various mouse events to do your drawing.
The final image can be saved by using BitmapData.draw() over the container that holds both the video and the canvas, and you can pass a bytearray encoded as PNG or JPG to a server-side script to save it.
I can't speak to Silverlight as I've never used it - but a Flex dev could build a basic sample of this for you in Flex in about 20 mins just as a proof of concept.
Where does your expertise lie?
Silverlight you could knock up a proof of concept rather easily and as Myk points out you could do the same in Flex. So your best bet is really whichever technology your current expertise lies in.
In Silverlight you could use a InkPresenter control above a MediaElement control in about 2 minutes up and running with a video file.
I think the hard part is finding a way to display realtime video from your specific device.
Silverlight supports streaming video so having that device talk with Windows Media Server or Silverlight Streaming sounds like the best bet.
Julie Lerman wrote an Silverlight app that you can draw on Images:
http://thedatafarm.com/blog/tablet/drawing-in-silverlight-article-in-msdn-magazine/
the article was presented at a magazine:
http://msdn.microsoft.com/en-us/magazine/cc721604.aspx
Hopes this helps.

Getting .png pixel data in Silverlight

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.
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 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
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.
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 - 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?

Sprite / Character animation in Silverlight (v2)

We have a Silverlight 2 project (game) that will require a lot of character animation. Can anyone suggest a good way to do this. Currently we plan to build the art in Illustrator, imported to Silverlight via Mike Snow's plug-in as this matches the skills our artists have.
Is key framing the animations our only option here? And if it is, what's the best way to do it? Hundreds of individual png's or is there some way in Silverlight to draw just a portion of a larger image?
You can use the Clip property on the image itself or on a container for the image to display a specific piece of a larger image, like a sprite sheet. This may or may not be more performant than swapping pngs. Also you could use the ImageBrush on a Rectangle to show just what you want, this would probably be a bit more efficient than the Clip property.
I just posted some code using Bill's suggestion regarding the Rectange and ImageBrush.
Silverlight at this time does not support bitmap effects nor has any libraries to manipulate the images. Your option now is to use keyframe animations from one png to another.
Now you can get at the raw bytes of an image. If you have your own image processing libraries you can compile them with the Silverlight dlls and then use the library in your Silverlight app.

Resources