c# - 如何获取图像中透明度的坐标

标签 c# image transparency

我是 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/

相关文章:

image - BlackBerry-在 PersistentStore 中存储图像

python - 如何选择 NumPy 数组中的所有非黑色像素?

flash - 如何获得透明度以在 Actionscript 中处理位图

php - 为什么修复 GD 的 png 透明度问题的解决方案不起作用?

opengl - 如何将 Opengl 纹理中的某些颜色设置为透明?

c# - 动态创建枚举

c# - 程序在执行时挂起

c# - 发送邮件在本地有效但在服务器上无效?

c#泛型类型的重载错误

html - 是否元 og :image actually load in background?