如何从Android的程序设计摄像头应用程序捕获的图像?程序设计、应用程序、摄像头、图像

2023-09-05 08:36:12 作者:余生爱自己

我想实现在Android摄像头应用程序,我从网上约code到WebCam.Upto创建一个Live的相机没有problem.Now我要捕捉图像时单击该按钮,和我在对话window.Without显示所捕获的图像的任何异常的程序正在运行,但不显示所捕获的图像时,显示一些默认图像。

I am trying to implement Camera application in android,and i got some code from net to create a Live Camera through WebCam.Upto this no problem.Now i have to capture the images when click the button, and i displayed the captured images in the Dialog window.Without any exception the program is running but the captured image is not displayed,some default image is displayed.

我的code是

public void captureImage()
{
	Camera.Parameters params = camera.getParameters();
	camera.setParameters(params);
	Camera.PictureCallback jpgCallback = new PictureCallback() 
	{
		public void onPictureTaken(byte[] data, Camera camera) 
		{
			try
			{
				Dialog d=new Dialog(c);
		    	d.setContentView(0x7f030000);
				BitmapFactory.Options opts = new BitmapFactory.Options();
    			Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,opts);
    			TextView tv=(TextView)d.findViewById(0x7f050001);
    			ImageView i=(ImageView)d.findViewById(0x7f050000);
    	    	i.setImageBitmap(bitmap);
    			tv.setText("Hai"+data.length);
    			d.show();
			}
			catch(Exception e)
			{
				AlertDialog.Builder alert=new AlertDialog.Builder(c);
				alert.setMessage("Exception1"+e.getMessage());
				alert.create();
				alert.show();
			}
		}

	};
	camera.takePicture(null, null, jpgCallback);
}

我不知道从那里此默认映像快到了,我没怎么上悬而未决这个problem.Anyone知道这个请大家帮忙me.Waiting的答复.....

I have no idea from where this default image is coming,i don't how to slove this problem.Anyone knows about this please help me.Waiting for the Reply.....

推荐答案

如果这是在模拟器上,唯一可用的摄像机图像是默认的图像。

If this is on the emulator, the only available camera image is a default image.

在一个完全无关的音符,不要引用由原始数据资源(例如, d.setContentView(0x7f030000))。使用生成的研究类(例如, R.layout.something )。这些数字的将会的变化,而当他们改变你的应用程序的将会的突破。

On a completely unrelated note, DO NOT reference resources by raw numbers (e.g., d.setContentView(0x7f030000)). Use the generated R class (e.g., R.layout.something). Those numbers will change, and when they change your application will break.