一、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的像素格式

代码:

 using System;
using System.Drawing; class App
{
static void Main()
{
var img = Image.FromFile(@"图像格式.jpg"); // 图像格式.png 改扩展名而来
Console.WriteLine(img.Height);
Console.WriteLine(img.Width);
Console.WriteLine(img.HorizontalResolution);
Console.WriteLine(img.VerticalResolution);
Console.WriteLine(img.PhysicalDimension);
Console.WriteLine(img.PhysicalDimension.Width);
Console.WriteLine(img.PhysicalDimension.Height);
Console.WriteLine(img.RawFormat);
Console.WriteLine(img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Png)); // 是否是 Png 格式
Console.WriteLine(img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg)); // 是否是 jpg 格式 ,不是扩展名氏 jpg 不等于图像格式就是 Jpeg
Console.WriteLine(img.PixelFormat);
}
}

效果

附本小节代码下载

常用静态方法:

public static Image FromFile(string filename)                  从指定文件创建 Image

public static Image FromStream(Stream stream)            从指定数据流创建 Image

常用实例方法:

public Image GetThumbnailImage(int thumbWidth,int thumbHeight,System.Drawing.Image.GetThumbnailImageAbort callback,IntPtr callbackData)       返回此 Image 的缩略图

RotateFlip                                     旋转

public void Save(string filename)       将该 Image 保存到指定的文件或流

代码:

using System;
using System.Drawing; class App
{
static void Main()
{
using(var img = Image.FromFile(@"图像格式.jpg"))
{
// 生成缩略图
var thumbImg = img.GetThumbnailImage(,,()=>{return false;},IntPtr.Zero);
thumbImg.Save(@"图像格式_thumb.jpg"); // 图像翻转
var newImg = img.Clone() as Image;
newImg.RotateFlip(RotateFlipType.Rotate180FlipX);
newImg.Save(@"图像格式_X轴翻转180度.jpg");
}
}
}

附本小节代码下载

类库探源——System.Drawing的更多相关文章

  1. 类库探源——System.Drawing.Bitmap

    一.System.Drawing.Bitmap Bitmap 类: 封装GDI+ 位图,此位图由图形图像及其属性的像素数据组成.Bitmap 是用于处理由像素定义的图像的对象 命名空间: System ...

  2. 类库探源——System.Delegate

    一.MSDN 描述 Delegate 类:表示委托,委托是一种数据结构,它引用静态方法或引用类实例及该类的实例方法.(是不是感觉很像C语言中的函数指针 :) ) 命名空间: System 程序集:   ...

  3. 类库探源——System.Configuration 配置信息处理

    按照MSDN描述 System.Configuration 命名空间 包含处理配置信息的类型 本篇文章主要两方面的内容 1. 如何使用ConfigurationManager 读取AppSetting ...

  4. 类库探源——System.Math 和 Random

    一.System.Math Math类:为三角函数.对数函数和其他通用数学函数提供常数和静态方法 命名空间: System 程序集 :   mscorlib.dll 继承关系: 常用属性: Math. ...

  5. 类库探源——System.ValueType

    一.MSDN描述 ValueType 类:提供值类型的基类 命名空间: System 程序集:   mscorlib.dll 继承关系: 值类型包括:字符.整数.浮点.布尔.枚举.结构(其实字符.整数 ...

  6. 类库探源——System.Environment

    Environment 类: 提供有关当前环境和平台的信息以及操作它们的方法.此类不能被继承. 命名空间: System 程序集:   mscorlib.dll 继承关系: 常用属性(字段)和方法: ...

  7. 类库探源——System.Exception

    一.MSDN描述 Exception 类: 表示在应用程序执行期间发生的错误 命名空间 : System 程序集:   mscorlib.dll 继承关系: 常用属性(含字段)和方法: 1. 属性Me ...

  8. 类库探源——System.String

    一.MSDN描述 String 类: 表示文本,即一系列的 Unicode 字符 命名空间 : System 程序集 : mscorlib.dll 继承关系: 备注: 1. 字符串是 Unicode ...

  9. 类库探源——System.Type

    一.MSDN 描述 Type 类:表示类型声明:类类型.接口类型.数组类型.值类型.枚举类型.类型参数.泛型类型定义.以及开放或封闭构造的泛型类型. 命名空间: System 程序集:mscorlib ...

随机推荐

  1. shell color

    shell 输出着色 格式: echo "/033[字背景颜色;字体颜色m字符串/033[控制码" 如果单纯显示字体颜色可以固定控制码位0m. 格式: echo "/03 ...

  2. Yii目录树扩展ztree,ctree等

    ztree: http://blog.csdn.net/jake451/article/details/7091449 http://hi.baidu.com/qiangtan/item/e85c48 ...

  3. 数值类对象:NSNumber,NSValue,NSNull

    基本,集合,复杂,对象 可用对象封装基本数值,然后将对象放入NSArray或NSDictionary 中. 用对象封装基本数值后,即可给其发送消息. 数值类型包括:NSNumber,NSValue,N ...

  4. Android中解析JSON格式数据常见方法合集

    待解析的JSON格式的文件如下: [{"id":"5", "version":"1.0", "name&quo ...

  5. PHP基本语法(一)

    整形:就是对用整数  正整数与负整数整形的表示:int integer NOTICE:写整形的时候不要在外面再加引号了 浮点:就是小数 3.1415926Float 浮点 布尔值:男和女 真和假 阴和 ...

  6. Mac下eclipse安装SVN插件

    eclipse中最常使用的SVN插件是subclipse,先到subclipse官网:http://subclipse.tigris.org下载该插件.   如上图,点击“Download and I ...

  7. C学习笔记之预处理指令

          一.什么是预处理指令            预处理指令是告诉编译器在编译之前预先处理的一些指令,有宏定义,文件包括,条件编译. 预处理指令一般以 # 号开头,能够出如今文件的不论什么地方, ...

  8. PERCONA-TOOLKIT 工具的安装与使用2

    [root@server-mysql ~]# cd /usr/bin [root@server-mysql bin]# ls pt* pt-align pt-duplicate-key-checker ...

  9. JVM专题

    http://blog.csdn.net/ITer_ZC/article/category/2758863

  10. 如何编译libcurl

    1. Android •1.1配置 •1.2 Make •1.3的参数配置 2.iOS 3.windows 4.关于头文件 注释 本文档介绍了如何为Android,iOS和Windows编译libcu ...