首先准备一张位图图像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的值将会看到不同的效果