简体   繁体   English

Android相机预览损坏

[英]android camera preview broken

i am a beginner developing a simple Android App where i try to take pictures using the Camera and Camera Preview. 我是开发一个简单的Android应用程序的初学者,在该应用程序中,我尝试使用“相机”和“相机预览”来拍照。

when trying to take the picture i got out of memory errors from 5 and 8 MegaPixel pictures. 尝试拍摄照片时,我从5张和8张MegaPixel图片中退出内存错误。 i therefore tried to use a smaller Camera Preview size. 因此,我尝试使用较小的Camera Preview尺寸。

This works great on my Moto X and my friends Galaxy Note 3 but causes pink and green stripes (ie you cant see the camera preview) on the Galaxy S4 and HTC One. 这在我的Moto X和我的朋友Galaxy Note 3上效果很好,但在Galaxy S4和HTC One上会引起粉红色和绿色条纹(即您看不到相机预览)。

I have been trying to find a solution (and the only one so far was to not change the camera preview size) but cant find anything. 我一直在尝试找到一种解决方案(到目前为止,唯一的解决方案是不更改相机预览的大小),但找不到任何东西。

i come from an iOS background where taking a picture is literally a coding effort of 5 minutes and cant believe it is this complicated on Android. 我来自iOS背景,拍照实际上是5分钟的编码工作,不能相信在Android上会如此复杂。

Anyone have any good third party libraries maybe to have a camera preview and take pictures to work on all phones? 任何人都有任何好的第三方库,也许可以预览相机并拍照以在所有手机上工作?

i can post some code too but its 99% the basic code from the android docs. 我也可以发布一些代码,但其99%来自android docs的基本代码。

here is my camera preview class if it helps - http://pastebin.mozilla.org/5698148 这是我的相机预览课,如果有帮助的话-http: //pastebin.mozilla.org/5698148

Thanks Chris 谢谢克里斯

So after a long time I found out that the issue was with 因此,经过很长一段时间,我发现问题出在

params.setPictureSize(opt.width, opt.height); params.setPictureSize(opt.width,opt.height);

for some reason some phones do not like when you call that... 由于某些原因,某些电话不喜欢您拨打该电话...

i now just use 我现在只用

params.setPreviewSize(opt.width, opt.height); params.setPreviewSize(opt.width,opt.height); - which helps against out of memory errors -这有助于防止内存不足错误

and then i scale the image before i show it in the ImageView 然后缩放图像,然后再在ImageView中显示它

if anyone needs the code please let me know... ill post it 如果有人需要代码,请告诉我...生病了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM