繁体   English   中英

如何通过单击按钮内的X和Y坐标来匹配相应的位图像素(C#Windows Store Apps)?

[英]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.Xppt.Y ,如何在像素数组中找到对应的像素?

要访问1d数组中的某个2d像素,偏移量将为x + y * width,其中width是图像的宽度

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM