我的程序捕获图像(作为位图)但我不知道(并且找不到)如何在自定义路径中使用自定义名称保存它...这是我的图像捕获代码。我可以做吗?或者有没有办法将其另存为另一种数据类型,而不是位图?一些帮助将是伟大的。感谢。
public class ShowMessagesPage extends Activity {
final static int CAMERA_RESULT = 0;
DBAdapter db = new DBAdapter(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_messages_page);
Button userButton = (Button)findViewById(R.id.button1);
userButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
error();
}});
Button buttonPhoto = (Button)findViewById(R.id.buttonPhoto);
buttonPhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, CAMERA_RESULT);
}});}
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (resultCode == RESULT_OK) {
Bundle extras = intent.getExtras();
Bitmap bmp = (Bitmap) extras.get("data");
}
}
and the other codes..........
答案 0 :(得分:1)
试试这个:
Intent getCameraImage = new Intent("android.media.action.IMAGE_CAPTURE");
File cameraFolder;
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
cameraFolder = new File(android.os.Environment.getExternalStorageDirectory(),"folder_name_of_your_choice");
else
cameraFolder= ShowMessagesPage.this.getCacheDir();
if(!cameraFolder.exists())
cameraFolder.mkdirs();
File photo = new File(Environment.getExternalStorageDirectory(), "folder_name_of_your_choice/camera_snap.jpg");
getCameraImage.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
initialURI = Uri.fromFile(photo);
startActivityForResult(getCameraImage, CAMERA_RESULT);
在onActivityResult()中,处理Uri initialURI
以获取已保存到您在上面发布的代码中选择的路径的图像。图像文件的名称为: camera_snap.jpg
注意:Uri initialURI
是全局声明的。