Така че имам приложение на Google Glass, което прави снимка, след това я преобразува в сива скала и презаписва оригиналното изображение в паметта:
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();
}
}
Сивото растерно изображение не се вижда напълно в паметта с помощта на Windows Photo Viewer, докато Google Glass не бъде изключен от компютъра за отстраняване на грешки и след това включен отново. Понякога може да се види половината от изображението в сивата скала, но това е. Промених кода, за да покажа изображението, вместо да го запазя във вътрешната памет и това беше бързо и успешно, което ме кара да мисля, че проблемът е с четенето на изображението в сивата скала във вътрешната памет:
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();
}
}
Всякакви обяснения или предложения са добре дошли. Благодаря.
MediaScannerConnection
иscanFile()
, за да индексирате файла отMediaStore
. Понякога може да се види половината от изображението в нива на сивото, но това е -- обадете се наgetFD().sync()
наFileOutputStream
, след като се обадите наflush()
, но преди да се обадите наclose()
. - person CommonsWare   schedule 22.02.2015