我使用以下代码来捕获图像。在其中我使用Surfaceview
. 捕获的图像保存在我在 android Sdcard 中创建的文件夹中,但是当我以图像方向显示这些图像时GridView
,图像方向不同。如果我使用相机,Intent (ACTION_IMAGE_CAPTURE)
则输出图像定义明确。谁能帮我
在这里,我有一个扩展 Activity 一个工具的类SurfaceHolder.Callback
public class CameraView extends Activity implements SurfaceHolder.Callback {
private static final String TAG = "CameraVeiw";
private Camera camera;
boolean previewing = false;
SurfaceHolder surfaceHolder;
private File file = null;
private static String mFileName = null;
private long name;
final int RESULT_SAVEIMAGE = 0;
private int w;
private int h;
public static byte[] data = null;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.camera);
}
我SurfaceView
用来捕捉图像
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceview);
surfaceHolder = surfaceView.getHolder();
surfaceView.getWindowVisibility();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
surfaceHolder.setFixedSize(300, 300); //hard coded
Button button2 = (Button) findViewById(R.id.picbutton);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
camera.takePicture(new CustomShutter(), null,
new CustomPictureCallback());
}
});
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
if(previewing){
camera.stopPreview();
previewing = false;
}
if (camera != null){
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
previewing = true;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void surfaceCreated(SurfaceHolder holder) {
camera = Camera.open();
camera.setDisplayOrientation(90); }
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
camera.stopPreview();
camera.release();
camera = null;
previewing = false;
}
class CustomPictureCallback implements Camera.PictureCallback {
private Bitmap bitmap;
public void onPictureTaken(byte[] data, Camera camera) {
FileOutputStream outStream = null;
try {
String path = "/sdcard/MonsterApp/Photos/" + data+".jpg";
outStream = new FileOutputStream(String.format(path));
outStream.write(data);
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");
camera.startPreview();
Log.i("Information", "Helllllooooo"); } }
class CustomShutter implements Camera.ShutterCallback {
public void onShutter() {
}
}
@Override
public void onDestroy() {
super.onDestroy();
if(camera != null) {
camera.release();
}
}
}