C#使用GDI中的API函数
来源:互联网 发布:如何下载数据精灵 编辑:程序博客网 时间:2024/05/11 03:57
我们知道在.NET 平台下主要是用GDI+来进行图形图像处理,在效率要求不高的情况下使用GDI+已经足够实现各种功能了,但一旦要求效率的情况下,我们可以考虑使用GDI来代替GDI+,网上有人士做过相关测试(本人也测试过),GDI在图形、图像绘制方面效率较GDI+有很大提高。下面将自己开发过程中整理到的NativeGdi32Api类贴出来:
public static class NativeGdi32Api { [ DllImport("gdi32.dll" )] public static extern int SetDIBits (IntPtr hdc, IntPtr hBitmap, int nStartScan , int nNumScans, IntPtr lpBits, IntPtr lpBI , int wUsage); [ DllImport("gdi32.dll" )] public static extern int SetDIBitsToDevice (IntPtr hdc, int x, int y , int dx, int dy, int SrcX, int SrcY, int Scan , int NumScans, IntPtr Bits, IntPtr BitsInfo , int wUsage); [ DllImport("gdi32.dll" )] public static extern IntPtr CreateDIBSection (IntPtr hdc, IntPtr pBitmapInfo, int un , IntPtr lplpVoid , IntPtr handle, int dw); [ DllImport("gdi32.dll" , CharSet = CharSet.Auto )] public static extern int SetPixel (IntPtr hdc, int x, int y , int crColor); [ DllImport("gdi32.dll" , CharSet = CharSet.Auto )] public static extern int GetPixel (IntPtr hdc, int x, int y ); [ DllImport("gdi32.dll" , CharSet= CharSet.Auto )] public static extern int CombineRgn (IntPtr dest, IntPtr src1, IntPtr src2 , int flags); [ DllImport("gdi32.dll" , CharSet= CharSet.Auto )] public static extern IntPtr CreateBrushIndirect (ref LOGBRUSH brush ); [ DllImport("gdi32.dll" , CharSet= CharSet.Auto )] public static extern IntPtr CreateRectRgnIndirect (ref RECTAPI rect ); [ DllImport("gdi32.dll" , CharSet= CharSet.Auto )] public static extern int GetClipBox (IntPtr hDC, ref RECTAPI rectBox); [ DllImport("gdi32.dll" , CharSet= CharSet.Auto )] public static extern bool PatBlt (IntPtr hDC, int x, int y , int width, int height, uint flags); [ DllImport("gdi32.dll" , CharSet= CharSet.Auto )] public static extern int SelectClipRgn (IntPtr hDC, IntPtr hRgn); [ DllImport("gdi32.dll" , CharSet = CharSet.Auto , CallingConvention = CallingConvention .StdCall, SetLastError=true )] public static extern IntPtr MoveToEx (IntPtr hDC, int x, int y , ref POINTAPI lpPoint ); [ DllImport("gdi32.dll" , CharSet = CharSet.Auto , CallingConvention = CallingConvention .StdCall, SetLastError=true )] public static extern IntPtr LineTo (IntPtr hDC, int x, int y ); [ DllImport("gdi32.dll" , CharSet = CharSet.Auto , CallingConvention = CallingConvention .StdCall, SetLastError=true )] public static extern IntPtr CreatePen (int nPenStyle, int nWidth, int crColor ); [ DllImport("gdi32.dll" , CharSet = CharSet.Auto , CallingConvention = CallingConvention .StdCall, SetLastError=true )] public static extern int SetBrushOrgEx (IntPtr hDC, int x, int y , ref POINTAPI p ); [ DllImport("gdi32.dll" , CharSet = CharSet.Auto , CallingConvention = CallingConvention .StdCall, SetLastError=true )] public static extern IntPtr CreatePatternBrush (IntPtr hBMP); [ DllImport("gdi32.dll" , CharSet = CharSet.Auto , CallingConvention = CallingConvention .StdCall, SetLastError=true )] public static extern int GetTextFace (IntPtr hDC, int nCount, string lpFacename ); [ DllImport("gdi32.dll" , CharSet = CharSet.Auto , CallingConvention = CallingConvention .StdCall, SetLastError=true )] public static extern int GetTextMetrics (IntPtr hDC, ref GDITextMetric TextMetric); [ DllImport("gdi32.dll" , CharSet = CharSet.Ansi , CallingConvention = CallingConvention .StdCall, SetLastError=true )] public static extern IntPtr CreateFontIndirect ([MarshalAs( UnmanagedType.LPStruct )]LogFont LogFont); [ DllImport("gdi32.dll" , SetLastError = true, CharSet = CharSet. Auto, CallingConvention = CallingConvention .StdCall)] public static extern int BitBlt (IntPtr hDestDC, int x, int y , int nWidth, int nHeight, IntPtr hSrcDC , int xSrc, int ySrc, int dwRop ); [ DllImport("gdi32.dll" , CharSet = CharSet.Auto , CallingConvention = CallingConvention .StdCall, SetLastError=true )] public static extern IntPtr CreateSolidBrush (int crColor); [ DllImport("gdi32.dll" , CharSet = CharSet.Auto , CallingConvention = CallingConvention .StdCall, SetLastError=true )] public static extern int Rectangle (IntPtr hDC, int left, int top , int right, int bottom); [ DllImport("gdi32.dll" , CharSet = CharSet.Auto , CallingConvention = CallingConvention .StdCall, SetLastError=true )] public static extern IntPtr CreateHatchBrush (int Style, int crColor); [ DllImport("gdi32.dll" , CharSet = CharSet.Auto , CallingConvention = CallingConvention .StdCall, SetLastError=true )] public static extern IntPtr CreateCompatibleBitmap (IntPtr hDC, int nWidth, int nHeight ); [ DllImport("gdi32.dll" , CharSet = CharSet.Auto , CallingConvention = CallingConvention .StdCall, SetLastError=true )] public static extern IntPtr CreateCompatibleDC (IntPtr hDC); [ DllImport("gdi32.dll" , CharSet = CharSet.Auto , CallingConvention = CallingConvention .StdCall, SetLastError=true )] public static extern IntPtr SelectObject (IntPtr hDC, IntPtr hObject); [ DllImport("gdi32.dll" , CharSet = CharSet.Auto , CallingConvention = CallingConvention .StdCall, SetLastError=true )] public static extern IntPtr DeleteObject (IntPtr hObject); [ DllImport("gdi32.dll" , SetLastError = true, CharSet = CharSet. Auto, CallingConvention = CallingConvention .StdCall)] public static extern int GetTextColor (IntPtr hDC); [ DllImport("gdi32.dll" , SetLastError = true, CharSet = CharSet. Auto, CallingConvention = CallingConvention .StdCall)] public static extern int SetTextColor (IntPtr hDC, int crColor); [ DllImport("gdi32.dll" , SetLastError = true, CharSet = CharSet. Auto, CallingConvention = CallingConvention .StdCall)] public static extern int GetBkColor (IntPtr hDC); [ DllImport("gdi32.dll" , SetLastError = true, CharSet = CharSet. Auto, CallingConvention = CallingConvention .StdCall)] public static extern int GetBkMode (IntPtr hDC); [ DllImport("gdi32.dll" , CharSet = CharSet.Auto , CallingConvention = CallingConvention .StdCall, SetLastError=true )] public static extern IntPtr DeleteDC (IntPtr hDC); [ DllImport("gdi32.dll" , SetLastError = true, CharSet = CharSet. Auto, CallingConvention = CallingConvention .StdCall)] public static extern int SetBkColor (IntPtr hDC, int crColor); [ DllImport("gdi32.dll" , SetLastError = true, CharSet = CharSet. Auto, CallingConvention = CallingConvention .StdCall)] public static extern int SetBkMode (IntPtr hDC, int Mode); [ DllImport("gdi32.dll" , CharSet = CharSet.Auto , CallingConvention = CallingConvention .StdCall, SetLastError=true )] public static extern int GdiFlush (); [ DllImport("gdi32.dll" , SetLastError = true, CharSet = CharSet. Ansi, CallingConvention = CallingConvention .StdCall)] public static extern int EnumFontFamiliesEx (IntPtr hDC, [MarshalAs(UnmanagedType .LPStruct)] LogFont lf , FONTENUMPROC proc, Int64 LParam, Int64 DW ); [ DllImport("gdi32.dll" , EntryPoint = "GdiAlphaBlend" )] public static extern bool AlphaBlend ( IntPtr hdcDest , // handle to destination DC int nXOriginDest , // x-coord of upper-left corner int nYOriginDest , // y-coord of upper-left corner int nWidthDest , // destination width int nHeightDest , // destination height IntPtr hdcSrc , // handle to source DC int nXOriginSrc , // x-coord of upper-left corner int nYOriginSrc , // y-coord of upper-left corner int nWidthSrc , // source width int nHeightSrc , // source height BLENDFUNCTION blendFunction // alpha-blending function ); }另外,如果真的是对效率要求很高的应用,还是推荐大家使用OpenGL、DirectX。.NET平台下有与之对应的Tao.OpenGL和Managed DirectX。
- C#使用GDI中的API函数
- GDI中的函数记录
- C#调用GDI函数SetPixel
- 调用API函数,在窗口非客户区绘图(C# GDI+编程)
- C#中使用API函数ShellExecute
- c#使用Api函数重设用户密码
- c# 使用api函数 ShowWindowAsync 控制窗体
- C#中使用API函数ShellExecute
- c# 使用GDI+画曲线图
- c# 使用GDI+画曲线图
- c#使用GDI+简单绘图
- c# GDI+ 的使用绘图
- WENDOWS API GDI绘图函数 输出 圆
- API函数 与C#中的函数参数对应表
- C#调用GDI+1.1中的函数实现高斯模糊、USM锐化等经典效果。
- C#调用GDI+1.1中的函数实现高斯模糊、USM锐化等经典效果。
- 使用Windows API进行GDI窗口绘图
- 使用Windows API进行GDI窗口绘图
- 指来指去之作交换
- 统计字母'A'出现的次数
- 页面调整简单记录
- SqlServer数据库同步方案详解
- 30岁前不必在乎的30件事
- C#使用GDI中的API函数
- 打入“内部”寻“内幕”
- 走出浮躁的泥沼:关于技术与工作
- Android launcher之总体分析
- 十六周上机任务(字符串连接)
- 项目1-小心的放开玩字符串之子母
- 上帝的心声
- 用java执行外部命令
- 在哪个学校拿工商管理硕士(MBA)最有分量?