bmp.aspx
Author: Taote.com
Source: Taote.com
Note: Please indicate the source for reprinting.
First prepare a bitmap image source.bmp and save it in the same directory as bmp.aspx
<%@ Page language="c#" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<script language="c#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
// Set the mime type to image/jpeg, which will output JPGE format images to the browser.
Response.Clear();
Response.ContentType="image/jpeg";
Bitmap OutputBitmap = new Bitmap(Server.MapPath("source.bmp"));//New BitMap object
System.Drawing.Imaging.EncoderParameters encoderParams = new System.Drawing.Imaging.EncoderParameters();
long[] quality = new long[1];
int comp = 0;
if (Request.QueryString["comp"] != "") { comp = Convert.ToInt16(Request.QueryString["comp"]); }
quality[0] = comp; //0 to 100 The highest quality is 100
System.Drawing.Imaging.EncoderParameter encoderParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
encoderParams.Param[0] = encoderParam;
ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();//Get an ImageCodecInfo object containing information about the built-in image codec.
ImageCodecInfo jpegICI = null;
for (int x = 0; x < arrayICI.Length; x++)
{
if (arrayICI[x].FormatDescription.Equals("JPEG"))
{
jpegICI = arrayICI[x];//Set JPEG encoding
break;
}
}
if (jpegICI != null)
{
OutputBitmap.Save(Response.OutputStream, jpegICI, encoderParams);//Save the bitmap object to the output stream in stream format and using JPEG encoding and decoding parameters.
}
// clean up
OutputBitmap.Dispose();
}
</script>
Enter the browser address: http://localhost/bmp.aspx?comp=0
You will see the image, adjust the value of comp, and you will see different effects.