解决方案:我实际上并没有设置相机预览,而是缩放它附带的默认预览。您需要将参数分配回相机,因为 _camera.getParamters.setPreviewSize()
不起作用!
我正在努力让Android相机在手机上预览(理想情况下是全屏)。
然而,我遇到了一种情况,我觉得硬件和软件都在密谋反对我:/
我得到了相机支持的屏幕尺寸列表。对于一半电话(我的12个设备中的大约6个),当我将预览设置为最接近屏幕的预览时,这可以正常工作。
然而,在另一半,预览被拉伸和倾斜。有许多帖子存在并声称可以解决这个问题,但没有。
我找到的原因是:我从硬件本身获得的支持的相机屏幕尺寸列表是错误的。为什么?因为手动将相机设置为支持的最大尺寸之一时,宽高比仍处于关闭状态:
_camera.getParameters().setPreviewSize(720,1280);
getHolder().setFixedSize(720, 1280);
对于此手机,屏幕尺寸为768 x 1280.支持的最近屏幕尺寸为720 x 1280.将其设置为此值仍会导致图像失真。下一个支持的屏幕尺寸分辨率是1280 x 960.对我来说,这很有趣,因为它说它支持2种不同的宽高比,但其中一些支持'纵横比是倾斜的。也就是说它支持4:3和16:9,但只有4:3看起来正常!
getHolder().setFixedSize(720, 960); //fixes issue even though this is NOT a supported screen size
当我强制表面支架与4:3宽高比匹配时,使用不支持的屏幕尺寸720 x 960,瞧,相机预览正常。
我的问题是,我怎么知道在支持的宽高比不同于所说的宽高比的相机中相机的宽高比是多少?
更新
深入了解我的手机细节:
http://www.gsmarena.com/lg_nexus_4_e960-5048.php
这款手机配有相机,可将图像保存为3264 x 2448.宽高比为4:3。我将看看我是否可以从手机中获取此数据并使用THAT来设置所需的宽高比。
更新2
使用
System.out.println("Camera picture size is " + _camera.getParameters().getPictureSize().width + " x " + _camera.getParameters().getPictureSize().height);
它给了我640 x 480.带有一点数学的是4:3的宽高比。然后我使用它并适当地缩放我的相机。
这很糟糕,但它完成了工作!
//Because the camera LIES about supporting both 16:9 and 4:3 we must find the actual one from the picture size
void determineCameraAspectRatio()
{
int cameraWidth = _camera.getParameters().getPictureSize().width;
int cameraHeight = _camera.getParameters().getPictureSize().height;
if( cameraWidth*3 == cameraHeight*4)
{
System.out.println("4:3");
}
if( cameraWidth*9 == cameraHeight*16)
{
System.out.println("16:9");
}
}
将修复程序应用于相机:
if(_is4By3AspectRatio)
{
height = (Helper.screenWidthPX(_context) * 4)/3;
}else//16:9
{
height = (Helper.screenWidthPX(_context) * 16)/9;
}
_camera.getParameters().setPreviewSize(Helper.screenWidthPX(_context),height);
getHolder().setFixedSize(Helper.screenWidthPX(_context),height);
}
更新
这适用于很多手机,但有些甚至这是错误的。 Nexus 6报告后置摄像头长宽比为4:3,其支持的最高比率为1440 x 1920,但将其设置为此会导致图像偏斜。我完全不知道为什么。这些都没有意义。它说它想要4:3的宽高比,但只能以16:9的比例正面显示(正面和背面)。所以我们
这是surfaceFlinger上的sysdump
SurfaceFlinger
Build configuration: [sf] [libui] [libgui]
Sync configuration: [using: EGL_ANDROID_native_fence_sync EGL_KHR_wait_sync]
DispSync configuration: app phase 0 ns, sf phase 0 ns, present offset 0 ns (refresh 16666667 ns)
Visible layers (count = 10)
+ LayerDim 0xb8919c28 (DimLayer)
Region transparentRegion (this=0xb8919d88, count=1)
[ 0, 0, 0, 0]
Region visibleRegion (this=0xb8919c30, count=1)
[ 0, 0, 0, 0]
layerStack= 0, z= 0, pos=(0,0), size=( 16, 16), crop=( 0, 0, -1, -1), isOpaque=0, invalidate=0, alpha=0xff, flags=0x00000001, tr=[1.00, 0.00][0.00, 1.00]
client=0xb88ebac8
format= 0, activeBuffer=[ 0x 0: 0, 0], queued-frames=0, mRefreshPending=0
mTexName=4 mCurrentTexture=-1
mCurrentCrop=[49152,0,415,-1] mCurrentTransform=0
mAbandoned=0
-BufferQueue mMaxAcquiredBufferCount=1, mDequeueBufferCannotBlock=0, default-size=[1x1], default-format=1, transform-hint=00, FIFO(0)={}
+ LayerDim 0xb88659d0 (DimLayer)
Region transparentRegion (this=0xb8865b30, count=1)
[ 0, 0, 0, 0]
Region visibleRegion (this=0xb88659d8, count=1)
[ 0, 0, 0, 0]
layerStack= 0, z= 0, pos=(0,0), size=( 16, 16), crop=( 0, 0, -1, -1), isOpaque=0, invalidate=0, alpha=0xff, flags=0x00000001, tr=[1.00, 0.00][0.00, 1.00]
client=0xb88ebac8
format= 0, activeBuffer=[ 0x 0: 0, 0], queued-frames=0, mRefreshPending=0
mTexName=5 mCurrentTexture=-1
mCurrentCrop=[0,0,0,0] mCurrentTransform=0
mAbandoned=0
-BufferQueue mMaxAcquiredBufferCount=1, mDequeueBufferCannotBlock=0, default-size=[1x1], default-format=1, transform-hint=00, FIFO(0)={}
+ LayerDim 0xb886d000 (DimLayer)
Region transparentRegion (this=0xb886d160, count=1)
[ 0, 0, 0, 0]
Region visibleRegion (this=0xb886d008, count=1)
[ 0, 0, 0, 0]
layerStack= 0, z= 0, pos=(0,0), size=( 16, 16), crop=( 0, 0, -1, -1), isOpaque=0, invalidate=0, alpha=0xff, flags=0x00000001, tr=[1.00, 0.00][0.00, 1.00]
client=0xb88ebac8
format= 0, activeBuffer=[ 0x 0: 0, 0], queued-frames=0, mRefreshPending=0
mTexName=6 mCurrentTexture=-1
mCurrentCrop=[-16843010,-16843010,-16843010,-16843010] mCurrentTransform=0
mAbandoned=0
-BufferQueue mMaxAcquiredBufferCount=1, mDequeueBufferCannotBlock=0, default-size=[1x1], default-format=1, transform-hint=00, FIFO(0)={}
+ Layer 0xb88f9580 (com.android.phasebeam.PhaseBeamWallpaper)
Region transparentRegion (this=0xb88f96e0, count=1)
[ 0, 0, 0, 0]
Region visibleRegion (this=0xb88f9588, count=1)
[ 0, 0, 0, 0]
layerStack= 0, z= 21000, pos=(0,0), size=( 768,1280), crop=( 0, 0, 768,1280), isOpaque=1, invalidate=0, alpha=0xff, flags=0x00000003, tr=[1.00, 0.00][0.00, 1.00]
client=0xb88591d0
format= 2, activeBuffer=[ 768x1280:1024, 3], queued-frames=0, mRefreshPending=0
mTexName=8 mCurrentTexture=1
mCurrentCrop=[0,0,0,0] mCurrentTransform=0
mAbandoned=0
-BufferQueue mMaxAcquiredBufferCount=1, mDequeueBufferCannotBlock=0, default-size=[768x1280], default-format=2, transform-hint=00, FIFO(0)={}
[00:0xb8911cc8] state=FREE , 0xb8868488 [ 768x1280:1024, 3]
>[01:0xb88feb78] state=ACQUIRED, 0xb88fdc40 [ 768x1280:1024, 3]
[02:0xb88ff1c0] state=FREE , 0xb88fedf0 [ 768x1280:1024, 3]
+ Layer 0xb887db18 (SurfaceView)
Region transparentRegion (this=0xb887dc78, count=1)
[ 0, 0, 0, 0]
Region visibleRegion (this=0xb887db20, count=1)
[ 0, 0, 768, 1024]
layerStack= 0, z= 21025, pos=(0,0), size=( 768,1024), crop=( 0, 0, 768,1024), isOpaque=1, invalidate=0, alpha=0xff, flags=0x00000002, tr=[1.00, 0.00][0.00, 1.00]
client=0xb89124b8
format= 4, activeBuffer=[ 640x 480: 640, 11], queued-frames=0, mRefreshPending=0
mTexName=61 mCurrentTexture=3
mCurrentCrop=[0,0,0,0] mCurrentTransform=0x4
mAbandoned=0
-BufferQueue mMaxAcquiredBufferCount=1, mDequeueBufferCannotBlock=0, default-size=[768x1024], default-format=4, transform-hint=00, FIFO(0)={}
[00:0xb8923620] state=DEQUEUED, 0xb89000e0 [ 640x 480: 640, 11]
[01:0xb88784c8] state=DEQUEUED, 0xb8878160 [ 640x 480: 640, 11]
[02:0xb8878550] state=DEQUEUED, 0xb88785f0 [ 640x 480: 640, 11]
>[03:0xb8877120] state=ACQUIRED, 0xb8878638 [ 640x 480: 640, 11]
[04:0xb8913c48] state=DEQUEUED, 0xb886c8a0 [ 640x 480: 640, 11]
[05:0xb88ff0f8] state=DEQUEUED, 0xb8879b08 [ 640x 480: 640, 11]
[06:0xb8900930] state=DEQUEUED, 0xb88c3308 [ 640x 480: 640, 11]
+ Layer 0xb8862be8 (co.pumpup.app/co.pumpup.app.Activities.CameraEditorActivity)
Region transparentRegion (this=0xb8862d48, count=1)
[ 0, 0, 0, 0]
Region visibleRegion (this=0xb8862bf0, count=1)
[ 0, 0, 768, 1280]
layerStack= 0, z= 21030, pos=(0,0), size=( 768,1280), crop=( 0, 0, 768,1280), isOpaque=0, invalidate=0, alpha=0xff, flags=0x00000000, tr=[1.00, 0.00][0.00, 1.00]
client=0xb89124b8
format= 1, activeBuffer=[ 768x1280: 768, 1], queued-frames=0, mRefreshPending=0
mTexName=60 mCurrentTexture=2
mCurrentCrop=[0,0,0,0] mCurrentTransform=0
mAbandoned=0
-BufferQueue mMaxAcquiredBufferCount=1, mDequeueBufferCannotBlock=0, default-size=[768x1280], default-format=1, transform-hint=00, FIFO(0)={}
[00:0xb88ffff8] state=FREE , 0xb88ed258 [ 768x1280: 768, 1]
[01:0xb88fe908] state=FREE , 0xb88ff3d0 [ 768x1280: 768, 1]
>[02:0xb8872348] state=ACQUIRED, 0xb88a6110 [ 768x1280: 768, 1]
+ Layer 0xb88befc0 (FocusedStackFrame)
Region transparentRegion (this=0xb88bf120, count=1)
[ 0, 0, 0, 0]
Region visibleRegion (this=0xb88befc8, count=1)
[ 0, 0, 0, 0]
layerStack= 0, z= 21031, pos=(0,0), size=( 1, 1), crop=( 0, 0, -1, -1), isOpaque=0, invalidate=0, alpha=0x4d, flags=0x00000001, tr=[1.00, 0.00][0.00, 1.00]
client=0xb88ebac8
format= 1, activeBuffer=[ 0x 0: 0, 0], queued-frames=0, mRefreshPending=0
mTexName=3 mCurrentTexture=-1
mCurrentCrop=[524288,327680,0,0] mCurrentTransform=0
mAbandoned=0
-BufferQueue mMaxAcquiredBufferCount=1, mDequeueBufferCannotBlock=0, default-size=[1x1], default-format=1, transform-hint=00, FIFO(0)={}
+ LayerDim 0xb886f9c8 (DimLayer)
Region transparentRegion (this=0xb886fb28, count=1)
[ 0, 0, 0, 0]
Region visibleRegion (this=0xb886f9d0, count=1)
[ 0, 0, 0, 0]
layerStack= 0, z= 22019, pos=(-192,-320), size=(1152,1920), crop=( 0, 0, -1, -1), isOpaque=0, invalidate=0, alpha=0x00, flags=0x00000001, tr=[1.00, 0.00][0.00, 1.00]
client=0xb88ebac8
format= 0, activeBuffer=[ 0x 0: 0, 0], queued-frames=0, mRefreshPending=0
mTexName=7 mCurrentTexture=-1
mCurrentCrop=[-67372037,-67372037,1919905635,-842203036] mCurrentTransform=0
mAbandoned=0
-BufferQueue mMaxAcquiredBufferCount=1, mDequeueBufferCannotBlock=0, default-size=[1152x1920], default-format=1, transform-hint=00, FIFO(0)={}
+ Layer 0xb8900d20 (StatusBar)
Region transparentRegion (this=0xb8900e80, count=1)
[ 0, 0, 0, 0]
Region visibleRegion (this=0xb8900d28, count=1)
[ 0, 0, 0, 0]
layerStack= 0, z= 151000, pos=(0,0), size=( 768, 50), crop=( 0, 0, 768, 50), isOpaque=0, invalidate=0, alpha=0xff, flags=0x00000001, tr=[1.00, 0.00][0.00, 1.00]
client=0xb88fea70
format= 1, activeBuffer=[ 768x 50: 768, 1], queued-frames=0, mRefreshPending=0
mTexName=10 mCurrentTexture=2
mCurrentCrop=[0,0,0,0] mCurrentTransform=0
mAbandoned=0
-BufferQueue mMaxAcquiredBufferCount=1, mDequeueBufferCannotBlock=0, default-size=[768x50], default-format=1, transform-hint=00, FIFO(0)={}
[00:0xb887a088] state=FREE , 0xb8873348 [ 768x 50: 768, 1]
[01:0xb88fe2f8] state=FREE , 0xb89004b8 [ 768x 50: 768, 1]
>[02:0xb8879fd8] state=ACQUIRED, 0xb88773c8 [ 768x 50: 768, 1]
+ Layer 0xb8861748 (NavigationBar)
Region transparentRegion (this=0xb88618a8, count=1)
[ 0, 0, 0, 0]
Region visibleRegion (this=0xb8861750, count=1)
[ 0, 0, 0, 0]
layerStack= 0, z= 201000, pos=(0,1184), size=( 768, 96), crop=( 0, 0, 768, 96), isOpaque=0, invalidate=0, alpha=0xff, flags=0x00000001, tr=[1.00, 0.00][0.00, 1.00]
client=0xb88fea70
format= 1, activeBuffer=[ 768x 96: 768, 1], queued-frames=0, mRefreshPending=0
mTexName=11 mCurrentTexture=2
mCurrentCrop=[0,0,0,0] mCurrentTransform=0
mAbandoned=0
-BufferQueue mMaxAcquiredBufferCount=1, mDequeueBufferCannotBlock=0, default-size=[768x96], default-format=1, transform-hint=00, FIFO(0)={}
[00:0xb88fff08] state=FREE , 0xb88fdf68 [ 768x 96: 768, 1]
[01:0xb88c2920] state=FREE , 0xb8862b88 [ 768x 96: 768, 1]
>[02:0xb8913d00] state=ACQUIRED, 0xb88c5138 [ 768x 96: 768, 1]
Displays (1 entries)
+ DisplayDevice: Built-in Screen
type=0, hwcId=0, layerStack=0, ( 768x1280), ANativeWindow=0xb885cd68, orient= 0 (type=00000000), flips=30060, isSecure=1, secureVis=0, powerMode=2, activeConfig=0, numLayers=2
v:[0,0,768,1280], f:[0,0,768,1280], s:[0,0,768,1280],transform:[[1.000,0.000,-0.000][0.000,1.000,-0.000][0.000,0.000,1.000]]
mAbandoned=0
-BufferQueue mMaxAcquiredBufferCount=1, mDequeueBufferCannotBlock=0, default-size=[768x1280], default-format=1, transform-hint=00, FIFO(0)={}
[00:0xb8913f80] state=DEQUEUED, 0xb88642e8 [ 768x1280: 768, 1]
>[01:0xb885fd80] state=ACQUIRED, 0xb8911608 [ 768x1280: 768, 1]
SurfaceFlinger global state:
EGL implementation : 1.4
EGL_QUALCOMM_shared_image EGL_KHR_image EGL_KHR_image_base EGL_QCOM_create_image EGL_KHR_lock_surface EGL_KHR_lock_surface2 EGL_KHR_fence_sync EGL_KHR_cl_eventEGL_KHR_cl_event2EGL_IMG_context_priority EGL_KHR_gl_texture_2D_image EGL_KHR_gl_texture_cubemap_image EGL_KHR_gl_texture_3D_image EGL_KHR_gl_renderbuffer_image EGL_EXT_create_context_robustness EGL_ANDROID_blob_cache EGL_ANDROID_framebuffer_target EGL_KHR_create_context EGL_KHR_wait_sync EGL_KHR_gl_colorspace EGL_ANDROID_image_crop EGL_ANDROID_recordable EGL_ANDROID_native_fence_sync EGL_ANDROID_image_native_buffer EGL_KHR_gl_colorspace EGL_IMG_image_plane_attribs
GLES: Qualcomm, Adreno (TM) 320, OpenGL ES 3.0 V@95.0 AU@ (GIT@Ia6306ec328)
GL_AMD_compressed_ATC_texture GL_AMD_performance_monitor GL_AMD_program_binary_Z400 GL_EXT_debug_label GL_EXT_debug_marker GL_EXT_discard_framebuffer GL_EXT_robustness GL_EXT_texture_format_BGRA8888 GL_EXT_texture_type_2_10_10_10_REV GL_NV_fence GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth_texture GL_OES_depth24 GL_OES_EGL_image GL_OES_EGL_sync GL_OES_EGL_image_external GL_OES_element_index_uint GL_OES_fbo_render_mipmap GL_OES_fragment_precision_high GL_OES_get_program_binary GL_OES_packed_depth_stencil GL_OES_depth_texture_cube_map GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_texture_3D GL_OES_texture_float GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_texture_npot GL_OES_vertex_half_float GL_OES_vertex_type_10_10_10_2 GL_OES_vertex_array_object GL_QCOM_alpha_test GL_QCOM_binning_control GL_QCOM_driver_control GL_QCOM_perfmon_global_mode GL_QCOM_extended_get GL_QCOM_extended_get2 GL_QCOM_tiled_rendering GL_QCOM_writeonly_rendering GL_EXT_sRGB GL_EXT_sRGB_write_control GL_EXT_texture_sRGB_decode GL_EXT_multisampled_render_to_texture GL_EXT_color_buffer_float GL_EXT_color_buffer_half_float GL_EXT_disjoint_timer_query
Region undefinedRegion (this=0xb8859fe4, count=1)
[ 0, 1024, 768, 1280]
orientation=0, isDisplayOn=1
last eglSwapBuffers() time: 1251.335000 us
last transaction time : 305.204000 us
transaction-flags : 00000000
refresh-rate : 59.999999 fps
x-dpi : 319.790009
y-dpi : 318.744995
gpu_to_cpu_unsupported : 0
eglSwapBuffers time: 0.000000 us
transaction time: 0.000000 us
VSYNC state: disabled
soft-vsync: disabled
numListeners=14,
events-delivered: 26757
0xb88642c0: count=-1
0xb88680e8: count=-1
0xb88684d0: count=-1
0xb886c8f8: count=-1
0xb886c9b8: count=-1
0xb886cf10: count=-1
0xb8874450: count=-1
0xb88ac618: count=-1
0xb88c1658: count=-1
0xb88fda88: count=-1
0xb89005d0: count=-1
0xb8912398: count=-1
0xb89125d8: count=-1
0xb8913e50: count=-1
h/w composer state:
h/w composer present and enabled
Hardware Composer state (version 01020000):
mDebugForceFakeVSync=0
Display[0] configurations (* current):
* 0: 768x1280, xdpi=319.790009, ydpi=318.744995, refresh=16666667
numHwLayers=3, flags=00000000
type | handle | hint | flag | tr | blnd | format | source crop (l,t,r,b) | frame | name
-----------+----------+------+------+----+------+-------------+--------------------------------+------------------------+------
HWC | b8878638 | 0002 | 0000 | 04 | 0100 | ? 00000011 | 0, 0, 640, 480 | 0, 0, 768, 1024 | SurfaceView
HWC | b88a6110 | 0002 | 0000 | 00 | 0105 | RGBA_8888 | 0, 0, 768, 1280 | 0, 0, 768, 1280 | co.pumpup.app/co.pumpup.app.Activities.CameraEditorActivity
FB TARGET | b8911608 | 0000 | 0000 | 00 | 0105 | RGBA_8888 | 0, 0, 768, 1280 | 0, 0, 768, 1280 | HWC_FRAMEBUFFER_TARGET
Qualcomm HWC state:
MDPVersion=440
DisplayPanel=8
HWC Map for Dpy: "PRIMARY"
PREV_FRAME: layerCount: 2 mdpCount: 2 cacheCount: 0
CURR_FRAME: layerCount: 2 mdpCount: 2 fbCount: 0
needsFBRedraw: NO pipesUsed: 2 MaxPipesPerMixer: 4
---------------------------------------------
listIdx | cached? | mdpIndex | comptype | Z
---------------------------------------------
0 | NO | 0 | MDP | 0
1 | NO | 1 | MDP | 1
Overlay State
==========================
Ctrl(mdp_overlay) id=1 z=1 fg=0 alpha=255 mask=-1 flags=0x60000
src(msmfb_img) w=768 h=1280 format=12 MDP_RGBA_8888
src_rect(mdp_rect) x=0 y=0 w=768 h=1280
dst_rect(mdp_rect) x=0 y=0 w=768 h=1280
Data(msmfb_overlay_data) id=1
data(msmfb_data) offset=0 memid=90 id=0 flags=0x0 priv=0
Attached to dpy=0
Ctrl(mdp_overlay) id=3 z=0 fg=0 alpha=255 mask=-1 flags=0x940000
src(msmfb_img) w=480 h=640 format=6 MDP_Y_CRCB_H2V2
src_rect(mdp_rect) x=0 y=0 w=480 h=640
dst_rect(mdp_rect) x=0 y=0 w=768 h=1024
Data(msmfb_overlay_data) id=3
data(msmfb_data) offset=462848 memid=123 id=0 flags=0x0 priv=0
Attached to dpy=0
Pipes used=2
MdpRotCtrl(msm_rotator_img_info) sessid=3966423424 rot=4, enable=1 downscale=0
src w=640 h=480 format=6 MDP_Y_CRCB_H2V2
dst w=480 h=640 format=6 MDP_Y_CRCB_H2V2
src_rect x=0 y=0 w=640 h=480
MdpRotData(msm_rotator_data_info) sessid=3966423424 verkey=0
src offset=0 memid=98 id=0 flags=0x0 priv=0
dst offset=462848 memid=123 id=0 flags=0x0 priv=0
src_chroma offset=0 memid=0 id=0 flags=0x0 priv=0
dst_chroma offset=0 memid=0 id=0 flags=0x0 priv=0
================
Allocated buffers:
0xb8862b88: 288.00 KiB | 768 ( 768) x 96 | 1 | 0x00000900
0xb88642e8: 3840.00 KiB | 768 ( 768) x 1280 | 1 | 0x00001a00
0xb8868488: 3840.00 KiB | 768 (1024) x 1280 | 3 | 0x00000900
0xb886c8a0: unknown | 640 ( 640) x 480 | 11 | 0x50020900
0xb8873348: 150.00 KiB | 768 ( 768) x 50 | 1 | 0x00000900
0xb88773c8: 150.00 KiB | 768 ( 768) x 50 | 1 | 0x00000900
0xb8878160: unknown | 640 ( 640) x 480 | 11 | 0x50020900
0xb88785f0: unknown | 640 ( 640) x 480 | 11 | 0x50020900
0xb8878638: unknown | 640 ( 640) x 480 | 11 | 0x50020900
0xb8879b08: unknown | 640 ( 640) x 480 | 11 | 0x50020900
0xb88a6110: 3840.00 KiB | 768 ( 768) x 1280 | 1 | 0x00000900
0xb88c3308: unknown | 640 ( 640) x 480 | 11 | 0x50020900
0xb88c5138: 288.00 KiB | 768 ( 768) x 96 | 1 | 0x00000900
0xb88ed258: 3840.00 KiB | 768 ( 768) x 1280 | 1 | 0x00000900
0xb88fdc40: 3840.00 KiB | 768 (1024) x 1280 | 3 | 0x00000900
0xb88fdf68: 288.00 KiB | 768 ( 768) x 96 | 1 | 0x00000900
0xb88fedf0: 3840.00 KiB | 768 (1024) x 1280 | 3 | 0x00000900
0xb88ff3d0: 3840.00 KiB | 768 ( 768) x 1280 | 1 | 0x00000900
0xb89000e0: unknown | 640 ( 640) x 480 | 11 | 0x50020900
0xb89004b8: 150.00 KiB | 768 ( 768) x 50 | 1 | 0x00000900
0xb8911608: 3840.00 KiB | 768 ( 768) x 1280 | 1 | 0x00001a00
Total allocated (estimate): 32034.00 KB
//摄像机逻辑
private void adjustAspectRatio()
{
List<Camera.Size> sizesOfPreviews = _camera.getParameters().getSupportedPreviewSizes();
Camera.Size size = getOptimalPreviewSize(sizesOfPreviews,Helper.screenWidthPX(_context),Helper.screenHeightPX(_context));
int cameraWidth = size.height;
int cameraHeight = size.width;
System.out.println("Optimal camera size is " + cameraWidth + " x " + cameraHeight);
_camera.getParameters().setPreviewSize(cameraWidth, cameraHeight);
_parentLayout.getLayoutParams().width = 768;
_parentLayout.getLayoutParams().height = 1024;
//_parentLayout.setAspectRatio((double)cameraWidth/cameraHeight);
}
private Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int w, int h)
{
final double ASPECT_TOLERANCE = 0.1;
double targetRatio = (double) h / w;
if (sizes == null)
return null;
Camera.Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = h;
for (Camera.Size size : sizes) {
double ratio = (double) size.height / size.width;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
continue;
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
if (optimalSize == null) {
minDiff = Double.MAX_VALUE;
for (Camera.Size size : sizes) {
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
}
return optimalSize;
}