Link to home
Start Free TrialLog in
Avatar of REA_ANDREW
REA_ANDREWFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Resize Images

How do I resize images with ASP.NET 2.0 and using C#??

thanks in advance

Andrew
Avatar of Swapnil
Swapnil
Flag of India image

Hi REA_ANDREW,

Following will help you.

True Image Resizing
http://aspnet.4guysfromrolla.com/articles/012203-1.aspx

Regards,
NetSwap
ASKER CERTIFIED SOLUTION
Avatar of Ramesh Srinivas
Ramesh Srinivas
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also, you must modify this line, if you want to let the width be variable without limits:

Dim bmp As Bitmap = CreateThumbnail(Path, Size, Size)

replace it with:

Dim bmp As Bitmap = CreateThumbnail(Path, Size, sSize)


To give u an example of this, use the code below also:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Dim rLink = Request.QueryString("vLink")
        Dim rWidth = Request.QueryString("w")
        Dim rHeight = Request.QueryString("h")

        Dim sSize As String = rWidth
        Dim Size As Integer = rHeight


===========================================

Now change the image tag to:

<img src="sizer.aspx?vLink=http://www.myDomain.com/img/myImage.jpg&w=500&h=300">

This will resize the image to 500 by 300.

regards,

KS
Avatar of REA_ANDREW

ASKER

When I pasted the code into. It gave me these errors in the error window

Error      1      Type 'Bitmap' is not defined.      C:\Inetpub\wwwroot\frag\sizer.aspx.vb      46      134      C:\...\frag\
Error      2      Type 'Bitmap' is not defined.      C:\Inetpub\wwwroot\frag\sizer.aspx.vb      49      30      C:\...\frag\
Error      3      Type 'Bitmap' is not defined.      C:\Inetpub\wwwroot\frag\sizer.aspx.vb      82      26      C:\...\frag\
Error      4      Type 'Graphics' is not defined.      C:\Inetpub\wwwroot\frag\sizer.aspx.vb      84      22      C:\...\frag\
Error      5      Name 'Brushes' is not declared.      C:\Inetpub\wwwroot\frag\sizer.aspx.vb      86      29      C:\...\frag\
Error      6      End of statement expected.      C:\Inetpub\wwwroot\frag\sizer.aspx.vb      99      64      C:\...\frag\
Error      7      Name 'rLink' is not declared.      C:\Inetpub\wwwroot\frag\sizer.aspx.vb      110      70      C:\...\frag\
Error      8      Type 'Bitmap' is not defined.      C:\Inetpub\wwwroot\frag\sizer.aspx.vb      114      20      C:\...\frag\
hi
 
this link  has sample project what you want



http://www.codeproject.com/aspnet/pnguploader.asp

Thanks
Andrew,

You need to include the following lines at the very top:

Imports System.Drawing.Imaging
Imports System.Net
Imports System.IO



ok I have narrowed the rrors down to 2

Error      1      Type 'ImageFormat' is not defined.      C:\Inetpub\wwwroot\frag\sizer.aspx.vb      50      29      C:\...\frag\
Error      2      Name 'ImageFormat' is not declared.      C:\Inetpub\wwwroot\frag\sizer.aspx.vb      117      41      C:\...\frag\


I am designing with ASP.NET 2.0
I have.  but in asp.net 2.0 the first one is now

Imports System.Drawing
I fixed it using this at the top

Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Net
Imports System.IO
Yes, I just looked it up and saw that the namespaces had slightly been changed, so you had to include Drawing as well.

All the best.