Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Converting images to thumbnails
4 replies. Latest Post by kobruleht on May 3, 2009.
(0)
kobruleht
Member
161 points
579 Posts
05-01-2009 5:33 AM |
Images are stored in server database and retrieved as byte[] arrays using web service.
How to allow users to upload images of any size but convert them to small fixed-size thumbnails for fast display over slow internet connection?Or is it better to do this conversion in client side to increase upload speed also?
Where to find such library and sample code? This should be common requirement.
Andrus.
ken tucker
All-Star
16288 points
2,485 Posts
05-01-2009 11:48 AM |
Silverlight 2 does not have any bitmap functions so you would have to upload the image and process it server side. I
Your best bet for doing this is to load the image into a bitmap class on the server side. Check the size if it is too large I would use drawimage to draw the old bitmap on a new one of smaller size. Then you would save the smaller image in the database.
ksleung
Contributor
5366 points
1,028 Posts
05-01-2009 12:27 PM |
In SL2 you can use the open source Jpeg decoder (and encoder) called FJCore. It has some functionality to resize images.
In SL3 beta there is WriteableBitmap but for two reasons it won't be helpful to you -- (1) security (see various threads on this topic), and (2) no way to encode bitmap to Jpeg. Therefore, your choices are really (a) send the whole thing to the server, or (b) use FJCore to process the image on the client side and then send it to the server.
jay nana...
3388 points
624 Posts
05-01-2009 12:54 PM |
If you prefer to use Silverlight 3, you can use WriteableBitmap class to redraw images that are large to relatively small size.
05-03-2009 1:54 PM |
Thank you. My shop cart thumbnails are defined as
<Image Source='{Binding Toode_pilt}' Height='200' MaxWidth='150'/> and retrieved from db using web service as byte[] arrays.
They can be enlarged so they must be stored in high quality in database.
Where to find sample code for DrawImage or other solution in server side which reduces size of jpeg byte[] array for this format and to minimal size before sending ?