C# System.Drawing、Graphics、Image、Bitmap


 

System.Drawing 命名空間

System.Drawing 命名空間提供了對 GDI+ 基本圖形功能的訪問。 System.Drawing.Drawing2DSystem.Drawing.ImagingSystem.Drawing.Text 命名空間中提供了更高級的功能。

Graphics 類提供了繪制到顯示設備的方法。 諸如 RectanglePoint 等類可封裝 GDI+ 基元。 Pen 類用於繪制直線和曲線,而從抽象類 Brush 派生出的類則用於填充形狀的內部。

請參考MSDN:http://msdn.microsoft.com/zh-cn/library/xs6ftd89

 

 

Graphics 類

Graphics 類提供將對象繪制到顯示設備的方法。 Graphics 與特定的設備上下文關聯。

 

Graphics object by calling the Control.CreateGraphics method on an object that inherits from System.Windows.Forms.Control, or by handling a control's Control.Paint event and accessing the Graphics property of the System.Windows.Forms.PaintEventArgs class.">通過調用繼承自 System.Windows.Forms.Control 的對象上的 Control.CreateGraphics 方法,或通過處理控件的 Control.Paint 事件並訪問 System.Windows.Forms.PaintEventArgs 類的 Graphics 屬性,可以獲取 Graphics 對象。 也可以使用 FromImage 方法從圖像創建 Graphics 對象。 有關創建 Graphics 對象的更多信息,請參見如何:創建用於繪制的 Graphics 對象

 

可以使用 Graphics 對象繪制許多不同的形狀和線條。 有關如何繪制線條和形狀的更多信息,請參見針對要繪制的線條或形狀的特定 DrawGraphicalElement 方法。 這些方法包括 DrawLineDrawArcDrawClosedCurveDrawPolygonDrawRectangle 有關如何繪制線條和形狀的更多信息,請參見使用鋼筆繪制線條和形狀使用畫筆填充形狀

 

還可以分別使用 DrawImageDrawIcon 方法來繪制圖像和圖標。 要執行顏色數據從屏幕到 Graphics 對象的繪圖圖面的位塊傳輸,請參見CopyFromScreen 有關如何使用 Graphics 對象繪制圖像的更多信息,請參見使用圖像、位圖、圖標和圖元文件

 

此外,您可以操作由 Graphics 對象使用的坐標系。 有關坐標系及其操作方法的更多信息,請參見坐標系和坐標變換

 

private  void Form1_Paint( object sender, System.Windows.Forms.PaintEventArgs pe) 
{
    //  Declares the Graphics object and sets it to the Graphics object
   
//  supplied in the PaintEventArgs.
   Graphics g = pe.Graphics;
    //  Insert code to paint the form here.
}

 

Graphics g;
//  Sets g to a graphics object representing the drawing surface of the
//  control or form g is a member of.
g =  this.CreateGraphics();

 

Bitmap myBitmap =  new Bitmap( @" C:\Documents and 
   Settings\Joe\Pics\myPic.bmp
");
Graphics g = Graphics.FromImage(myBitmap);

 

 

示例:TARGET.DrawImage(SOURCE, xx, ...)

 

//  Uses the System.Environment.GetFolderPath to get the path to the current user's MyPictures folder.
Bitmap myBitmap =  new Bitmap (System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures));
//  Creates a Graphics object that represents the drawing surface of Button1.
Graphics g = Button1.CreateGraphics();
g.DrawImage(myBitmap,  11);

 

請參考MSDN:http://msdn.microsoft.com/zh-cn/library/ac148eb3

 

 

Image 類

為源自 BitmapMetafile 的類提供功能的抽象基類。

請參考MSDN:http://msdn.microsoft.com/zh-cn/library/system.drawing.image

 

 

Bitmap 類

封裝 GDI+ 位圖,此位圖由圖形圖像及其特性的像素數據組成。 Bitmap 是用於處理由像素數據定義的圖像的對象。

 

備注:

位圖由圖形圖像及其特性的像素數據組成。 可使用許多標准格式將位圖保存到文件中。 GDI+ 支持下列文件格式:BMP、GIF、EXIF、JPG、PNG 和 TIFF。 有關支持的格式的更多信息,請參見位圖類型

可以使用 Bitmap 構造函數中的一種來從文件、流和其他源創建圖像,然后使用 Save 方法將這些圖像保存到流或文件系統中。 使用 Graphics 對象的 DrawImage 方法,將圖像繪制到屏幕上或內存中。 有關使用圖像文件的主題的列表,請參見使用圖像、位圖、圖標和圖元文件

 

請參考MSDN:http://msdn.microsoft.com/zh-cn/library/system.drawing.bitmap

 

 

 

顏色與圖像

1、什么是RGB、CMYK、HSB顏色模型?

2、什么是灰度?

3、什么是單色位圖、16色位圖、256色位圖、24位位圖?

4、什么是調色板?

5、什么是Alpha通道?

6、常見圖像文件格式有哪些?什么區別?

7、什么是圖像分辨率?

8、圖像縮放原理是什么?

9、什么是矢量圖?

 

【參考】

圖像格式:http://baike.baidu.com/view/13674.htm

位圖BMP:http://baike.baidu.com/view/189487.htm

矢量圖:http://baike.baidu.com/view/138039.htm

Bitmap:http://en.wikipedia.org/wiki/Bitmap

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM