Android:将图像保存到存储 [英] Android: Saving image to storage
本文介绍了Android:将图像保存到存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前,我的应用程序正在拍照,然后将数据放入ImageView中.
Currently my application, takes a photo, and put's the data into a ImageView.
public void openCamera() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
现在,我希望它执行此操作:当用户单击保存按钮"按钮时,我希望将其保存到存储中.我该怎么办?我使用OnClick侦听器设置了按钮.
Now, i want it to do this: When the user clicks the button 'Save Button' I would like it to save to storage. How would i do this? I have my button set up with an OnClick listener.
public void save_btn() {
}
推荐答案
步骤1:按住Bitmap
某处
步骤2:单击该按钮时,派生一个后台线程,AsyncTask
,IntentService
等进行工作
Step #2: When the button is clicked, fork a background thread, AsyncTask
, IntentService
, etc. to do the work
Step #3: In the background thread (or whatever), call compress()
on the Bitmap
, providing an OutputStream
on whatever file you want to write to
这篇关于Android:将图像保存到存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文