First, upload a map as source.bmp and save it in the same directory as bmp. aspx.
Copy codeThe Code is 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)
{
// Set the mime type to image/jpeg. The JPGE format image will be output to the browser.
Response. Clear ();
Response. ContentType = "image/jpeg ";
Bitmap OutputBitmap = new Bitmap (Server. MapPath ("source.bmp"); // create a 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 (); // obtain the ImageCodecInfo object that contains information about the built-in image decoder.
ImageCodecInfo policici = null;
For (int x = 0; x <arrayICI. Length; x ++)
{
If (arrayICI [x]. FormatDescription. Equals ("JPEG "))
{
JpegICI = arrayICI [x]; // sets the JPEG encoding.
Break;
}
}
If (policici! = Null)
{
OutputBitmap. Save (Response. OutputStream, jpegICI, encoderParams); // saves the bitmap object to the output stream in the stream format and uses the JPEG codec parameter.
}
// Clean up
OutputBitmap. Dispose ();
}
</Script>
Enter http: // localhost/bmp. aspx in the browser address? Comp = 0
The image is displayed, and the value of comp is adjusted. Different effects are displayed.