Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

test: Reply
 
LinkBack Thread Tools
Old July 13th, 2011, 02:29 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jul 2011
Posts: 3
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default Camera Orientation prb..urgent!!!

Helllo frnds.I am creating android application which uses camera code.I have used android-API 2.1 . I have installed my application on dell mobile and the orientation of camera is correct.However, i installed my application in other android mobiles like samsung galaxy s2 etc.Here,the problem is with camera orientation , even in portrait mode the camera is rotated 90 degrees.Can any1 suggest me if any camera parameteres need to be changed so that camera orientation works well on all mobiles...Here is my code:


//class CameraDemo
public class CameraDemo extends Activity {
private static final String TAG = "CameraDemo";
Camera camera;
Preview preview;
Button buttonClick;
Button next;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
try
{

super.onCreate(savedInstanceState);
setContentView(R.layout.camdemo);

preview = new Preview(this);
((FrameLayout) findViewById(R.id.preview)).addView(preview);

buttonClick = (Button) findViewById(R.id.buttonClick);
next = (Button) findViewById(R.id.next);
buttonClick.setOnClickListener( new OnClickListener() {
public void onClick(View v) {

preview.camera.takePicture(shutterCallback, rawCallback, jpegCallback);

try{

Constants.takepic=1;

buttonClick.setEnabled(false); //once click is clicked, its disable
}
catch(Exception e)
{
e.printStackTrace();
}
}


});
next.setOnClickListener( new OnClickListener() {
public void onClick(View v) {
//preview.camera.takePicture(shutterCallback, rawCallback, jpegCallback);
if(Constants.takepic==1)
{
Intent intent_new=new Intent(CameraDemo.this,NotesAndUpload.class);
startActivity(intent_new);
}
else
{
Toast.makeText(CameraDemo.this, "Take a picture",5);
}

}


});

Log.d(TAG, "onCreate'd");
}
catch(Exception e ){}
}


ShutterCallback shutterCallback = new ShutterCallback() {
public void onShutter() {
Log.d(TAG, "onShutter'd");
}
};

/** Handles data for raw picture */
PictureCallback rawCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
Log.d(TAG, "onPictureTaken - raw");
}
};

/** Handles data for jpeg picture */
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
//taking time and date
Constants.dateValue=dateAndTime("yyyy-MM-dd");
Constants.timeValue=dateAndTime("HH:mm:ss");
FileOutputStream outStream = null;
try {
// write to local sandbox file system
// outStream =
CameraDemo.this.openFileOutput(String.format("%d.j pg",
System.currentTimeMillis()), 0);
// Or write to sdcard
long imageNameLong=System.currentTimeMillis();
Constants.imageName=new Long(imageNameLong).toString();
outStream = new
FileOutputStream(String.format("/sdcard/%d.jpg",imageNameLong));
outStream.write(data);
Constants.takepic=1;
outStream.close();

Log.d(TAG, "onPictureTaken - wrote bytes: " + data.length);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
Log.d(TAG, "onPictureTaken - jpeg");
}
};

}


//Preview Class
class Preview extends SurfaceView implements SurfaceHolder.Callback {
private static final String TAG = "Preview";

SurfaceHolder mHolder;
public Camera camera;

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_BU FFERS);
}

public void surfaceCreated(SurfaceHolder holder) {
// The Surface has been created, acquire the camera and tell it where
// to draw.
camera = Camera.open();
try {
camera.setPreviewDisplay(holder);


camera.setPreviewCallback(new PreviewCallback() {

public void onPreviewFrame(byte[] data, Camera arg1) {
/*FileOutputStream outStream = null;
try {
outStream = new FileOutputStream(String.format("/sdcard/%d.jpg",
System.currentTimeMillis()));
outStream.write(data);
outStream.close();
Log.d(TAG, "onPreviewFrame - wrote bytes: " + data.length);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}*/
Preview.this.invalidate();
}
});
} catch (IOException e) {
e.printStackTrace();
}
}

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.
camera.stopPreview();
camera = 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 NEED TO BE CHANGED :-
Camera.Parameters parameters = camera.getParameters();
parameters.setPreviewSize(w, h);
if(getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_PORTRAIT)
{
parameters.set("rotation",90);
parameters.set("orientation", "portrait");
}
if (getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_LANDSCAPE)
{
parameters.set("rotation", 90);
parameters.set("orientation", "landscape");

}
parameters.set("jpeg-quality", 50);
camera.setParameters(parameters);
camera.startPreview();
}

@Override
public void draw(Canvas canvas) {
super.draw(canvas);
Paint p= new Paint(Color.RED);
Log.d(TAG,"draw");
canvas.drawText("PREVIEW", canvas.getWidth()/2, canvas.getHeight()/2, p );
}
}

Advertisements
Shinchan is offline  
Reply With Quote
sponsored links
Old July 18th, 2011, 12:58 AM   #2 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jul 2011
Posts: 3
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Some plz see the code and solve the problem......plz!!!
Shinchan is offline  
Reply With Quote
Reply
Tags
android 2.1, camera orientation


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 08:43 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.