C # solve the problem that the Image drawn by DrawImage becomes larger,

Source: Internet
Author: User

C # solve the problem that the Image drawn by DrawImage becomes larger,

For example:

Private Image image = Resources. image1; // assume that image1 is as large as 360x600.

Private Graphics graphics;

Graphics. DrawImage (image, 0, 0); // draw the image at the coordinates of [0, 0]. I will wipe it! The image is larger than the source image!

Why ???

It turns out that DrawImage is a device-related function, that is, DrawImage will bring the screen parameters !!!

Therefore, the DPI of the image is usually 96. Our images are usually 72DPI.

For example, assume that the width of an Image object is 216 pixels, And the stored horizontal resolution value is 72 points/inch. Because 216 divided by 72 is equal to 3, DrawImage scales the image
The width of the 96-point/inch resolution is 3 inch. That is to say, DrawImage will display an image with a width of 96x3 = 288 pixels.

Solution Law Office:

1: graphics. DrawImage (image, 0, 0, image. Width, image. Height); // you can add the Width and Height of the source image.

2: image. SetResolution (96, 96); // set SetResolution so that it is displayed at a 96-point/inch resolution.

Related Article

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.