国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 房山区| 时尚| 富锦市| 中超| 巴林右旗| 抚州市| 锡林浩特市| 道孚县| 盘锦市| 济南市| 南溪县| 安顺市| 延安市| 甘德县| 广平县| 灵丘县| 景谷| 喀什市| 商南县| 新津县| 广宁县| 林州市| 龙口市| 灵丘县| 万源市| 汾阳市| 柞水县| 醴陵市| 伊春市| 西安市| 宜城市| 城市| 兰溪市| 金塔县| 通州市| 怀化市| 丰城市| 呼玛县| 太和县| 靖江市| 全椒县|