我是 C# 新手,我有一个具有透明边框的图像(C# 中的 Image 类型)。我想获得该图像有多少透明度的坐标。
我知道 C# 中有一个名为 Color.Transparency 的属性(这里是链接: http://msdn.microsoft.com/en-us/library/system.drawing.color.transparent(v=vs.110).aspx ),但我不确定如何实际使用它来获取透明度所在的坐标。 它不是为了简单地编写语句而编译:Image.Color.Transparent
(P.s.图像是PNG,然后转换为BMP,我可以使用任一文件格式来获取这些坐标:http://www.techsmith.com/tutorial-snagit-transparency-prior.html)
谢谢大家!
最佳答案
如果您处理 Bitmap 对象,可以使用以下方法:
private static IEnumerable<System.Drawing.Point> GetTransparencyPoints(System.Drawing.Bitmap image)
{
for (int i = 0 ; i < image.Width ; i ++ ) {
for (int j = 0 ; j < image.Height ; j ++) {
Color color = image.GetPixel(i, j) ;
if (color == Color.Transparent) {
yield return new System.Drawing.Point(i, j) ;
}
}
}
}
关于c# - 如何获取图像中透明度的坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24410492/