gpt4 book ai didi

android - Android:BitmapFactory.decodeFile/OpenCV确实返回了无效的位图

转载 作者:行者123 更新时间:2023-12-02 16:43:08 26 4
gpt4 key购买 nike

我正在用相机 Activity 拍照,然后尝试从保存的位置读取它。不幸的是,位图由以下方式返回:

Bitmap bimage = BitmapFactory.decodeFile( path );

具有高度和宽度= -1。
我正在使用OpenCV,当我使用
Mat img = Highgui.imread(path);

我得到一个适当的矩阵。完全我无法将其转换为位图。做的时候
bmp = Bitmap.createBitmap(img.cols(), img.rows(), Config.ARGB_8888);
Utils.matToBitmap(img, bmp);

我再次得到相同的结果:宽度和高度= -1的位图。我需要注意图像格式吗?我可以在相机意图上进行设置吗?不应该
BitmapFactory.decodeFile( path );

自动实现什么格式?

我在装有Android 2.3.1和OpenCV 2.3.1的三星银河S上运行此程序

谢谢你的帮助。

最佳答案

三星的相机意图Photo capture Intent causes NullPointerException on Samsung phones only有一些问题

试试这个

// call 相机

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);

// 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);
}

}

关于android - Android:BitmapFactory.decodeFile/OpenCV确实返回了无效的位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9044909/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com