简体   繁体   English

图像处理(需要图像的像素值)

[英]Image Processing (need pixel value of an image)

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 . 我想制作一个应用程序,我想在其中拍摄照片并输入x,y轴,它将显示捕获图片中对应的点像素值。

I don't have any knowledge about image processing well . 我对图像处理没有任何了解。 So, how can I do it ? 那么,我该怎么做呢? help me . 帮我 。

The way I have done this in the past is by writing the image to the filesystem and then decoding it. 我过去这样做的方法是将图像写入文件系统然后解码。 Admittedly its a little inefficient but it's functional. 不可否认,它有点低效,但它的功能。

This requires a number of steps. 这需要许多步骤。 I suggest you read over this documentation . 我建议你阅读这篇文章 It describes the process of taking an image and saving it to the file system which you will need to do before you can do the rest of these steps. 它描述了拍摄图像,并保存到你需要做的,然后才能做这些步骤的其余文件系统的过程。

Next you will need to use BitmapFactory to decode the image which will give you an instance of Bitmap which you can do all sorts of things with (documented here ). 接下来,您将需要使用BitmapFactory对图像进行解码,该图像将为您提供一个Bitmap实例,您可以使用这些内容( 此处记录 )。 In this example I return the Color object for the pixel located at (50, 50) using getPixel() . 在此示例中,我使用getPixel()返回位于(50, 50)的像素的Color对象。 This example assumes that the path the the image is mCurrentPhotoPath but should be wherever you saved the image. 此示例假定图像的路径为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);
}

You can get RGB values from this Color object which is what I think you are wanting to do. 您可以从此Color对象中获取RGB值,这是我认为您想要做的。 That can be found under the Color object documentation on Android Developers as well. 这可以在Android开发者的Color对象文档中找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM