首页 > 解决方案 > Xamarin Android 等效项-> Java:Color.Red(int)

问题描述

有谁知道什么相当于:Java代码:

int pixel = source.getPixel(x, y);
int g = (int) (0.3 * Color.red(pixel) + 0.59 * Color.green(pixel) + 0.11 * Color.blue(pixel)); //grayscale shade corresponding to rgb

在 Xamarin Android 中。

标签: xamarin.android

解决方案


我想这可能是你想要的:

int pixel = source.GetPixel(x, y);
int g = (int) (0.3 * Color.GetRedComponent(pixel) + 0.59 * Color.GetGreenComponent(pixel) + 0.11 * Color.GetBlueComponent(pixel));

这也会产生相同的结果:

Color pixelColor = new Color(source.GetPixel(x, y));
int g1 = (int) (0.3 * pixelColor.R + 0.59 * pixelColor.G + 0.11 * pixelColor.B);

顺便说一句,还有 GetAlphaComponent():

int A = Color.GetAlphaComponent(pixel);

推荐阅读