xamarin - SkiaSharp 在可点击的路径上制作位图
问题描述
我已经绘制了一个圆形路径,并且每 1 度角添加一个位图。现在,我想使用 Xamarin 表单收听每个位图单击该圆形路径!我怎样才能实现这一点。我已经在 xamarin 和 amble 上进行操作以获取触摸坐标,但无法准确获取选择了哪个位图?
编辑:
foreach (var item in bitmapPoints)
{
using (Stream streami = assembly.GetManifestResourceStream(resID))
{
redBitmap = SKBitmap.Decode(streami);
}
canvas.DrawBitmap(redBitmap,item, null);
}
现在我正在尝试为画布上绘制的每个位图启用点击事件。我应该制作具有 HiTest 方法的自定义 BitMap 类吗?如果是这样,应该通过什么 Rect x 和 y 来获取 HiTest?
解决方案
这被称为“命中测试” - Xamarin在他们的 SkiaSharp 文档中有一个示例
public bool HitTest(SKPoint location)
{
// Invert the matrix
SKMatrix inverseMatrix;
if (Matrix.TryInvert(out inverseMatrix))
{
// Transform the point using the inverted matrix
SKPoint transformedPoint = inverseMatrix.MapPoint(location);
// Check if it's in the untransformed bitmap rectangle
SKRect rect = new SKRect(0, 0, bitmap.Width, bitmap.Height);
return rect.Contains(transformedPoint);
}
return false;
}
推荐阅读
- android - Android - Retrofit2 - Kotlin:REST API 响应格式与模型不同
- ethereum - 共识发生在 evm 执行之前还是之后?
- python - Emacs python嵌套循环缩进问题
- java - Spring JpaRepositoryn 中的 %Like% 查询
- python - 使用 cv2 从相机捕获视频会打印出满是零的矩阵
- hyperledger-fabric - 使用 cryptogen 和 configtxgen 创建的工件构建网络时,fabric-ca 未启动
- flutter - TextFormField 验证器不起作用 - 在 null 上调用了方法“验证”
- powershell - 尝试为每个用户确定 CSV 中最长的字符串
- php - 无法将表单方法从“发布”更改为“删除”
- javascript - 使用加密 nodejs 解密大文件