上previewFrame不改变数据 [英] onPreviewFrame doesn't change the data
问题描述
这是在Android上我第一次编程,多的我不熟悉的Java programmation。我试图找到我在互联网上的一些问题的答案,但没有找到任何解决办法。我希望你们中的一个将能够帮助我。 我想要做的是运用一些图像处理实时视频摄像头和显示。这就是为什么我使用previewFrame该函数的结果之前显示的做一些图像处理。请告诉我,如果它是不是最好的方法。我的问题是,当我试图修改该数据阵列,作为没有任何改变的屏幕上。从我所看到的调试器函数被调用。所有这一切都完成与2.1的API。
It is my first time programming on Android, and more I am not that familiar with the java programmation. I tried to find some answer on my problem over the internet but didn't find any solution. I hope one of you will be able to help me. What I want to do is applying some image processing in real time to the video camera and display it. That is why I am using the function onPreviewFrame the make some image processing before display the result. Please tell me if it isn't the best way. my problem is that when I try to modify the data array, nothing as changed on the screen. From what I saw with the debugger the function is called. All of that is done with the 2.1 API.
是否有人知道为什么吗?我怎样才能解决这个问题?
Does someone know why? How can i solve this?
要帮助,这是我的code:
To help, here is my code :
import android.app.Activity;
import android.content.Context;
import android.hardware.Camera;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
import java.io.IOException;
// ----------------------------------------------------------------------
public class CameraPreview extends Activity {
private Preview mPreview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Hide the window title.
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Create our Preview view and set it as the content of our activity.
mPreview = new Preview(this);
setContentView(mPreview);
}
}
// ----------------------------------------------------------------------
class Preview extends SurfaceView implements SurfaceHolder.Callback, Camera.PreviewCallback {
SurfaceHolder mHolder;
Camera mCamera;
Preview(Context context) {
super(context);
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceCreated(SurfaceHolder holder) {
// The Surface has been created, acquire the camera and tell it where
// to draw.
mCamera = Camera.open();
try {
mCamera.setPreviewDisplay(holder);
mCamera.setPreviewCallback(this);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void onPreviewFrame(byte[] data, Camera camera) {
if (data != null) {
for(int i=0;i<data.length;i++){
data[i] = 0;
}
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
// Surface will be destroyed when we return, so stop the preview.
// Because the CameraDevice object is not a shared resource, it's very
// important to release it when the activity is paused.
mCamera.stopPreview();
mCamera.release();
mCamera = null;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// Now that the size is known, set up the camera parameters and begin
// the preview.
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(w, h);
mCamera.setParameters(parameters);
mCamera.startPreview();
}
}
感谢您的帮助, 摩根科米尔
Thank you for the help, Morgan Cormier
推荐答案
对于我来说只有当我安装previewCallback在SurfaceChanged方法
For me only works if I install the PreviewCallback in the method on SurfaceChanged
这篇关于上previewFrame不改变数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!