So, I have an application in Google Glass that takes a picture, then converts it to shades of gray and overwrites the original image in memory:
private void rGBProcessing (final String picturePath, Mat image) { //BitmapFactory Creates Bitmap objects from various sources, //including files, streams, and byte-arrays Bitmap myBitmapPic = BitmapFactory.decodeFile(picturePath); image = new Mat(myBitmapPic.getWidth(), myBitmapPic.getHeight(), CvType.CV_8UC4); Mat imageTwo = new Mat(myBitmapPic.getWidth(), myBitmapPic.getHeight(), CvType.CV_8UC1); Utils.bitmapToMat(myBitmapPic, image); Imgproc.cvtColor(image, imageTwo, Imgproc.COLOR_RGBA2GRAY); Utils.matToBitmap(imageTwo, myBitmapPic); FileOutputStream out = null; try { out = new FileOutputStream(picturePath); myBitmapPic.compress(Bitmap.CompressFormat.PNG, 100, out); // PNG is a lossless format, the compression factor (100) is ignored } catch (Exception e) { e.printStackTrace(); } finally { try { if (out != null) { out.close(); } } catch (IOException e) { e.printStackTrace(); } }
A gray bitmap is not fully displayed in memory using the Windows Photo Viewer until Google Glass is disconnected from the debug computer and then reconnected. Sometimes you can view half the image in grayscale, but it is. I changed the code to show the image, not save it to the internal memory, and it was fast and successful, which makes me think that the problem is reading the grayscale image to the internal memory:
FileOutputStream out = null; try { out = new FileOutputStream(picturePath); myBitmapPic.compress(Bitmap.CompressFormat.PNG, 100, out); // PNG is a lossless format, the compression factor (100) is ignored } catch (Exception e) { e.printStackTrace(); } finally { try { if (out != null) { out.close(); } } catch (IOException e) { e.printStackTrace(); } }
Any explanation or suggestions are welcome. Thanks.
source share