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 .

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.