一、System.Drawing 命名空间简述

System.Drawing 命名空间提供访问 GDI+ 的基本功能,更高级的功能在 System.Drawing.Drawing2D,System.Drawing.Imaging 和 System.Drawing.Text 命名空间

程序集: System.Drawing.dll

 

二、System.Drawing.Image 简述

Image 类:为源自 Bitmap 和 Metafile 的类提供功能的抽象基类

命名空间: System.Drawing

程序集:   System.Drawing.dll

原型定义:

[SerializabaleAttribute]
[ComVisibleAttribute(true)]
[TypeConverterAttribute(typeof(ImageConverter))]
public abstract class Image : MarshalByRefObject, ISerializable, ICloneable, IDisposable

 

常用实例属性:

Height            获取当前图像实例的 高度(以像素为单位)

Width            获取当前图像实例的 宽度(以像素为单位)

HorizontalResolution          获取当前图像实例的水平分辨率(像素/英寸)

VerticalResolution             获取当前图像实例的垂直分辨率(像素/英寸)

PhysicalDimension           获取当前图像的宽度和高度。

RawFormat                    获取当前图像格式

PixelFormat                  获取当前Image的像素格式

代码:

 1 using System;
 2 using System.Drawing;
 3 
 4 class App
 5 {
 6     static void Main()
 7     {
 8         var img = Image.FromFile(@"图像格式.jpg");    // 图像格式.png 改扩展名而来        
 9         Console.WriteLine(img.Height);
10         Console.WriteLine(img.Width);
11         Console.WriteLine(img.HorizontalResolution);
12         Console.WriteLine(img.VerticalResolution);
13         Console.WriteLine(img.PhysicalDimension);
14         Console.WriteLine(img.PhysicalDimension.Width);
15         Console.WriteLine(img.PhysicalDimension.Height);
16         Console.WriteLine(img.RawFormat);        
17         Console.WriteLine(img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Png)); // 是否是 Png 格式
18         Console.WriteLine(img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg)); // 是否是 jpg 格式 ,不是扩展名氏 jpg 不等于图像格式就是 Jpeg    
19         Console.WriteLine(img.PixelFormat);
20     }
21 }
View Code

相关文章:

  • 2021-05-28
  • 2022-02-03
  • 2021-10-11
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
  • 2021-04-07
  • 2021-06-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
  • 2021-09-04
相关资源
相似解决方案