![](/img/trans.png)
[英]how do you track the X and Y Coordinates of a Rectangle on a bitmap in c#
[英]How to match X and Y coordinates from a click inside a button with the corresponding bitmap pixels (C# Windows Store Apps)?
我有一个带有一些图像作为内容的按钮。 我将PointerEntered
事件处理程序附加到按钮,并在光标进入按钮时获取PointerPoint
坐标。 我可以使用RenderTargetBitmap
获取按钮内容的位图,并从该bitmap
获取像素array
。 我需要找到与PointerPoint
位置相对应的确切像素,以检查其透明度。
这是代码:
public async void button_PointerEntered(object sender, PointerRoutedEventArgs e)
{
Button button = sender as Button;
RenderTargetBitmap bitmap;
bitmap = new RenderTargetBitmap();
await bitmap.RenderAsync(button);
IBuffer pixelBuffer = await bitmap.GetPixelsAsync();
byte[] pixels = pixelBuffer.ToArray();
Pointer pointer = e.Pointer;
PointerPoint ppt = e.GetCurrentPoint(button);
}
我有ppt.X
和ppt.Y
,如何在像素数组中找到对应的像素?
要访问1d数组中的某个2d像素,偏移量将为x + y * width,其中width是图像的宽度
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.