操纵Android位图中的黑白像素

时间:2016-10-03 16:57:30

标签: android android-studio bitmap android-bitmap android-graphics

我正在开发一个用于点击图像并将位图转换为二进制的应用程序。以下是我将图像转换为二进制文件的一些代码:

    File file = new  File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Watershed/WatershedImages", "Image_"+Save.MyDate+".jpg");
    Mat origianlImage = Imgcodecs.imread(file.getAbsolutePath());
    Mat image1Mat = new Mat();
    Imgproc.cvtColor(origianlImage,image1Mat, Imgproc.COLOR_BGR2HSV);
    Mat mat3 = new Mat();
    Core.inRange(image1Mat, new Scalar(0, 0, 0), new Scalar(50, 255, 255), mat3);
    Mat mat4 = new Mat();    
    Imgproc.threshold(mat3, mat4, 0, 255, Imgproc.THRESH_BINARY);
    Bitmap threshBitmap = Bitmap.createBitmap(mat4.cols(), mat4.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(mat4, threshBitmap);

图像转换为位图。我检查了像素的颜色,发现黑色像素值为-16777216,白色为-1。为了进一步处理,我需要将这些值更改为原始java类型(0表示黑色,255表示白色)。

如何在不更改颜色的情况下将像素值从-16777216处理为0和-1到255?有什么办法吗?请帮忙。

0 个答案:

没有答案