Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果之前在Android中拍摄过图像,则在OnResume之后在相机预览中设置图像_Android_Image_Android Camera - Fatal编程技术网

如果之前在Android中拍摄过图像,则在OnResume之后在相机预览中设置图像

如果之前在Android中拍摄过图像,则在OnResume之后在相机预览中设置图像,android,image,android-camera,Android,Image,Android Camera,我最近创建了一个Android应用程序,它提供了拍摄图像的功能(使用相机预览&而不是意图) 除一种情况外,大多数事情都已解决 我拍了这张照片并保存下来。图像当前显示在预览中 切换到其他应用程序(例如Whatsapp消息或其他) 返回到我的应用程序&预览丢失。未显示图像 这是我的onResume()函数: if(camera == null && !isPreviewStopped) { Log.d("Camera","Camera View refreshed");

我最近创建了一个Android应用程序,它提供了拍摄图像的功能(使用相机预览&而不是意图)

除一种情况外,大多数事情都已解决

  • 我拍了这张照片并保存下来。图像当前显示在预览中
  • 切换到其他应用程序(例如Whatsapp消息或其他)
  • 返回到我的应用程序&预览丢失。未显示图像
这是我的
onResume()
函数:

if(camera == null && !isPreviewStopped) {
    Log.d("Camera","Camera View refreshed");
    flPreview.removeAllViews();//Remove view from FrameLayout
    camera = getCameraInstance();
    preview = new CameraPreview(context, camera);//set preview
    flPreview.addView(preview);//Add preview to Frame Layout

}

最好是在上面添加图像视图,还是有一个选项可以将图像从文件设置为预览。

我不确定这是否是一个完美的方法,但它工作得相当好。这是我更新的
onResume()
方法

onResume()
中的逻辑:


如果有更好的方法,请告诉我。随时准备学习

我不确定这是否是一种完美的方法,但它相当有效。这是我更新的
onResume()
方法

onResume()
中的逻辑:

如果有更好的方法,请告诉我。随时准备学习

   if(camera == null && !isPreviewStopped) {
        Log.d("Camera","Camera View refreshed");
        flPreview.removeAllViews();
        camera = getCameraInstance();
        preview = new CameraPreview(context, camera);//set preview
        flPreview.addView(preview);
    }else if(isPreviewStopped){
        ImageView previewImage = new ImageView(context);
        // Make sure to store file instance in onSaveInstanceState() & restore it as well.
        ByteArrayOutputStream imageOutputStream = ImageCompression.compressImage(fileObjectOfStoredImage.getPath());


        byte[] imageBytes = imageOutputStream.toByteArray();
        previewImage.setImageBitmap(BitmapFactory.decodeByteArray(imageBytes,0,imageBytes.length));


        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        flPreview.addView(previewImage,params);
    }