一、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. 解决 MyEclipse 10 中 JSp页面 “return false” 报错问题

    1.MyEclipse ->. Preferences 2.validation ->>找到JavaScript validator for Js files  builder 下面 ...

  2. linux驱动程序之电源管理之linux的电源管理架构(3)

    设备电源管理 Copyright (c) 2010 Rafael J. Wysocki<rjw@sisk.pl>, Novell Inc. Copyright (c) 2010 Alan ...

  3. oracle 中的truncate 和delete

    一.查询表大小,块多少语句 Select SEGMENT_Name,BYTES,BLOCKS,Extents From dba_segments Where segment_name In('BAI_ ...

  4. Windows Azure 基本操作手册

    http://www.cnblogs.com/sennly/p/4139663.html 基本测试信息 登陆地址:https://manage.windowsazure.cn(Azure管理门户,适用 ...

  5. POJ3349: Snowflake Snow Snowflakes(hash 表)

    考察hash表: 每一个雪花都有各自的6个arm值,如果两个雪花从相同或者不同位置开始顺时针数或者逆时针数可以匹配上,那么这两个雪花就是相等的. 我们采用hash的方法,这样每次查询用时为O(1),总 ...

  6. ndk-gdb of NDK r9d modified to *always* debug the ":remote"-process of your app

    https://gist.github.com/TomTasche/9690186 ndk-gdb of NDK r9d modified to *always* debug the ":r ...

  7. Go语言简介

    Go语言简介 - Go语言是由Google开发的一个开源项目,目的之一为了提高开发人员的编程效率. Go语言简介 Go语言是由Google开发的一个开源项目,目的之一为了提高开发人员的编程效率. Go ...

  8. [置顶] 使用U盘安装ubuntu系统

    使用U盘安装ubuntu系统 在网上找了很多教程,都不起效,提示:“从光盘上读取数据出错”. 总结出了几个关键点. 首先,版本,Ubuntu 12.04 Server,一般的U盘安装都会报:“从光盘上 ...

  9. Ajax核心——XMLHttpRequest基础

    XMLHttpRequest对象负责将用户信息以异步方式发送到服务器,并接受服务器返回的相应信息和数据.也就是可以在页面已经加载后从后从服务器请求.接收数据,这样使得用户的体验度更好,而同时提升了客户 ...

  10. JAVA_3lesson

    程序设计守则 为了增加程序的可扩展性,维护性.可以采用interface, abstract   可以抽象出来:共同的方法,属性   开发系统时,主体构架使用接口,接口构成了系统的骨架.   要遵循开 ...