Image Processing (need pixel value of an image)

时间:2016-07-11 22:07:59

标签: android

I want to make an app, in which I want to take a picture and input x,y axis it will show me corresponding point pixel value from the captured picture .

I don't have any knowledge about image processing well . So, how can I do it ? help me .

1 个答案:

答案 0 :(得分:0)

我过去这样做的方法是将图像写入文件系统,然后对其进行解码。不可否认,它有点低效但功能正常。

这需要许多步骤。我建议你仔细阅读documentation。它描述了拍摄图像并将其保存到文件系统的过程,您需要执行之前,您可以执行其余步骤。

接下来,您需要使用BitmapFactory对图像进行解码,该图像将为您提供Bitmap的实例,您可以执行各种操作(记录为here)。在此示例中,我使用Color返回位于(50, 50)的像素的getPixel()对象。此示例假定图像的路径为mCurrentPhotoPath,但应该是保存图像的位置。

private Color getColor() {
    // Get the dimensions of the View
    int targetW = mImageView.getWidth();
    int targetH = mImageView.getHeight();

    // Get the dimensions of the bitmap
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;

    // Determine how much to scale down the image
    int scaleFactor = Math.min(photoW/targetW, photoH/targetH);

    // Decode the image file into a Bitmap sized to fill the View
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;
    Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
    return bitmap.getPixel(50, 50);
}

您可以从此Color对象获取RGB值,这是我认为您想要做的事情。这可以在Android开发者的Color对象文档中找到。