Question : Handling Images in Silverlight

Hi to all,

I am working on a silverlight application and I was wondering what the best way is to handle images in Silverlight? It is very similar to the following site:
http://www.vertigo.com/slideshow.aspx
I downloaded the sample and found that the image thumbs are no bigger than 200 KB. When I upload my Images and create thumbs for the images they are distorted and DO NOT LOOK GOOD!!!!  Below is a sample of my code I use, but this is for bulk resize. When I upload I just replace the bulk upload with a single filename.

How can I resize images with a size between 1.4 meg to 2 meg to thumbnail size and not distort them and how will I handle the smaller images in Silverlight where it still looks good?

Thanks
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
Private Sub Resizing()
        Dim ThumbWidth As Double = 150
        Dim ThumbHeight As Double = 200
        Dim ThumbFolder As String = "myfolder goes here"
        Dim inp As New IntPtr
 
        Try
 
            For Each picFile In IO.Directory.GetFiles("my image folder goes here")
                Dim fileEXT As String = IO.Path.GetExtension(picFile)
                If fileEXT = ".jpg" Then
                    Dim FileUseName As String = IO.Path.GetFileName(picFile)
                    Dim ThumbPicture As String = ThumbFolder & FileUseName
                    Dim Bigfileinfo As Image = Image.FromFile(picFile)
                    Dim NewFileThumb As Image = Nothing
                    If Bigfileinfo.Height > Bigfileinfo.Width Then
                        NewFileThumb = ResizeImage(Bigfileinfo, ThumbWidth, ThumbHeight)
                        NewFileThumb.Save(ThumbPicture)
                    Else
                        NewFileThumb = ResizeImage(Bigfileinfo, ThumbHeight, ThumbWidth)
                        NewFileThumb.Save(ThumbPicture)
                    End If
 
                End If
            Next
            MessageBox.Show("Done")
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error resizing pictures" _
                            , MessageBoxButtons.OK _
                            , MessageBoxIcon.Information)
        End Try
    End Sub
 
    Public Shared Function ResizeImage(ByVal originalImage As System.Drawing.Image, ByVal width As Integer, ByVal height As Integer) As System.Drawing.Image
        Dim finalImage As System.Drawing.Image = New Bitmap(width, height)
 
        Dim graphic As Graphics = Graphics.FromImage(finalImage)
 
        graphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality
        graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
        graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
 
        Dim rectangle As New Rectangle(0, 0, width, height)
 
        graphic.DrawImage(originalImage, rectangle)
 
        Return finalImage
    End Function

Answer : Handling Images in Silverlight

You'll need to add a library to be able to control the image compression you want. FJCore is a common one used for this:

http://fluxcapacity.net/2008/07/14/fjcore-to-the-rescue/
Random Solutions  
 
programming4us programming4us