Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write a. Net compressed bitmap to JPEG code

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "how to write a. Net compressed bitmap to JPEG code", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to write a. Net compressed bitmap to JPEG code.

First prepare a bitmap image source.bmp and save it in the same directory as bmp.aspx

The copy code is as follows:

Private void Page_Load (object sender, System.EventArgs e)

{

/ / set the mime type to image/jpeg, and output the image in JPGE format to the browser soon.

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 100Max quality is 100mm

System.Drawing.Imaging.EncoderParameter encoderParam = new System.Drawing.Imaging.EncoderParameter (System.Drawing.Imaging.Encoder.Quality, quality)

EncoderParams.Param [0] = encoderParam

ImageCodecInfo [] arrayICI = ImageCodecInfo.GetImageEncoders (); / / gets the ImageCodecInfo object that contains 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); / / saves bitmap objects in stream format and JPEG codec parameters to the output stream.

}

/ / clean up

OutputBitmap.Dispose ()

}

Enter: http://localhost/bmp.aspx?comp=0 in the browser address

You will see the image, adjust the value of comp, and you will see a different effect.

At this point, I believe you have a deeper understanding of "how to write a. Net compressed bitmap to JPEG code". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report