Hai是Android Application.i中的新手。使用Camera.Now生成一个代码来拍照。我想在不使用Database.i的情况下查看拍摄的照片。我不知道怎么做.AnyBody请帮帮我。 提前致谢 这是我的代码
private void createCamera() {
// TODO Auto-generated method stub
preview = new Preview(this);
((FrameLayout) findViewById(R.id.preview)).addView(preview);
buttonClick = (Button) findViewById(R.id.buttonClick);
buttonClick.setOnClickListener( new OnClickListener() {
public void onClick(View v) {
preview.camera.takePicture(shutterCallback, rawCallback, jpegCallback);
}
});
Log.d(TAG, "onCreate'd");
}
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) {
FileOutputStream outStream = null;
try {
outStream = new FileOutputStream(String.format("/sdcard/%d.jpg", System.currentTimeMillis()));
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");
}
};
private void createpictures() {
img = (ImageView)findViewById(R.id.ImageView01);
((Button) findViewById(R.id.Button01)).setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
System.out.println("Image Path : " + selectedImagePath);
img.setImageURI(selectedImageUri);
}
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
答案 0 :(得分:1)
这很简单:
Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse("file://"+yourFileName));
startActivity(in);
用于查看图片的默认应用程序将开始,或者如果没有默认应用程序,则用户获取选择对话框以使用哪个应用程序。
答案 1 :(得分:0)
你真的不需要使用数据库来查看拍摄的照片。
答案 2 :(得分:0)
通过手机上的意图打开数据的概述。所有这些文档都在这里http://developer.android.com/guide/topics/intents/intents-filters.html,但不是很清楚。
http://indyvision.net/2010/03/android-using-intents-open-files/
File imageFile2View = new File("/sdcard/nice_photo.jpeg");
Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(imageFile2View), "image/jpeg");
startActivity(i);
现在,如果你想要的是显示你在自己的活动中拍摄的照片,你可以使用。
String file = String.format("/sdcard/%d.jpg", System.currentTimeMillis());
//SAVE IMAGE TO file
img.setImageURI(URI.parse(file));
或
String file = String.format("/sdcard/%d.jpg", System.currentTimeMillis());
//SAVE IMAGE TO file
bitmap = BitmapFactory.decodeFile(file);
img.setImageBitmap(bitmap);