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

首頁 > 開發 > 綜合 > 正文

C#生成縮略圖代碼

2024-07-21 02:25:55
字體:
來源:轉載
供稿:網友

if(fileupload.postedfile!=null)
{
//addto為要添加的屬性,aboutfile為文件說明
string nam = fileupload.postedfile.filename ;
//取得文件名(抱括路徑)里最后一個"."的索引
int i= nam.lastindexof(".");
//取得文件擴展名
string newext =nam.substring(i);
//這里我自動根據日期和文件大小不同為文件命名,確保文件名不重復
datetime now = datetime.now;
string newname=now.dayofyear.tostring()+fileupload.postedfile.contentlength.tostring();
//保存文件到你所要的目錄,這里是iis根目錄下的upload目錄.你可以改變.
//注意: 我這里用server.mappath()取當前文件的相對目錄.在asp.net里"/"必須用"http://"代替,把"upload//"改成"http://upload//"就成了取當前文件的絕對目錄了
fileupload.postedfile.saveas(server.mappath("upload//"+newname+newext));
//得到這個文件的相關屬性:文件名,文件類型,文件大小
//fname.text=myfile.postedfile.filename;
//fenc.text=myfile.postedfile.contenttype ;
//fsize.text=myfile.postedfile.contentlength.tostring();
//下面是生成縮略圖
system.drawing.image image,anewimage;
int width,height,newwidth,newheight;
image=system.drawing.image.fromfile(server.mappath("upload/"+newname.tostring()+newext.tostring()));
system.drawing.image.getthumbnailimageabort callb =new system.drawing.image.getthumbnailimageabort(thumbnailcallback);
width=image.width;
height=image.height;
if(firstpageshow.selectedvalue.tostring()=="1"&&fenlei.selectedvalue.tostring()=="5")
{
newwidth=203;newheight=86;
newheight=height*newwidth/width;
}
else if(isweekman.selectedvalue.tostring()=="1")
{
newwidth=171;newheight=111;
newheight=height*newwidth/width;
}
else if(firstpageshow.selectedvalue.tostring()=="1"&&fenlei.selectedvalue.tostring()=="3")
{
newwidth=171;newheight=111;
newheight=height*newwidth/width;
}
else
{
newwidth=62;newheight=80;
newheight=height*newwidth/width;
}
anewimage=image.getthumbnailimage(newwidth,newheight,callb,new system.intptr());
anewimage.save(server.mappath("upload//"+"small_"+newname+newext));
image.dispose();
//生成縮略圖 生成并保存完畢,保存名是在原圖名前加了一個small_。
pic="upload/"+newname.tostring()+newext.tostring();
smallpic="upload/small_"+newname.tostring()+newext.tostring();
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 同江市| 珲春市| 邛崃市| 梁河县| 仙居县| 郓城县| 铜鼓县| 玉田县| 平顺县| 旬邑县| 同德县| 巴青县| 简阳市| 达州市| 金乡县| 天峻县| 津市市| 奉新县| 合山市| 伊金霍洛旗| 武夷山市| 长海县| 延安市| 乐亭县| 扎鲁特旗| 茂名市| 渝北区| 宜川县| 临夏市| 碌曲县| 叙永县| 武汉市| 晋江市| 宝坻区| 临城县| 宾阳县| 武强县| 峡江县| 安泽县| 宁安市| 锡林浩特市|