Iron Speed Technical Forums
Register Latest Topics
 
 
 


Reply
  Author   Comment  
smithm

Registered:
Posts: 35
Reply with quote  #1 
I came across some code out in the wild wild internet that allowed me to automagically create a thumbnail image from an image being uploaded by a user. I use it in an EditRecord page where I give the user a FileUpload control, allowing them to upload files and images. I wanted a way to display a thumbnail image on the ShowRecord page if they uploaded an image, but I didn't want the user to have to download the entire image (which could be megabytes in size), and have it resized on the screen. I thought I'd share the magic.
 
The table in the database that the record with the image is being saved to has a Screenshot column and a Thumbnail column.
 
 
 If Me.Screenshot.FileName <> "" Then
                        Dim FileExtension As String = Me.Screenshot.FileName.Substring(Me.Screenshot.FileName.Length - 3, 3).ToUpper
                        'Determine whether file being uploaded is an image.
                        If FileExtension = "BMP" Or FileExtension = "JPG" Or FileExtension = "GIF" Or FileExtension = "PNG" Then 'File is an image, parse for thumbnail
                            'Create Thumbnail variable
                            Dim Thumbnail As System.Drawing.Image = Nothing
 
                            'Populate with current Screenshot image
                            Thumbnail = Drawing.Image.FromStream(Me.Screenshot.PostedFile.InputStream())
 
                            'Convert thumbnail to new size
                            Thumbnail = Thumbnail.GetThumbnailImage(CInt(Thumbnail.Width / 5), CInt(Thumbnail.Height / 5), Nothing, New IntPtr())
 
                            'Convert Image to byte array
                            Dim imgByteArray As Byte() = Nothing
                            Dim imgMemoryStream As System.IO.MemoryStream = New System.IO.MemoryStream()
                            Thumbnail.Save(imgMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg)
                            imgByteArray = imgMemoryStream.GetBuffer()
 
                            'Save thumbnail to record
                            Report.ThumbnailImage = imgByteArray
                        End If
 
                        Report.Save()
                    End If
 
Don't forget to make sure your Save button has its Postback property set to true, or it won't work!
JimiJ

Avatar / Picture

MVP Developer
Registered:
Posts: 1,927
Reply with quote  #2 
Check on http://sjc.ironspeed.com/post/Resize-Image-before-uploading-to-DB-*UPDATED*-2217787  

Look for Post # 13

Jimi J

__________________

  Jaime Jegonia
[jts_logo]

Iron Speed MVP Developer
 

". . . and whoever sows generously will also reap generously" 2 Cor 9:6

smithm

Registered:
Posts: 35
Reply with quote  #3 
Ahh, and here I was thinking I was so clever.
cpet

Registered:
Posts: 84
Reply with quote  #4 
JimiJ,
Could you repost your link? I click on it and am told the topic could not be found.
thanks
Cpet
JimiJ

Avatar / Picture

MVP Developer
Registered:
Posts: 1,927
Reply with quote  #5 
Try to do a search "Resize-Image-before-uploading".
__________________

  Jaime Jegonia
[jts_logo]

Iron Speed MVP Developer
 

". . . and whoever sows generously will also reap generously" 2 Cor 9:6

TheChief

Avatar / Picture

MVP Developer
Registered:
Posts: 145
Reply with quote  #6 

I think this is what Jimi was referring to:

http://sjc.ironspeed.com/post/Resize-Image-before-uploading-to-DB-*UPDATED*-2217787?highlight=resize+image+uploading

Cheers


__________________

Former Senior Web Engineer
CEO Simple And Smart Apps
IronSpeed MVP

youimage

Registered:
Posts: 2
Reply with quote  #7 
first,thank  you for this amazing codes you are sharing for us. it is indeed a good way to resize an image before uploading without the entire page images downloaded.
arronlee

Registered:
Posts: 9
Reply with quote  #8 
Here are the code I have ever used to resize images on C#.NET:
Code:
using System.IO;
using System.Drawing.Printing;
using Yiigo.Imaging;
using Yiigo.Imaging.Processing;

using YiigoImage Image = new YiigoImage();
{
string ImageID = (@"C:\ yiigo_example.jpg ");
float ImageWidth = "300";
float ImageHeight = "500";
}
Image.YiigoImageProcessResize(@"C:\ yiigo_example.jpg", "300", "500");
Image.Save(@"C:\ yiigo_example.jpg");

I hope it helps. Good luck.



Best regards,
Arron

__________________
Best Regards,
Arron
I am testing about SDKs dealing with
imaging SDK. Do you have any ideas?
[I]Next Tomorrow is Another Day[/B].
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Download Iron Speed Designer

Terms of Service Privacy Statement