C # generates HD thumbnails from large pictures

Source: Internet
Author: User

C # generates HD thumbnail code, a C # function module, contains annotations, followed by function parameters, see this C # generated thumbnail code:

01public static void Setgoodimage (String fileName, string newFile, int maxheight, int maxwidth,long qualitys)

229

if (qualitys = 0)

04 {

Qualitys = 80;

06}

Modified using (System.Drawing.Image img = System.Drawing.Image.FromFile (fileName))

08 {

System.Drawing.Imaging.ImageFormat

Ten Thisformat = img. Rawformat;

One Size newsize = newsize (maxwidth, MaxHeight, IMG. Width, IMG. Height);

Bitmap outbmp = new Bitmap (newsize.width, newsize.height);

Graphics g = graphics.fromimage (outbmp);

14//Set the painting quality of the canvas

g.compositingquality = compositingquality.highquality;

G.smoothingmode = smoothingmode.highquality;

G.interpolationmode = Interpolationmode.highqualitybicubic;

G.drawimage (IMG, new Rectangle (0, 0, Newsize.width, newsize.height),

0, 0, IMG. Width, IMG. Height, GraphicsUnit.Pixel);

G.dispose ();

21//The following code to save the picture, set the compression quality

EncoderParameters encoderparams = new EncoderParameters ();

long[] quality = new LONG[1];

Quality[0] = Qualitys;

Encoderparameter Encoderparam = new Encoderparameter (System.Drawing.Imaging.Encoder.Quality, Quality);

Encoderparams.param[0] = Encoderparam;

27//Get the ImageCodecInfo object containing information about the built-in image codec.

imagecodecinfo[] Arrayici = Imagecodecinfo.getimageencoders ();

ImageCodecInfo jpegici = null;

for (int x = 0;

x < arrayici.length;

X + +)

33 {

if (Arrayici[x]. Formatdescription.equals ("JPEG"))

35 {

Jpegici = Arrayici[x];

37//Set JPEG encoding

break;

39}

40}

if (Jpegici!= null)

42 {

Outbmp.save (NewFile, Jpegici, encoderparams);

44}

Or else

46 {

Outbmp.save (NewFile, Thisformat);

48}

The IMG. Dispose ();

Outbmp.dispose ();

51}

52}

Function parameter Description:

View sourceprint?1///Original file

2///New File

3///Max Height

4///Max width

5///quality, if 0, then set to 80

Note : Please pay attention to the triple programming Tutorials section for more wonderful articles .

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.