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

首頁 > 開發(fā) > 綜合 > 正文

關于system.drawing.imaging類的說明和范例

2024-07-21 02:26:11
字體:
供稿:網(wǎng)友

代碼段1
=========================
system.drawing.image image =
system.drawing.image.fromfile(originalfilename);
system.drawing.size size = getimagesize(image.width, image.height,
information.maximumdimension);
system.drawing.image bitmap = new system.drawing.bitmap(size.width,
size.height);
system.drawing.graphics graphics =
system.drawing.graphics.fromimage(bitmap);
graphics.interpolationmode =
system.drawing.drawing2d.interpolationmode.high;
graphics.smoothingmode = system.drawing.drawing2d.smoothingmode.highquality;
graphics.clear(information.backgroundcolor);
graphics.drawimage(image, new system.drawing.rectangle(0, 0, bitmap.width,
bitmap.height), new system.drawing.rectangle(0, 0, image.width,
image.height), system.drawing.graphicsunit.pixel);
graphics.dispose();


代碼段2
============================
//原始圖片名稱
string originalfilename = "c://222.jpg";
//生成的高質(zhì)量圖片名稱
string strgoodfile = "c://222-small-good.jpg";
//生成的低質(zhì)量圖片名稱
string strbadfile = "c://222-small-bad.jpg";
//縮小的倍數(shù)
int iscale = 3;

//從文件取得圖片對象
system.drawing.image image = system.drawing.image.fromfile(originalfilename);
//取得圖片大小
system.drawing.size size = new size(image.width / iscale , image.height / iscale);
//新建一個bmp圖片
system.drawing.image bitmap = new system.drawing.bitmap(size.width,size.height);
//新建一個畫板
system.drawing.graphics g = system.drawing.graphics.fromimage(bitmap);
//設置高質(zhì)量插值法
g.interpolationmode = system.drawing.drawing2d.interpolationmode.high;
//設置高質(zhì)量,低速度呈現(xiàn)平滑程度
g.smoothingmode = system.drawing.drawing2d.smoothingmode.highquality;
//清空一下畫布
g.clear(color.blue);
//在指定位置畫圖
g.drawimage(image, new system.drawing.rectangle(0, 0, bitmap.width, bitmap.height),
new system.drawing.rectangle(0, 0, image.width,image.height),
system.drawing.graphicsunit.pixel);
//保存高清晰度的縮略圖
bitmap.save(strgoodfile, system.drawing.imaging.imageformat.jpeg);
//取得原圖像的普通縮略圖
system.drawing.image img = image.getthumbnailimage(image.width / iscale, image.height / iscale, null, intptr.zero);
//保存普通縮略圖
img.save(strbadfile, system.drawing.imaging.imageformat.jpeg);

g.dispose();
messagebox.show("生成完畢");



俺自己寫的一段原圖+縮略圖代碼
===============================
using system;
using system.collections;
using system.componentmodel;
using system.configuration;
using system.data;
using system.drawing;
using system.drawing.imaging;
using system.web;
using system.web.sessionstate;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.htmlcontrols;

namespace bscrm.shangpin
{
 /// <summary>
 /// shangpin_img 的摘要說明。
 /// </summary>
 public class shangpin_img : system.web.ui.page
 {
  string imagepath = configurationsettings.appsettings["imagepath"]+"http://";
  bool error;
  string src;
  int height,width;
  private void page_load(object sender, system.eventargs e)
  {
   // 在此處放置用戶代碼以初始化頁面
   height=width=0;

   if(request["h"]!=null&&request["h"].tostring().trim()!="")
   {
    height=int.parse(request["h"].tostring().trim());
   }
   if(request["w"]!=null&&request["h"].tostring().trim()!="")
   {
    width=int.parse(request["w"].tostring().trim());
   }
        

   if(request["src"]!=null)
   {
    src = imagepath+request["src"].tostring();
    try
    {
     system.drawing.image img = system.drawing.image.fromfile(src);

     if(height>0||width>0)
     {
      if(height==0) height=img.height;
      if(width==0) width=img.width;
      system.drawing.image img2 = img.getthumbnailimage(width,height,null,intptr.zero);
      img2.save(response.outputstream,img.rawformat);
      img2.dispose();
     }
     else
     {
         img.save(response.outputstream,img.rawformat);
     }

     img.dispose();
    }
    catch
    {
     error = true;
    }
   }
   else
   {
    error = true;
   }

   if(error)
   {
    response.statuscode = 404;
    response.write("<html><head><title>object not found</title></head><body><h1>http/1.1 404 object not found</h1></body></html>");
   }
  }

  #region web 窗體設計器生成的代碼
  override protected void oninit(eventargs e)
  {
   //
   // codegen: 該調(diào)用是 asp.net web 窗體設計器所必需的。
   //
   initializecomponent();
   base.oninit(e);
  }
  
  /// <summary>
  /// 設計器支持所需的方法 - 不要使用代碼編輯器修改
  /// 此方法的內(nèi)容。
  /// </summary>
  private void initializecomponent()
  {   
   this.load += new system.eventhandler(this.page_load);
  }
  #endregion
 }
}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 买车| 商南县| 铅山县| 台山市| 松原市| 北川| 正定县| 清镇市| 方正县| 美姑县| 江口县| 德阳市| 通山县| 出国| 汉中市| 梓潼县| 民勤县| 合川市| 龙岩市| 乐平市| 连南| 柞水县| SHOW| 辽宁省| 孝昌县| 临汾市| 修水县| 罗田县| 平潭县| 秀山| 乐亭县| 陵川县| 逊克县| 阿勒泰市| 望都县| 鹤岗市| 高邑县| 壶关县| 乐陵市| 贡觉县| 巴里|