如何从Xamarin项目中的图像访问像素?

时间:2019-04-07 12:13:09

标签: c# android image xamarin

我想访问图像中的像素颜色,但是据我所知,图像不能以这种方式使用。在我的代码中有一个事件Modify,在其中我调用了方法MakeDarker,但是我想知道如何在其中修改像素。

我试图将图像转换为位图或字节数组,但是这些都不适合我。尽管我使用Xamarin.Forms.Image进行输入,但Visual Studio甚至无法识别位图。

public void Modify(object sender, EventArgs args)
{
    ImageModify modify = new ImageModify();

    picture = modify.MakeDarker(picture);
}
class ImageModify
{
    public Image MakeDarker(Image image)
    {
        Image output = new Image();

        for (int i = 0; i < image.Height; i++)
        {
            for (int j = 0; j < image.Width; j++)
            {

            }
        }

        return output;
    }
}

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用System.Drawing命名空间中的Color struct(不知道您是否可以在Xamarin中使用它,或者它是否特定于基于Windows的项目)?

我在自己的C#项目中使用它来收集像素的RGB值,并且效果很好。