日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

如何在C#控件中画点并获得指定点的像素颜色

發(fā)布時間:2023/12/18 C# 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何在C#控件中画点并获得指定点的像素颜色 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

畫點的方法:
方法一:
???? 用picGraphics.FillRectangle(new SolidBrush(fillColor), p.X, p.Y, 1, 1); 即用一個像素填充方法.
方法二:
??? 用gdi32.dll庫中的SetPixel方法
?????[DllImport("gdi32.dll")]
?????private static extern int SetPixel(IntPtr hdc, int x1, int y1, int color);
獲得指定點的顏色:
?? 用gdi32.dll庫中的GetPixel方法
???[DllImport("gdi32.dll")]
???private static extern uint GetPixel(IntPtr hDC, int XPos, int YPos);
?? 下面給出一些圖形操作的集合:
???

?????? #region 圖形操作函數(shù)集合
????????[DllImport("gdi32.dll")]
??????? private static extern uint GetPixel(IntPtr hDC, int XPos, int YPos);

????????[DllImport("gdi32.dll")]
??????? private static extern int SetPixel(IntPtr hdc, int x1, int y1, int color);

???????????????
????????
??????? static public byte GetRValue(uint color)
??????? {
??????????? return (byte)color;
??????? }
????????????
??????? static public byte GetGValue(uint color)
??????? {
??????????? return ((byte)(((short)(color)) >> 8));
??????? }

??????? static public byte GetBValue(uint color)
??????? {
??????????? return ((byte)((color) >> 16));
??????? }

??????? static public byte GetAValue(uint color)
??????? {
??????????? return ((byte)((color) >> 24));
??????? }

??????? private? uint RGB(Color color)
??????? {
????????????// 返回由RGB構成的32位uint
??????????? uint R = color.R;
??????????? uint G = color.G;
??????????? uint B = color.B;
??????????? G <<= 8;
??????????? B <<= 16;
??????????? return ((uint)(R|G|B));
??????? }
????????
??????? public Color GetColor(Point p)
??????? {
????????????// 得到指定點的顏色RGB
????????????
??????????? uint colorref = GetPixel(this.picGraphics.GetHdc(), p.X, p.Y);??// picGraphics是我用picturePox類中的CreateGraphics方法創(chuàng)建的Graphics對象
??????????? this.picGraphics.ReleaseHdc();
??????????? byte Red = GetRValue(colorref);
??????????? byte Green = GetGValue(colorref);
??????????? byte Blue = GetBValue(colorref);
??????????? return Color.FromArgb(Red, Green, Blue);
??????? }

??????? public void SetColor(Point p, Color fillColor)
??????? {
??????????? SetPixel(this.picGraphics.GetHdc(), p.X, p.Y, (int)RGB(fillColor));
??????????? this.picGraphics.ReleaseHdc();
??????? }
???????? #endregion

總結

以上是生活随笔為你收集整理的如何在C#控件中画点并获得指定点的像素颜色的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。