Hi soulcode,
here are 2 very good examples:
http://aspnet.4guysfromrol
http://www.plus.hr/skripte
Regards!
B..M
Main Topics
Browse All Topics
Hi People,
Im using the following control in asp.net to allow users to upload an image to the server::
<INPUT id="ctlLogoFile" type="file" name="Pic" runat="server" size="15">
I want to be able to take the image, resize it in ratio so it will fit within 200x200 bounds, then save it on the server as a file.
I have code to save the image to the server, just no code to resize image. Its similar to creating a thumbnail image, just making sure the height and width ratio stays in tact.
Help me! :o( i've bee trying to find a solution for this for weeks!!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi soulcode,
here are 2 very good examples:
http://aspnet.4guysfromrol
http://www.plus.hr/skripte
Regards!
B..M
and check this too
http://www.codeproject.com
good luck
Imports System.Drawing
Imports System.Drawing.Imaging
Public Class ResizeImage
Private _CreateThumbnail As Boolean
Private _ThumbX, _ThumbY, _FullSizeX, _FullSizeY As Integer
Private UnacceptableImageFormats As ArrayList
Public Property CreateThumbnail() As Boolean
Get
Return _CreateThumbnail
End Get
Set(ByVal Value As Boolean)
_CreateThumbnail = Value
End Set
End Property
Public Property FullSizeX() As Integer
Get
Return _FullSizeX
End Get
Set(ByVal Value As Integer)
_FullSizeX = Value
End Set
End Property
Public Property FullSizeY() As Integer
Get
Return _FullSizeY
End Get
Set(ByVal Value As Integer)
_FullSizeY = Value
End Set
End Property
Public Property ThumbX() As Integer
Get
Return _ThumbX
End Get
Set(ByVal Value As Integer)
_ThumbX = Value
End Set
End Property
Public Property ThumbY() As Integer
Get
Return _ThumbY
End Get
Set(ByVal Value As Integer)
_ThumbY = Value
End Set
End Property
Public Sub New(ByVal CreateThumbnail As Boolean, ByVal FullSizeX As Integer, ByVal FullSizeY As Integer)
_CreateThumbnail = CreateThumbnail
_FullSizeX = FullSizeX
_FullSizeY = FullSizeY
UnacceptableImageFormats = New ArrayList(10)
With UnacceptableImageFormats
.Add(Imaging.PixelFormat.F
.Add(Imaging.PixelFormat.F
.Add(Imaging.PixelFormat.F
.Add(Imaging.PixelFormat.U
.Add(Imaging.PixelFormat.D
.Add(Imaging.PixelFormat.F
.Add(Imaging.PixelFormat.F
End With
End Sub
Public Function ResizeImage(ByVal ImageSource As String) As String
Dim IncomingImage As System.Drawing.Image
Dim OutputBitmap As Bitmap
Dim JpegCodec As ImageCodecInfo
Dim JpegEncodeParams As EncoderParameters
Dim NewSize As Size
Dim fiSource As New IO.FileInfo(ImageSource)
Dim fsSource As IO.FileStream
Dim fiDestination As New IO.FileInfo(ImageSource)
Dim NewFilename As String
fiSource.MoveTo(fiSource.D
fsSource = fiSource.OpenRead()
IncomingImage = IncomingImage.FromStream(f
OutputBitmap = RedrawImage(IncomingImage,
If fiSource.Extension = ".gif" Then
NewFilename = fiDestination.Name
OutputBitmap.Save(fiDestin
Else
JpegCodec = ReturnJpegCodec()
JpegEncodeParams = ReturnEncoderParams()
NewFilename = fiDestination.Name.Replace
OutputBitmap.Save(fiDestin
JpegCodec, JpegEncodeParams)
End If
fsSource.Close() ''''This may have done it check on wednesday
'This is causing the generic GDI+ exception
If CreateThumbnail Then
OutputBitmap = RedrawImage(IncomingImage,
If fiSource.Extension = ".gif" Then
OutputBitmap.Save(fiDestin
Else
JpegCodec = ReturnJpegCodec()
JpegEncodeParams = ReturnEncoderParams()
OutputBitmap.Save(fiDestin
fiDestination.Name.Replace
End If
End If
OutputBitmap.Dispose()
IncomingImage.Dispose()
fiSource.Delete()
Return NewFilename
End Function
Private Function RedrawImage(ByVal IncomingImage As Image, ByVal MaximumX As Integer, _
ByVal MaximumY As Integer) As Bitmap
Dim ResizedX, ResizedY As Integer
Dim Bitmap As Bitmap
Dim Graphic As Graphics
Dim NewSize As Size
ResizedY = CInt((IncomingImage.Height
ResizedX = CInt((IncomingImage.Width * MaximumY) / IncomingImage.Height)
If ResizedY >= MaximumY Then
NewSize = New Size(ResizedX, MaximumY)
Else
NewSize = New Size(MaximumX, ResizedY)
End If
Bitmap = New Bitmap(IncomingImage, NewSize)
Bitmap.SetResolution(72, 72)
'Some graphic pixel formats prevent the image from being converted into an instance of Graphics.
' If this is the case, return just the resized bitmap without processing.
If UnacceptableImageFormats.C
'All pixel formats that Microsoft says will generate exceptions have been loaded into the array
' above, yet some pixel formats are still throwing exceptions. Resorted to a Try / Catch block - AM
Try
Graphic = Graphics.FromImage(Bitmap)
Catch
Return Bitmap
End Try
Graphic.SmoothingMode = Drawing2D.SmoothingMode.Hi
Graphic.InterpolationMode = Drawing2D.InterpolationMod
Graphic.PixelOffsetMode = Drawing2D.PixelOffsetMode.
Graphic.DrawImage(Bitmap, 0, 0)
Graphic.Dispose()
Return Bitmap
End Function
Private Function ReturnJpegCodec() As ImageCodecInfo
Dim codecs As Imaging.ImageCodecInfo() = ImageCodecInfo.GetImageEnc
For Each codec As ImageCodecInfo In codecs
If codec.MimeType.Equals("ima
Next
End Function
Private Function ReturnEncoderParams() As EncoderParameters
Dim EncoderInstance As Encoder
Dim EncoderParametersInstance As New EncoderParameters(2)
Dim QualityParameter As EncoderParameter
Dim ColorParameter As EncoderParameter
EncoderInstance = Encoder.Quality
QualityParameter = New EncoderParameter(EncoderIn
EncoderParametersInstance.
EncoderInstance = Encoder.ColorDepth
ColorParameter = New EncoderParameter(EncoderIn
EncoderParametersInstance.
Return EncoderParametersInstance
End Function
End Class
Aeros
call it like so:
Dim IncomingFile As IO.FileInfo
Dim ImageSource, PriceValue As String
Dim ImageResizer As New ResizeImage(True, 400, 300)
ImageResizer.ThumbX = 100
ImageResizer.ThumbY = 100
If ImageSrc.PostedFile.Conten
IncomingFile = New IO.FileInfo(Request.Files(
IncomingFile = New IO.FileInfo(Server.MapPath
Request.Files(0).SaveAs(In
ImageSource = ImageResizer.ResizeImage(I
End If
Business Accounts
Answer for Membership
by: ihenryPosted on 2004-10-18 at 00:38:01ID: 12336702
Try this article,
om/article s/display. html? artic le=2003040 501&page=1
Uploading, Determining Size, Width and Height and Resizing Image Files with ASP.NET
http://www.stardeveloper.c