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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image Resize. Works Testing Not Live

Status
Not open for further replies.

thankgodfortektips

Programmer
Dec 20, 2005
95
KY
Hi All,

Firstly I just want to say that I have no knowledge of C# at all... I know VB and ASP and I had to find a way to resize an image and I found a sample page which after many hours I made work for me.

The page works fine in my testing environment but when I try and run it from my web host it isn't working. I have googled away and found a few posts that say it is permissions, some that say that it is because the file is already in use so cant be used to resize... but my problem is that I dont have a clue how to implement any of the solutions in code because of my lack of knowledge.

The error I am getting is:
******************
An error occurred - System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) at System.Drawing.Image.Save(String filename, ImageFormat format) at ASP.createthumbland_aspx.UploadBtn_Click(Object sender, EventArgs e)
******************

My Code is:

******************
<%@ Page Language="C#" %>
<%@ import Namespace="System.Drawing.Imaging" %>
<script runat="server">

//this function is reqd for thumbnail creation
public bool ThumbnailCallback()
{
return false;
}
//Send feedback to dotnut@hotmail.com

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 + "Uploads\\" + Request.QueryString["intPropID"].ToString() + "\\" + UploadedFileName );

//thumbnail creation starts
try
{
//Read in the image filename whose thumbnail has to be created
String imageUrl= Request.QueryString["strImgName"].ToString();

//Read in the width and height
int imageHeight =Convert.ToInt32("110");
int imageWidth = Convert.ToInt32("150");
int imageHeight2 =Convert.ToInt32("450");
int imageWidth2 = Convert.ToInt32("600");

//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 = "Uploads/" + Request.QueryString["intPropID"].ToString() + "/" + 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);

System.Drawing.Image thumbNailImg2 = fullSizeImg.GetThumbnailImage(imageWidth2, imageHeight2, dummyCallBack, IntPtr.Zero);

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

String MyString = "tb_" + Request.QueryString["strImgName"].ToString();
String MyString2 = "MN_" + Request.QueryString["strImgName"].ToString();

//Save the thumbnail in Png format. You may change it to a diff format with the ImageFormat property
thumbNailImg.Save ( Request.PhysicalApplicationPath + "Uploads\\" + Request.QueryString["intPropID"].ToString() + "\\" + MyString , ImageFormat.Png);
thumbNailImg2.Save ( Request.PhysicalApplicationPath + "Uploads\\" + Request.QueryString["intPropID"].ToString() + "\\" + MyString2 , ImageFormat.Png);

thumbNailImg.Dispose();
thumbNailImg2.Dispose();

Response.Redirect("CloseAndRefresh.asp", true);

//Display the original & the newly generated thumbnail
// Image1.AlternateText = "Original image";
// Image1.ImageUrl="Uploads\\" + Request.QueryString["intPropID"].ToString() + "\\" + UploadedFileName;

// Image2.AlternateText = "Thumbnail";
// Image2.ImageUrl="Uploads\\" + Request.QueryString["intPropID"].ToString() + "\\" + MyString;
}

catch(Exception ex)
{
Response.Write("An error occurred - " + ex.ToString());
}

}


</script>
<html>
<head>

<link href="CSS/CSSForRent.css" rel="stylesheet" type="text/css">
<title>Upload Finalization</title></head>
<body>

<form action="" id="form1" name="form1" method="post" enctype="multipart/form-data" runat="server">
<div align="center">
<p><img src="images/Logo.gif" alt="" width="165" height="150"></p>
<p class="SubHeader">Your image has been verified. Please click below to finalize upload.<span class="SubHeader"></span><br/>
<br/>
<input type="submit" class="DetailFont" value="Finalize" runat="server" onserverclick="UploadBtn_Click" />
<br/>
<br/>
</p>
</div>
<div id="FileDetails" runat="server" visible="false"></div>
</form>
</body>
</html>
*********************

Please HELLLLLPPPPPPP!!!!!
 
c# or .net shouldn't matter the errors are the same. if you can't convert vb to c# and vice versa then google "c# to vb converter" there a plenty online. i would hope that the stack trace and inner exceptions are more useful than the error above. since "generic error" gives no clue to the source of the problem.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top