安卓:BitmapFactory.de codeFILE / OpenCV中不会返回invaild位图 [英] Android: BitmapFactory.decodeFile / OpenCV does return invaild Bitmap
问题描述
我正在用相机的活动图片,然后尝试从保存的位置读取它。不幸的是通过位图returnd:
I'm taking a picture with the camera activity and then try to read it from the saved location. Unfortunately the Bitmap returnd by:
Bitmap bimage = BitmapFactory.decodeFile( path );
有高度和宽度= -1。
我使用OpenCV的,当我阅读
has height and width = -1. I'm using OpenCV and when I read the image with
Mat img = Highgui.imread(path);
我得到一个正确的矩阵。 Altough我不能将它转换为位图。当执行
I get a proper matrix. Altough I cannot convert it to a bitmap. When doing
bmp = Bitmap.createBitmap(img.cols(), img.rows(), Config.ARGB_8888);
Utils.matToBitmap(img, bmp);
我再次得到了相同的结果:宽度和高度= -1位图。我需要注意的图像格式?我可以设置相机意图是什么?不应
I get the same result again: A Bitmap with width and height = -1. Do I need to watch out for the image format? Can I set that on the camera intent? Shouldn't
BitmapFactory.decodeFile( path );
自动实现的格式是什么?
automatically realize what the format is?
我在三星Galaxy S的Android 2.3.1运行此和OpenCV 2.3.1
I'm running this on a Samsung galaxy S with Android 2.3.1 and OpenCV 2.3.1
感谢您的帮助。
推荐答案
三星与相机意图一些问题<一href=\"http://stackoverflow.com/questions/7031374/photo-capture-intent-causes-nullpointerexception-on-samsung-phones-only/7031422#7031422\">Photo拍摄意图导致NullPointerException异常三星手机只
Samsung has some issues with camera intent Photo capture Intent causes NullPointerException on Samsung phones only
试试这个方法。
//调用摄像头
String _path = Environment.getExternalStorageDirectory()
+ File.separator + "TakenFromCamera.png";
File file = new File(_path);
Uri outputFileUri = Uri.fromFile(file);
Intent intent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, 1212);
//在活动onResult
// in activity onResult
if (requestCode == 1212) {
String _path = Environment.getExternalStorageDirectory()
+ File.separator + "TakenFromCamera.png";
mBitmap = BitmapFactory.decodeFile(_path);
if (mBitmap == null) {
} else {
Intent intent = new Intent(AYGCamActivity.this,
myGalleryImage.class);
startActivity(intent);
}
}
这篇关于安卓:BitmapFactory.de codeFILE / OpenCV中不会返回invaild位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!