日期:2014-05-18  浏览次数:20797 次

图片放大问题,急!
要求如下:

①确认指定文件夹内照片文件是否存在
②如果照片文件不存在就退出处理
③判断照片文件中有没有.jpg格式的文件,没有则退出处理
④如果.jpg文件存在,则取得jpg文件个数从第一个开始循环,每个jpg文件都进行下面5-8的处理
⑤.jpg文件的尺寸如果不是0进行⑥的处理
⑥根据jpg文件名在DB中检索flg=0的jpg进行⑦的处理
⑦把这个jpg文件转换成640×480尺寸(希望失真不要太严重)
⑧在数据库中把转换完成后的flg更新成1

大家帮帮忙。

------解决方案--------------------
需求很明确
------解决方案--------------------
给你生成一个jpg文件的代码吧


protected void Button1_Click(object sender, EventArgs e)
{
System.Drawing.Image myImage = System.Drawing.Image.FromFile(Server.MapPath("img/NX006.jpg"));
int imageWidth = myImage.Width;
int imageHeight = myImage.Height;
int[] iSize = ReducedSize(imageWidth,imageHeight,640,480);
System.Drawing.Image myImageTarget = myImage.GetThumbnailImage(iSize[0], iSize[1], new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
myImageTarget.Save(Server.MapPath("img/mmm.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
}

static private bool ThumbnailCallback()
{
return true;
}

private int[] ReducedSize(int imageWidth, int imageHeight, int targetWidth, int targetHeight)
{
int reducedWidth = imageWidth;
int reducedHeight = imageHeight;
int[] result = new int[2];

if (!(imageWidth - targetWidth < 0 && imageHeight - targetHeight < 0))
{
if ((imageWidth * 1.0 / targetWidth) > (imageHeight * 1.0 / targetHeight))
{
reducedWidth = targetWidth;
reducedHeight = (targetWidth * imageHeight) / imageWidth;
}
else
{
reducedWidth = (targetHeight * imageWidth) / imageHeight;
reducedHeight = targetHeight;
}
}

result[0] = reducedWidth;
result[1] = reducedHeight;
return result;
}
------解决方案--------------------
对不起 代码是错误的
------解决方案--------------------
帮你顶吧
------解决方案--------------------
③判断照片文件中有没有.jpg格式的文件,没有则退出处理
string sfiles[] = File.GetFiles("*.jpg")

⑦把这个jpg文件转换成640×480尺寸(希望失真不要太严重)
image oimage = Image.GetThumbnailImage(...)