国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net生成縮略圖及給原始圖加水印

2024-07-10 12:55:50
字體:
供稿:網(wǎng)友
using system.io;
using system.drawing.imaging;

private void button1_serverclick(object sender, system.eventargs e)
{
graphics g=null;
system.drawing.image upimage=null;
system.drawing.image thumimg=null;
system.drawing.image simage=null;
bitmap outputfile=null;
try
{
string extension = path.getextension(file1.postedfile.filename).toupper();
string filename = datetime.now.tostring("yyyymmddhhmmss");
string smallpath = server.mappath(".")+"/smallimg/";
string bigpath = server.mappath(".")+"/bigimg/";
int width,height,newwidth,newheight;

system.drawing.image.getthumbnailimageabort callb =new system.drawing.image.getthumbnailimageabort(thumbnailcallback);
if(!directory.exists(smallpath))
directory.createdirectory(smallpath);
if(!directory.exists(bigpath))
directory.createdirectory(bigpath);

stream upimgfile = file1.postedfile.inputstream;
string simagefile = server.mappath("a8logo.jpg"); //要加水印的文件
simage=system.drawing.image.fromfile(simagefile);
upimage= system.drawing.image.fromstream(upimgfile); //上傳的圖片

width = upimage.width;
height = upimage.height;
if(width>height)
{
newwidth=200;
newheight =(int)((double)height/(double)width * (double)newwidth);
}
else
{
newheight=200;
newwidth=(int)((double)width/(double)height * (double)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 = bigpath + filename + extension; //原始圖路徑
string thumpath = smallpath + filename + extension; //縮略圖路徑
outputfile.save(newpath);
thumimg.save(thumpath);
outputfile.dispose();

}
catch(exception ex)
{
throw ex;
}
finally
{
if(g!=null)
g.dispose();
if(thumimg!=null)
thumimg.dispose();
if(upimage!=null)
upimage.dispose();
if(simage!=null)
simage.dispose();
}
}
public bool thumbnailcallback()
{
return false;
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 中超| 报价| 安阳市| 布尔津县| 丽江市| 泾阳县| 长泰县| 平和县| 华宁县| 洪泽县| 宁津县| 抚远县| 临泉县| 天等县| 大理市| 兴安县| 平阳县| 禄丰县| 泽州县| 永德县| 青海省| 曲阜市| 丽水市| 临桂县| 彭阳县| 通辽市| 宜城市| 改则县| 裕民县| 新乐市| 班玛县| 庆城县| 平利县| 昌都县| 烟台市| 运城市| 慈溪市| 南召县| 项城市| 江油市| 麻栗坡县|