custom camera view error

All your problems with Audio, Video and Images.

custom camera view error

Postby xiaodar » Fri Apr 23, 2010 6:49 am

hi i am a new developer trying out the custom camera view code
i've ran into some error and i dont know how to solve it.
hoping that someone would help me here.
thanks in advance.

i've got my code from here
http://www.devx.com/wireless/Article/42482/0/page/2

i've got an error on the CustomCameraView.java about the w,h not being able to be resolve. even by creating new variable height and width and change them it still shows me error on the emulator

here is the source code

CustomCameraView.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.example.test1;
  2.  
  3. import android.content.Context;
  4. import android.graphics.PixelFormat;
  5. import android.hardware.Camera;
  6. import android.hardware.Sensor;
  7. import android.hardware.SensorEvent;
  8. import android.hardware.SensorEventListener;
  9. import android.hardware.SensorManager;
  10. import android.hardware.Camera.Parameters;
  11. import android.view.SurfaceHolder;
  12. import android.view.SurfaceView;
  13.  
  14.  
  15.  
  16.  
  17.         public class CustomCameraView extends SurfaceView
  18.         {
  19.            Camera camera;
  20.            SurfaceHolder previewHolder;
  21.          
  22.            public CustomCameraView(Context ctx)
  23.            {
  24.                    super(ctx);
  25.                    
  26.                    previewHolder = this.getHolder();
  27.                    previewHolder.setType
  28.                    (SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  29.                    previewHolder.addCallback(surfaceHolderListener);
  30.              
  31.            }
  32.            SurfaceHolder.Callback surfaceHolderListener = new SurfaceHolder.Callback() {
  33.                       public void surfaceCreated(SurfaceHolder holder) {
  34.                            
  35.                             try {
  36.                                     camera.setPreviewDisplay(previewHolder);
  37.                             }
  38.                             catch (Throwable e){ }
  39.                            }
  40.                    public void surfaceChanged(SurfaceHolder holder, int format, int width,
  41.                          int height)
  42.                    {
  43.                            
  44.                        
  45.                                    
  46.                       Parameters params = camera.getParameters();
  47.                       params.setPreviewSize(w, h);
  48.                       params.setPictureFormat(PixelFormat.JPEG);
  49.                               camera.setParameters(params);
  50.                               camera.startPreview();
  51.                    }
  52.  
  53.                    public void surfaceDestroyed(SurfaceHolder arg0)
  54.                    {
  55.                       camera.stopPreview();
  56.                       camera.release();  
  57.                    }
  58.                  };
  59.            
  60.         }
  61.        
Parsed in 0.062 seconds, using GeSHi 1.0.8.4



test1.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.example.test1;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.widget.FrameLayout;
  6.  
  7. public class test1 extends Activity {
  8.     /** Called when the activity is first created. */
  9.    
  10.     CustomCameraView cv;
  11.     @Override
  12.     public void onCreate(Bundle savedInstanceState) {
  13.            try{
  14.               super.onCreate(savedInstanceState);
  15.               cv = new CustomCameraView(
  16.                  this.getApplicationContext());
  17.               FrameLayout rl = new FrameLayout(
  18.                  this.getApplicationContext());
  19.               setContentView(rl);
  20.               rl.addView(cv);
  21.            } catch(Exception e){}
  22.         }
  23.  
  24.     }
Parsed in 0.043 seconds, using GeSHi 1.0.8.4



android manifest.xml

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.       package="com.example.test1"
  4.       android:versionCode="1"
  5.       android:versionName="1.0">
  6.     <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
  7.     <uses-permission android:name="android.permission.CAMERA" />
  8.         <activity android:name=".test1"
  9.                   android:label="@string/app_name">
  10.             <intent-filter>
  11.                 <action android:name="android.intent.action.MAIN" />
  12.                 <category android:name="android.intent.category.LAUNCHER" />
  13.             </intent-filter>
  14.         </activity>
  15.  
  16.     </application>
  17.     <uses-sdk android:minSdkVersion="3" />
  18.  
  19. </manifest>
Parsed in 0.049 seconds, using GeSHi 1.0.8.4
xiaodar
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Mar 24, 2010 9:51 am

Top

Postby mrco » Wed Apr 28, 2010 8:47 am

h,w - this is height and weigh from surfaceChanged parameters. But this sample has many other errors - no camera initialization, wrong release. Take a look into this snippet http://snippets.dzone.com/posts/show/8683
mrco
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Jan 15, 2010 11:31 am
Location: 2V Software

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 13 guests