Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
after upload the image is not resizing.
VB
Dim image__1 = Image.FromStream(fromStream)
       Dim newWidth = 75
       Dim newHeight = 73

       Using thumbnailBitmap = New Bitmap(newWidth, newHeight)
           Using thumbnailGraph = Graphics.FromImage(thumbnailBitmap)
               thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality
               thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality
               thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic
               Dim imageRectangle As Object
               imageRectangle = New Rectangle(2, 34, newWidth, newHeight)
               thumbnailGraph.DrawImage(image__1, imageRectangle)

               thumbnailBitmap.Save(toStream, image__1.RawFormat)
           End Using
       End Using


here in image_1 having oldwidth and height only..it is not changing to i specified width and height
Posted

If is actually re-sized. Moreover, it is properly re-sampled in the server side. Just look at this:
http://msdn.microsoft.com/en-us/library/yws82c40.aspx[^].

You just don't observe it. One possible reason could be your HTML file. Imagine that you have your img element like this:
HTML
<img alt="my image" src="myImage.png" width="750" height="730" />


For example, on your server side you re-sample the original image down, but the client part re-samples it up again, according to this HTML. Is so, you will need to remove the attribute width and height, or perhaps generate them on the fly on the server side using appropriate size, but better just one of them, not both, to avoid mangling the aspect ratio.

—SA
 
Share this answer
 
VB
Private Sub DrawImageRect(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create rectangle for displaying image.
    Dim destRect As New Rectangle(100, 100, 450, 150)

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, destRect)
End Sub



one more solution using scripting...
<%@ Page Language="C#" %>
<%@ import Namespace="System.Drawing.Imaging" %>
<script runat="server">
//Pics folder has to be created under the current folder
void UploadBtn_Click(Object sender, EventArgs e)
{
String UploadedFile = MyFile.PostedFile.FileName;
int ExtractPos = UploadedFile.LastIndexOf("\\") + 1;

//to retrieve only Filename from the complete path
String UploadedFileName = UploadedFile.Substring(ExtractPos,UploadedFile.Length - ExtractPos);

// Display information about posted file. Div is invisible by default
FileName.InnerHtml = UploadedFileName;

MyContentType.InnerHtml = MyFile.PostedFile.ContentType;

ContentLength.InnerHtml = MyFile.PostedFile.ContentLength.ToString();

FileDetails.Visible = true; //div is made visible

// Save uploaded file to server at the in the Pics folder
MyFile.PostedFile.SaveAs(Request.PhysicalApplicationPath
+ "pics\\" + UploadedFileName );

//thumbnail creation starts
try
{
//Retrieve the image filename whose thumbnail has to be created
String imageUrl = UploadedFileName;
//Read in the width and height
int imageHeight =Convert.ToInt32(h.Text);
int imageWidth = Convert.ToInt32(w.Text);

//You may even specify a standard thumbnail size
//int imageWidth = 70;
//int imageHeight = 70;

if (imageUrl.IndexOf("/") >= 0 || imageUrl.IndexOf("\\") >= 0 )
{
//We found a / or \
Response.End();
}

//the uploaded image will be stored in the Pics folder.
//to get resize the image, the original image has to be
//accessed from the Pics folder
imageUrl = "pics/" + imageUrl;

System.Drawing.Image fullSizeImg
= System.Drawing.Image.FromFile(Server.MapPath(imageUrl));
System.Drawing.Image.GetThumbnailImageAbort dummyCallBack
= new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
System.Drawing.Image thumbNailImg
= fullSizeImg.GetThumbnailImage(imageWidth, imageHeight,
dummyCallBack, IntPtr.Zero);

//We need to create a unique filename for each generated image
DateTime MyDate = DateTime.Now;

String MyString = MyDate.ToString("ddMMyyhhmmss") + ".png" ;

//Save the thumbnail in PNG format.
//You may change it to a diff format with the ImageFormat property
thumbNailImg.Save ( Request.PhysicalApplicationPath
+ "pics\\" + MyString , ImageFormat.Png);
thumbNailImg.Dispose();

//Display the original & the newly generated thumbnail

Image1.AlternateText = "Original image";
Image1.ImageUrl="pics\\" + UploadedFileName;
Image2.AlternateText = "Thumbnail";
Image2.ImageUrl="pics\\" + MyString;
}
catch(Exception ex)
{
Response.Write("An error occurred - " + ex.ToString());
}
}

//this function is reqd for thumbnail creation
public bool ThumbnailCallback()
{
return false;
}
</script>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900