我最近修改了我的相机以捕获和显示全尺寸图像,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)