如何上传已经修改过的图片?

dengyigeqingtian 2009-03-29 12:42:14
我通过FileUpload获得图片路径以后给图片加上水印和改变图片大小,我怎么上传编辑过的图片啊?FileUpload.postePdFile.SaveAs()的话得到的是原图的路径对吧,所有上传的也是原图,我把编辑过的图片保存好以后要怎么把它上传呢?或者有什么别的方法?
谢谢指教啊~~~~
...全文
189 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
pdsnet 2009-03-30
  • 打赏
  • 举报
回复
我以为我的答案 文不对题 ..⊙﹏⊙b汗
pdsnet 2009-03-29
  • 打赏
  • 举报
回复
protected void Button1_Click(object sender, EventArgs e)
{
if (this.flImage.HasFile)
{
Graphics g = null;
System.Drawing.Image upImage = null;
System.Drawing.Image thumimg = null;
System.Drawing.Image simage = null;
Bitmap outputFile = null;
string filename1 = flImage.PostedFile.FileName;
int pos = filename1.LastIndexOf(".");
string extension = filename1.Substring((pos + 1)).ToLower();
if (extension != "jpg" && extension != "gif" && extension != "jpeg" && extension != "bmp")
{
ChangeHope_fc.Show_Msg("提示:图片格式必须是bmp、jpeg、gif、jpg中的一种!", "YX_Upfile4.aspx");
}
string fileName = DateTime.Now.ToString("yyyyMMddhhmmss").ToLower();//用时间来定义文件名,以免重复
try
{
//保存路径
string savedPath = Server.MapPath("~") + "\\YX_UpFile\\Big\\";
string saveSnPath = Server.MapPath("~") + "\\YX_UpFile\\SNPic\\";
int width, height, newWidth, newHeight;
System.Drawing.Image.GetThumbnailImageAbort callb = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
//水印文件
simage = System.Drawing.Image.FromFile(Server.MapPath("~/YX_UpFile/SNPic/yixiang.jpg"));
//保存上传的图片
upImage = System.Drawing.Image.FromStream(flImage.PostedFile.InputStream);
//宽
width = upImage.Width;
//高
height = upImage.Height;
if (width > height)
{
newWidth = 200;
newHeight = (int)((double)height / width * newWidth);
}
else
{
newHeight = 200;
newWidth = (int)((double)width / height * newHeight);
}
//保存缩略图的各项长 宽 高
thumimg = upImage.GetThumbnailImage(newWidth, newHeight, callb, IntPtr.Zero);
outputFile = new Bitmap(upImage);
g = Graphics.FromImage(outputFile);
// 在上传的图片上绘制水印图片。
g.DrawImage(simage,
new Rectangle(upImage.Width - simage.Width, upImage.Height - simage.Height, upImage.Width, upImage.Height),
0,
0,
upImage.Width,
upImage.Height,
GraphicsUnit.Pixel);
string newPath = savedPath + fileName + "." + extension;// 带水印的大图片路径
string thumPath = saveSnPath + fileName + "." + extension;// 缩略图路径
string big = "YX_UpFile/Big/" + fileName + "." + extension;// 保存带水印的大图片
string small = "YX_UpFile/SNPic/" + fileName + "." + extension;
outputFile.Save(newPath); //保存大图片
thumimg.Save(thumPath);// 保存缩略图
Response.Write("<script>parent.document.form1.imgUrl2.value+='" + big + "|';</script>");
Response.Write("<script>parent.document.form1.imgUrl3.value+='" + small + "|';</script>");
outputFile.Dispose();
}
catch
{
ChangeHope_fc.Show_Msg("对不起,为图片添加水印图片时失败,请重试!", "YX_Upfile4.aspx");
}
finally
{
if (g != null)
{
g.Dispose();
}
if (thumimg != null)
{
thumimg.Dispose();
}
if (upImage != null)
{
upImage.Dispose();
}
if (simage != null)
{
simage.Dispose();
}
}
}
else
{
ChangeHope_CMS.Show_Msg("提示:请您选择文件!");
}
}
private bool ThumbnailCallback()
{
return false;
}
pdsnet 2009-03-29
  • 打赏
  • 举报
