Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resizing an image

Status
Not open for further replies.

meckeard

Programmer
Joined
Aug 17, 2001
Messages
619
Location
US
Hi all,

I'm trying to get set the height and width of an image control using the following but it's not working:

imgItemImage.ImageUrl = ("images/NoImage.jpg")
imgItemImage.Height.Equals(50)
imgItemImage.Width.Equals(50)

What am I doing wrong?

Thanks!
 
I'll actually need that to determine the new height and width. But it wasn't what I was trying to achieve with my code sample above.

I'll need to reduce an image size in half, so I need to set the height and width properties. Something like this:

'Get the current height and width in to var's.
Dim intHeight = imgItemImage.Item.Height
Dim intWidth = imgItemImage.Item.Width

'Set the new H & W
imgItemImage.Item.Height = intHeight/2
imgItemImage.Item.Width = intWidth/2

Onviously that's not the correct syntax but it's what I'm trying to achieve.

Thanks.
 
here is some sample code from a page I coded that uses the FileUpload control (fuPhoto)

Code:
if (fuPhoto.PostedFile != null && fuPhoto.PostedFile.FileName != string.Empty) //Checking for valid file
        {

            System.Drawing.Image UploadedImage = System.Drawing.Image.FromStream(fuPhoto.PostedFile.InputStream);

            float UploadedImageWidth = UploadedImage.PhysicalDimension.Width;
            float UploadedImageHeight = UploadedImage.PhysicalDimension.Height;

            float NewImageWidth = UploadedImageWidth;
            float NewImageHeight = UploadedImageHeight;

            bool bResize = false;

            // Since the PostedFile.FileNameFileName gives the entire path we use Substring function to rip of the filename alone.
            string StrFileName = fuPhoto.PostedFile.FileName.Substring(fuPhoto.PostedFile.FileName.LastIndexOf("\\") + 1);
            string StrFileType = fuPhoto.PostedFile.ContentType;
            int IntFileSize = fuPhoto.PostedFile.ContentLength;
            //Checking for the length of the file. If length is 0 then file is not uploaded.

            if (IntFileSize <= 0)
            {
                //lblMessage.Text=" <font color='Red' size='2'>Uploading of file " + StrFileName + " failed </font>";
            }
            else
            {
                string strCompleteFilePath = Server.MapPath(".\\images\\uploaded\\" + "UserID" + iUserID + StrFileName);
                fuPhoto.PostedFile.SaveAs(strCompleteFilePath);
            }


etc....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top