android - HTC Mobile 中的图像捕获问题

标签 android camera htc-android

我正在使用以下代码在 Android 中捕获图像:

String fileName = "image.jpeg";
                //create parameters for Intent with filename
                ContentValues values = new ContentValues();
                values.put(MediaStore.Images.Media.TITLE, fileName);
                values.put(MediaStore.Images.Media.DESCRIPTION,"Image captured by camera");
                //imageUri is the current activity attribute, define and save it for later usage (also in onSaveInstanceState)
                imageUri = getContentResolver().insert(
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
                //create new Intent
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
                intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
                startActivityForResult(intent, CAMERA_PIC_REQUEST); 

捕获图像后,我使用以下代码获取图像:

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
        {
            super.onActivityResult(requestCode, resultCode, data);
                            if( requestCode == CAMERA_PIC_REQUEST)
                {
                    if(resultCode == Activity.RESULT_OK)
                    {
                        if(imageUri == null)
                            imageUri = data.getData();
                        String filePath = getPath(imageUri);
                        UploadContentToServer(filePath, "image.jpeg");
                        //getBytesFromFile(filePath);
                    }
                }
}

它在除 HTC 横屏模式外的所有设备上都能正常工作。

我在我的应用中使用纵向模式。但是当我在我的 HTC 中以横向模式拍摄图像时,我得到的 imageUri 为空。 如何解决此问题,仅在 HTC 设备中。

最佳答案

尝试使用相机拍摄图像时,我在 Galaxy s2 上遇到了同样的问题。尝试在 Intent 中指定真实路径,然后在您的 onActivityResult 中获取路径。直接从 Intent 数据中提取 uri 对我来说在图像捕获中也不起作用。

这是我的意思的一个例子:

 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
 fileName = dateFormat.format(new Date()) + ".jpg";
 File photo = new File(Environment.getExternalStorageDirectory(), fileName);
 Intent cameraintent = new Intent("android.media.action.IMAGE_CAPTURE");
 cameraintent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
 imageURICamera = Uri.fromFile(photo);
 startActivityForResult(cameraintent, 1);

现在在 onActivityResult 中再次获取照片:

 realPath = Environment.getExternalStorageDirectory() + "/" + fileName; 

关于android - HTC Mobile 中的图像捕获问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6819777/

相关文章:

Android - Viewpager 自定义

android - 使用摘要式 HTTP 身份验证 : “Cannot retry streamed HTTP body” 改造 POST 请求

android - 在不写入文件的情况下将视频录制到字节数组

opencv - 网络摄像机捕获

unity-game-engine - 当 UI 覆盖屏幕时,将相机剔除 mask 设置为 Nothing 好吗?

android - 无法在 HTC wildfire 上测试 android 应用程序

android - android webview 中的 onClick 事件太慢

java - byte[] toString() 给出一个奇怪的字符串而不是实际值

android - 如何从我的 HTC one x 获取数据库文件?

android - 标准 Intent URI 损坏?