![](/img/trans.png)
[英]How do i insert a Box which i drew out from pen to a picturebox image?
[英]GDI :Figure out which color the pixel has, which I drew before
我試圖找出我之前用紅色繪制的Pixel的顏色。
因此,當我讀到不可能直接執行此操作時,請將我的Graphics對象轉換為一個位圖,該位圖具有功能GetPIxel,並且寬度/高度與我的圖形對象相同。 否則我認為它不會起作用。
但它總是讓我返回:顏色[A = 0,R = 0,G = 0,B = 0]
我想這是懷特。
這是我的代碼:
namespace GDi
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.components = new System.ComponentModel.Container();
this.Size = new System.Drawing.Size(400, 400);
this.Text = "Display At Startup";
this.BackColor = Color.White;
}
private void Form1_Load(object sender, EventArgs e)
{
Graphics dc = this.CreateGraphics();
this.Show();
Pen BluePen = new Pen(Color.Blue, 3);
dc.DrawRectangle(BluePen, 0, 0, 50, 50);
Pen RedPen = new Pen(Color.Red, 2);
dc.DrawEllipse(RedPen, 20, 70, 80, 0);
dc.DrawEllipse(RedPen, 2, 88, 300, 0);
Bitmap myBitmap = new Bitmap(400, 400, dc);
string test = myBitmap.GetPixel(2, 88).ToString();
MessageBox.Show(test);
}
}
}
知道為什么它起作用了嗎?
這是行不通的,因為Bitmap構造函數只是創建了一個新的空位圖,而該空位圖與以前的圖形沒有任何關系。
您可能應該使用其他方法:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.