捕获图像而不意图,给出了在不同设备上不同的输出 [英] Capture image without intent, Gives different output on different devices
问题描述
我的要求是既不能显示摄像机preVIEW也使用相机的意图进行图像采集。
My requirement is neither to display camera preview nor to use camera intent for image capture.
在那里我找到一种方法,它正在为我的第一个测试设备(Galaxy Tab的7)。
There for I find a way which is working for my first testing device (Galaxy tab 7").
我的 CaptureImage
函数如下
private void CaptureImage() {
int FrontCameraFound = getCameraID();
if (FrontCameraFound != -1) {
mCamera = Camera.open(FrontCameraFound);
parameters = mCamera.getParameters();
mCamera.setParameters(parameters);
mCamera.startPreview();
Camera.PictureCallback mCall = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
// set bitmap tp image view just to check
// if image capture proper, testing purpose
iv_image.setImageBitmap(bmp);
mCamera.stopPreview();
mCamera.release();
mCamera = null;
}
};
mCamera.takePicture(null, null, mCall);
}
}
和 getCameraID
函数如下
private int getCameraID() {
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
for (int camIdx = 0; camIdx < Camera.getNumberOfCameras(); camIdx++) {
Camera.getCameraInfo(camIdx, cameraInfo);
// for capture image from back camera
// If want to capture from front
// then change it to CAMERA_FACING_FRONT
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
try {
return camIdx;
} catch (RuntimeException e) {
}
}
}
return -1;
}
现在我面临的困难,成功地上面$ C在不同的设备上运行$ C。
Now I am facing difficulty to run successfully above code on different devices.
- 在三星Galaxy S +(2.3.6):前置摄像头总是返回绿色形象,但编码回相机工作正常
- 三星GALAXY Nexus(4.1):编码并不不论是对于前也不对回相机和放大器工作;给takePicture失败。
- LG擎天柱网(2.3.4):只有相机背面是否有与放大器;做工精细。
- 三星Galaxy Tab 7(2.3.3):两个摄像头做工精细
- 在摩托罗拉Xoom(3.1):两个摄像头做工精细
三星GALAXY Nexus的logcat的:
Logcat of Samsung Galaxy Nexus :
09-21 09:37:42.125: E/AndroidRuntime(4647): Caused by: java.lang.RuntimeException: takePicture failed
09-21 09:37:42.125: E/AndroidRuntime(4647): at android.hardware.Camera.native_takePicture(Native Method)
09-21 09:37:42.125: E/AndroidRuntime(4647): at android.hardware.Camera.takePicture(Camera.java:1061)
09-21 09:37:42.125: E/AndroidRuntime(4647): at android.hardware.Camera.takePicture(Camera.java:1006)
09-21 09:37:42.125: E/AndroidRuntime(4647): at fortyonepost.com.pwop.TakePictureDemoActivity.CaptureImage(TakePictureDemoActivity.java:63)
09-21 09:37:42.125: E/AndroidRuntime(4647): at fortyonepost.com.pwop.TakePictureDemoActivity.onCreate(TakePictureDemoActivity.java:36)
09-21 09:37:42.125: E/AndroidRuntime(4647): at android.app.Activity.performCreate(Activity.java:5008)
09-21 09:37:42.125: E/AndroidRuntime(4647): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
09-21 09:37:42.125: E/AndroidRuntime(4647): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
这是不可能检查code每一个设备,我只是测试我的code 5的设备和2设备引起的问题,所以有来从相机图像无意图与放任何标准的办法; preVIEW。
It is not possible to check code for every devices , I just test my code on 5 devices and 2 device causes problem, so is there any standard way to fetch image from camera without intent & preview.
请注意,我在清单及放大器包括:设定最低SDK版本9
Please note that I include in manifest & set minimum sdk version to 9
更新:
在4.1的Nexus银河 takePicture失败
从行号1061 Camera.java类,这里是<一个href="https://github.com/android/platform_frameworks_base/blob/master/core/java/android/hardware/Camera.java#L1061">class链接这给我的信息 native_takePicture(MSGTYPE);在Camera.java功能
没有抛出
Update :
In 4.1 Nexus Galaxy takePicture Failed
from Line number 1061 in Camera.java class, here is the class link which gives me information that native_takePicture(msgType); function in Camera.java
did throw that
推荐答案
若干搜索后,我发现,$ P $相机PVIEW是必要的,我不知道如何我的code行之有效的一些设备甚至是错误的
After several search, i found that preview of camera is necessary and i wonder how my code works well in some devices even it is faulty.
任何方式的解决方案是,
Any ways solution is that,
我们需要在表面上视摄像头preVIEW保留,我们可以躲在其他任何观点表面看来,我以我的FrameLayout表面观(我知道这是德precated),它上面我把图像视图,表面来看我只取80 * 80 DP面来看,因为像30 * 30 DP小型表面来看并没有通过错误工作又一遍。
We require camera preview hold on surface view and we can hide that surface view behind any other view, I take surface view in framelayout(i know it is deprecated) and above it i take image view, for surface view i just take 80*80 dp surface view because small surface view like 30*30 dp didn't work and again through error.
这篇关于捕获图像而不意图,给出了在不同设备上不同的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!