主题:.net生成縮略圖
/// <summary>
/// 添加遊戲信息
/// </summary>
private void AddGameInfo()
{
if(dp.CheckData("select * from GameInfo where GameName='"+txtGameName.Text+"'"))
{
Response.Write("<script language=javascript>alert('已經存在該遊戲的信息了!');</script>");
return;
}
string fileFullName=GamePhoto.PostedFile.FileName;//文件名全名
string fileName=fileFullName.Substring(fileFullName.LastIndexOf("\\")+1);//文件名
string fileType=fileFullName.Substring(fileFullName.LastIndexOf(".")+1);//文件類型
if(fileType=="jpg"||fileType=="bmp"||fileType=="gif")
{
string strFile=MapPath("../UpLoadPhoto")+"\\"+fileName;
//Img.ImageUrl=strFile;
GamePhoto.PostedFile.SaveAs(strFile);
//生成縮略圖
CreatePhoto(strFile);
try
{
dp.RunProcedure("usp_InsertGameInfo",new SqlParameter[]{new SqlParameter("@GameName",txtGameName.Text),new SqlParameter("@GamePhoto",strFile),new SqlParameter("@JieShaoContent",txtContent.Text)});
Response.Write("<script language=javascript>alert('操作成功!');</script>");
}
catch
{
Response.Write("<script language=javascript>alert('操作失敗,請與管理員聯系!');</script>");
}
}
else
{
Response.Write("<script language=javascript>alert('文件類型有誤!');</script>");
}
}
/// <summary>
/// 生成縮略圖
/// </summary>
/// <param name="file">圖片路徑</param>
private void CreatePhoto(string file)
{
int width, height,newWidth,newHeight;
System.Drawing.Image image,newImage;
System.Drawing.Image.GetThumbnailImageAbort callb=null;
image=System.Drawing.Image.FromFile(file);
width=image.Width;
height=image.Height;
if(width>height)
{
newWidth=110;
newHeight=image.Height/image.Width*newWidth;
}
else
{
newHeight=110;
newWidth=image.Width/image.Height*newHeight;
}
newImage=image.GetThumbnailImage(newWidth,newHeight,callb,new System.IntPtr());
file=file.Insert(file.LastIndexOf("\\")+1,"001");
newImage.Save(file);
Img.ImageUrl=file;
image.Dispose();
newImage.Dispose();
}
上面會出現內存不足,請高手幫忙
/// 添加遊戲信息
/// </summary>
private void AddGameInfo()
{
if(dp.CheckData("select * from GameInfo where GameName='"+txtGameName.Text+"'"))
{
Response.Write("<script language=javascript>alert('已經存在該遊戲的信息了!');</script>");
return;
}
string fileFullName=GamePhoto.PostedFile.FileName;//文件名全名
string fileName=fileFullName.Substring(fileFullName.LastIndexOf("\\")+1);//文件名
string fileType=fileFullName.Substring(fileFullName.LastIndexOf(".")+1);//文件類型
if(fileType=="jpg"||fileType=="bmp"||fileType=="gif")
{
string strFile=MapPath("../UpLoadPhoto")+"\\"+fileName;
//Img.ImageUrl=strFile;
GamePhoto.PostedFile.SaveAs(strFile);
//生成縮略圖
CreatePhoto(strFile);
try
{
dp.RunProcedure("usp_InsertGameInfo",new SqlParameter[]{new SqlParameter("@GameName",txtGameName.Text),new SqlParameter("@GamePhoto",strFile),new SqlParameter("@JieShaoContent",txtContent.Text)});
Response.Write("<script language=javascript>alert('操作成功!');</script>");
}
catch
{
Response.Write("<script language=javascript>alert('操作失敗,請與管理員聯系!');</script>");
}
}
else
{
Response.Write("<script language=javascript>alert('文件類型有誤!');</script>");
}
}
/// <summary>
/// 生成縮略圖
/// </summary>
/// <param name="file">圖片路徑</param>
private void CreatePhoto(string file)
{
int width, height,newWidth,newHeight;
System.Drawing.Image image,newImage;
System.Drawing.Image.GetThumbnailImageAbort callb=null;
image=System.Drawing.Image.FromFile(file);
width=image.Width;
height=image.Height;
if(width>height)
{
newWidth=110;
newHeight=image.Height/image.Width*newWidth;
}
else
{
newHeight=110;
newWidth=image.Width/image.Height*newHeight;
}
newImage=image.GetThumbnailImage(newWidth,newHeight,callb,new System.IntPtr());
file=file.Insert(file.LastIndexOf("\\")+1,"001");
newImage.Save(file);
Img.ImageUrl=file;
image.Dispose();
newImage.Dispose();
}
上面會出現內存不足,請高手幫忙