First prepare a bitmap image source.bmp, save it in bmp.aspx same directory
Copy Code code as follows:
<%@ 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)
{
Sets the MIME type to Image/jpeg and is about to output JPGE-formatted 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 highest quality of 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 ImageCodecInfo object that contains information about the built-in image codec.
ImageCodecInfo jpegici = null;
for (int x = 0; x < Arrayici.length + +)
{
if (arrayici[x). Formatdescription.equals ("JPEG"))
{
Jpegici = arrayici[x];//Set JPEG encoding
Break
}
}
if (Jpegici!= null)
{
Outputbitmap.save (Response.outputstream, Jpegici, Encoderparams)//bitmap objects are saved to the output stream in streaming format and JPEG codec parameters.
}
Clean up
Outputbitmap.dispose ();
}
</script>
In browser address input: http://localhost/bmp.aspx?comp=0
You will see the image, adjust the value of the comp, and you will see different effects.