[英]How to view the taken pictures in Android Without using Database?
Hai am new in Android Application.i Generated a code to take picture by using Camera.Now i want to view the Taken Pictures without using Database.i dont know how to do this.AnyBody please help me. Hai是Android Application.i中的新手。使用Camera.Now生成一个代码来拍照。我想在不使用Database.i的情况下查看拍摄图片。我不知道怎么做.AnyBody请帮帮我。 Thanks in advance Here my Code 在此先感谢我的代码
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);
}
Simple as this: 很简单:
Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse("file://"+yourFileName));
startActivity(in);
Default app for viewing pictures will start, or if there's no default, user get selection dialog which app to use. 将开始查看图片的默认应用程序,或者如果没有默认值,则用户获取选择对话框以使用哪个应用程序。
you really dont need to use database to view taken picture. 你真的不需要使用数据库来查看拍摄的照片。
heres a good overview of opening data via intents on your phone. 这是一个很好的概述,通过手机上的意图打开数据。 All this documentation is in here as well http://developer.android.com/guide/topics/intents/intents-filters.html but not as clear to follow. 所有这些文档都在这里http://developer.android.com/guide/topics/intents/intents-filters.html,但不是很清楚。
http://indyvision.net/2010/03/android-using-intents-open-files/ 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);
Now if what your looking for is to display the picture you took in your own activity you can use. 现在,如果你想要的是显示你在自己的活动中拍摄的照片,你可以使用。
String file = String.format("/sdcard/%d.jpg", System.currentTimeMillis());
//SAVE IMAGE TO file
img.setImageURI(URI.parse(file));
or 要么
String file = String.format("/sdcard/%d.jpg", System.currentTimeMillis());
//SAVE IMAGE TO file
bitmap = BitmapFactory.decodeFile(file);
img.setImageBitmap(bitmap);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.