回复
protected void Button1_Click(object sender, EventArgs e)
{
if (this.flImage.HasFile)
{
Graphics g = null;
System.Drawing.Image upImage = null;
System.Drawing.Image thumimg = null;
System.Drawing.Image simage = null;
Bitmap outputFile = null;
string filename1 = flImage.PostedFile.FileName;
int pos = filename1.LastIndexOf(".");
string extension = filename1.Substring((pos + 1)).ToLower();
if (extension != "jpg" && extension != "gif" && extension != "jpeg" && extension != "bmp")
{
ChangeHope_fc.Show_Msg("提示:图片格式必须是bmp、jpeg、gif、jpg中的一种!", "YX_Upfile4.aspx");
}
string fileName = DateTime.Now.ToString("yyyyMMddhhmmss").ToLower();//用时间来定义文件名,以免重复
try
{
//保存路径
string savedPath = Server.MapPath("~") + "\\YX_UpFile\\Big\\";
string saveSnPath = Server.MapPath("~") + "\\YX_UpFile\\SNPic\\";
int width, height, newWidth, newHeight;
System.Drawing.Image.GetThumbnailImageAbort callb = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
//水印文件
simage = System.Drawing.Image.FromFile(Server.MapPath("~/YX_UpFile/SNPic/yixiang.jpg"));
//保存上传的图片
upImage = System.Drawing.Image.FromStream(flImage.PostedFile.InputStream);
//宽
width = upImage.Width;
//高
height = upImage.Height;
if (width > height)
{
newWidth = 200;
newHeight = (int)((double)height / width * newWidth);
}
else
{
newHeight = 200;
newWidth = (int)((double)width / height * newHeight);
}
//保存缩略图的各项长 宽 高
thumimg = upImage.GetThumbnailImage(newWidth, newHeight, callb, IntPtr.Zero);
outputFile = new Bitmap(upImage);
g = Graphics.FromImage(outputFile);
// 在上传的图片上绘制水印图片。
g.DrawImage(simage,
new Rectangle(upImage.Width - simage.Width, upImage.Height - simage.Height, upImage.Width, upImage.Height),
0,
0,
upImage.Width,
upImage.Height,
GraphicsUnit.Pixel);
string newPath = savedPath + fileName + "." + extension;// 带水印的大图片路径
string thumPath = saveSnPath + fileName + "." + extension;// 缩略图路径
string big = "YX_UpFile/Big/" + fileName + "." + extension;// 保存带水印的大图片
string small = "YX_UpFile/SNPic/" + fileName + "." + extension;
outputFile.Save(newPath); //保存大图片
thumimg.Save(thumPath);// 保存缩略图
Response.Write("<script>parent.document.form1.imgUrl2.value+='" + big + "|';</script>");
Response.Write("<script>parent.document.form1.imgUrl3.value+='" + small + "|';</script>");
outputFile.Dispose();
}
catch
{
ChangeHope_fc.Show_Msg("对不起,为图片添加水印图片时失败,请重试!", "YX_Upfile4.aspx");
}
finally
{
if (g != null)
{
g.Dispose();
}
if (thumimg != null)
{
thumimg.Dispose();
}
if (upImage != null)
{
upImage.Dispose();
}
if (simage != null)
{
simage.Dispose();
}
}
}
else
{
ChangeHope_CMS.Show_Msg("提示:请您选择文件!");
}
}
private bool ThumbnailCallback()
{
return false;
}
pdsnet 2009-03-29
  • 打赏
  • 举报
回复
上传的时候给图片加上水印和改变图片大小
dengyigeqingtian 2009-03-29
  • 打赏
  • 举报
回复
哈哈~~谢谢3楼~~之前有点烦躁,后来看了你的代码,改了自己的现在成功了~谢谢~
谢谢6楼帮顶~
dengyigeqingtian 2009-03-29
  • 打赏
  • 举报
回复
是上传好图片以后再加水印和改变它的大小?
itcrazyman 2009-03-29
  • 打赏
  • 举报
回复
up
dengyigeqingtian 2009-03-29
  • 打赏
  • 举报
回复
我只要知道怎么上传改过的图片,谢谢
dengyigeqingtian 2009-03-29
  • 打赏
  • 举报
回复
我只要知道怎么上传改过的图片,谢谢

62,267

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