Probe into the source--system.drawing of class library

Source: Internet
Author: User
Tags prototype definition

I. A brief description of the System.Drawing namespace

The System.Drawing namespace provides the basic functionality to access GDI +, more advanced features in the system.drawing.drawing2d,system.drawing.imaging and System.Drawing.Text namespaces

Assembly: System.Drawing.dll

Ii. Brief introduction of System.Drawing.Image

Image class: An abstract base class that provides functionality for classes originating from Bitmap and Metafile

Namespaces: System.Drawing

Assembly: System.Drawing.dll

Prototype definition:

[Serializabaleattribute][comvisibleattribute (true)][typeconverterattribute (  typeof(ImageConverter))]publicabstractclass Image:marshalbyrefobject, ISerializable, ICloneable, IDisposable

Common Instance Properties:

Height gets the altitude (in pixels) of the current image instance

Width gets the widths (in pixels) of the current image instance

HorizontalResolution get the horizontal resolution (pixels/inch) of the current image instance

VerticalResolution get the vertical resolution (pixels/inch) of the current image instance

Physicaldimension Gets the width and height of the current image.

Rawformat getting the current image format

PixelFormat gets the pixel format of the current image

Code:

1 usingSystem;2 usingSystem.Drawing;3 4 classApp5 {6     Static voidMain ()7     {8         varimg = Image.FromFile (@"image format. jpg");//image format. png to name extension9 Console.WriteLine (img. Height);Ten Console.WriteLine (img. Width); One Console.WriteLine (img. HorizontalResolution); A Console.WriteLine (img. verticalresolution); - Console.WriteLine (img. physicaldimension); - Console.WriteLine (img. Physicaldimension.width); the Console.WriteLine (img. Physicaldimension.height); - Console.WriteLine (img.        Rawformat);  -Console.WriteLine (IMG. Rawformat.equals (System.Drawing.Imaging.ImageFormat.Png));//whether it is in Png format -Console.WriteLine (IMG. Rawformat.equals (System.Drawing.Imaging.ImageFormat.Jpeg));//whether it is a JPG format, not an extension myoji jpg is not equal to the image format is Jpeg + Console.WriteLine (img. PixelFormat); -     } +}
View Code

Effect

Download the code attached to this section


Common static methods:

public static image FromFile (string filename) creates an image from the specified file

public static image FromStream (Stream stream) creates an image from the specified data stream

Common example methods:

Public Image getthumbnailimage (int thumbwidth,int Thumbheight,system.drawing.image.getthumbnailimageabort callback, INTPTR callbackdata) Returns the thumbnail of this image

RotateFlip rotation

public void Save (string filename) saves the Image to the specified file or stream

Code:

usingSystem;usingSystem.Drawing;classapp{Static voidMain () {using(varimg = Image.FromFile (@"image format. jpg"))        {                            //generate thumbnail images            varThumbimg = img. Getthumbnailimage ( the, -, () =>{return false;},intptr.zero); Thumbimg.save (@"image Format _thumb.jpg"); //Image Rollover            varNewimg = img. Clone () asImage;            Newimg.rotateflip (ROTATEFLIPTYPE.ROTATE180FLIPX); Newimg.save (@"image Format _x axis flip 180 degrees. jpg"); }    }}

Download the code attached to this section

Probe into the source--system.drawing of class library

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.