简体   繁体   English

Android查看位图像素值

[英]Android See bitmap pixel values

I'm on a image processing study. 我正在进行图像处理研究。 I've read and researched about bitmaps, pixels and arrays. 我已经阅读并研究了位图,像素和数组。 I want to know the pixel values of the image. 我想知道图像的像素值。 My plan is to convert the bitmap to an array and save it as a text file. 我的计划是将位图转换为数组并将其保存为文本文件。 Is there any other way to see the whole array of pixel values of an image? 还有其他方法可以查看图像的像素值的整个数组吗?

Yes, there is a way to convert an image to text. 是的,有一种方法可以将图像转换为文本。 It is actually called a byte array. 它实际上称为字节数组。 You can do this like so: 您可以这样做:

        // Convert bitmap to byte array
        Bitmap bitmap = bitmapImage;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
        byte[] bitmapdata = bos.toByteArray();

You can also just take the byte array and then save the actual values instead of turning it into an image file. 您也可以只获取字节数组,然后保存实际值,而不是将其转换为图像文件。 To turn the byte array into a file, do this: 要将字节数组转换为文件,请执行以下操作:

        // Create a file to write bitmap data
        File f = new File(getApplicationContext().getCacheDir(), "image.png");
        f.createNewFile();

        // INSERT ABOVE CODE HERE (BITMAP TO BYTE ARRAY CONVERSION)

        // Write the bytes in file
        FileOutputStream fos = new FileOutputStream(f);
        fos.write(bitmapdata);
        fos.flush();
        fos.close();

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

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