无法在ImagePreview中显示完整尺寸的图像

时间:2013-10-18 12:47:40

标签: bitmap android-camera android-lru-cache

我最近修改了我的相机以捕捉和显示全尺寸图像,Galaxy Nexus上的尺寸为2592 X 1944.我在拍摄图像并在预览中显示时尝试使用LruCache。图像应该在哪里我的LogCat上的一个条目告诉我图像已经保存。

如何显示全尺寸图像?

使用以下方法获得图片尺寸:

    private Size getDesiredPictureSize(Parameters params)
{
    //Resolution is widthxheight
    Size result=null;
    //boolean isDesiredValue=false;
    final int minArea=500*500;  
    final int maxArea=1000*1000;
    List<Size> supportedSizeList=params.getSupportedPictureSizes();
    for(Size size:supportedSizeList)
    {
            if(result==null)
                result=size;
            else
            {
                int resultArea=result.width*result.height;
                int sizeArea=size.width*size.height;
                if(resultArea<sizeArea)
                {   
                    result=size;
                    Log.d("CameraPreview", "Result pictureSize has been set to "+result.width+"X"+result.height);
                }   
            }
        }
    Log.d("CameraPreview", "Picture size has been set to "+result.width+"X"+result.height);

    return result;
}

当预览图像必须显示时,logcat会显示以下内容:

  FATAL EXCEPTION: main
      java.lang.OutOfMemoryError
      at android.graphics.Bitmap.nativeCopy(Native Method)
  at android.graphics.Bitmap.copy(Bitmap.java:450)
  at com.example.newscancardapp.ImagePreviewActivity.onCreate(ImagePreviewActivity.java:58)
  at android.app.Activity.performCreate(Activity.java:5133)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
  at android.app.ActivityThread.access$600(ActivityThread.java:141)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:137)
  at android.app.ActivityThread.main(ActivityThread.java:5103)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:525)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

此问题的答案与相机的实施无关,您应该在显示之前将图像缩小到2048x2048以下。