熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> ASP編程 >> 正文

一個.net 壓縮位圖至JPEG的代碼

2022-06-13   來源: ASP編程 

  首先准備一張位圖圖像sourcebmp將它保存在bmpaspx同一目錄中

  <%@ Page language=c# %> <%@ Import Namespace=SystemDrawing %> <%@ Import Namespace=SystemDrawingImaging %>

  <script language=c# runat=server>

  private void Page_Load(object sender SystemEventArgs e)

  {

  // 設置 mime 類型為image/jpeg即將向浏覽器輸出JPGE格式的圖像ResponseClear()ResponseContentType=image/jpeg

  Bitmap OutputBitmap = new Bitmap(ServerMapPath(sourcebmp))//新建BitMap對象SystemDrawingImagingEncoderParameters encoderParams = new SystemDrawingImagingEncoderParameters()long[] quality = new long[]

  int comp = if (RequestQueryString[comp] != ) { comp = ConvertToInt(RequestQueryString[comp]) } quality[] = comp // to 最高質量為 SystemDrawingImagingEncoderParameter encoderParam = new SystemDrawingImagingEncoderParameter(SystemDrawingImagingEncoderQuality quality)encoderParamsParam[] = encoderParam

  ImageCodecInfo[] arrayICI = ImageCodecInfoGetImageEncoders()//獲得包含有關內置圖像編碼解碼器的信息的ImageCodecInfo 對象

  ImageCodecInfo jpegICI = nullfor (int x = x < arrayICILength x++)

  { if (arrayICI[x]FormatDescriptionEquals(JPEG))

  { jpegICI = arrayICI[x]//設置JPEG編碼break}

  if (jpegICI != null)

  { OutputBitmapSave(ResponseOutputStream jpegICI encoderParams)//將位圖對象以流格式並用JPEG編解碼參數保存到輸出流

  }

  // clean up OutputBitmapDispose()

  } </script>在浏覽器地址輸入x?comp=將會看到圖像調整comp的值將會看到不同的效果


From:http://tw.wingwit.com/Article/program/ASP/201311/21720.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.