I'm new to android development and recently, I've made a simple camera app with android but I have to problems that I cannot solve. First, I've rotated the preview screen to 90 degree so that the surfaceview would be in a portrait mode. I 've used the code below .
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
if(mCamera != null) {
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
requestLayout();
mCamera.setDisplayOrientation(90);
mCamera.setParameters(parameters);
mCamera.startPreview();
}
But the problem isn't solved. After I take the shot and check the image in the folder the jpg image that I took with my app is saved horizontally with a bad resolution.
I'm not sure how to explain it clearly but what I want to do is to alter the image size and save it in a portrait mode. The code to save the image is like the sample below, but I'm not certain how and where I can change the size and rotation before saving. Sorry for my bad English. It would be great if I can have some clear tips for noobs.
private class SaveImageTask extends AsyncTask<byte[], Void, Void> {
@Override
protected Void doInBackground(byte[]... data) {
FileOutputStream outStream = null;
// Write to SD Card
try {
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/camtest");
dir.mkdirs();
String fileName = String.format("%d.jpg", System.currentTimeMillis());
File outFile = new File(dir, fileName);
outStream = new FileOutputStream(outFile);
outStream.write(data[0]);
outStream.flush();
outStream.close();
Is it possible to rotate the data in PictureCallback?
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
//change the rotarion
new SaveImageTask().execute(data);
resetCam();
Log.d(TAG, "onPictureTaken - jpeg");
}
};