简体   繁体   English

如何在应用程序中保存图片?

[英]How to save a picture in an application?

I want to know how I can save an image in my storage because in my app I can take a photo and see it, but when I close my app and reopen it, the image disappears I have used bitmap. 我想知道如何将图像保存在存储器中,因为在我的应用程序中我可以拍照并看到它,但是当我关闭应用程序并重新打开它时,该图像消失了,我使用了位图。

My code: 我的代码:

public static final int REQUEST_CODE = 01;
private ImageView imgs1;
private File outputMediaFile;

protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.semana1);
     imgs1 = (ImageView) findViewById(R.id.imgs1);
}

public void btnTakePhotoClicked1(View v){
    Intent intent1= new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(intent1, REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode == RESULT_OK){
        Bitmap bm1= (Bitmap) data.getExtras().get("data");
        imgs1.setImageBitmap(bm1);
    }
} 

Use this code in onActivityResult, after you have obtained the image bitmap object. 获取图像位图对象后,请在onActivityResult中使用此代码。

File file = new File("foldername/imagename.jpg")
OutputStream fOut = new FileOutputStream(file);
bm1.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
fOut.flush();
fOut.close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用程序会拍照,但不会保存 - Application will take a picture, but will not save it 如何保存图片并在PC上访问它? - How to save a picture and access it on a PC? 如何在Android中创建目录并将图片保存到其中 - How to create a directory, and save a picture to it in Android 如何将Java中的图片保存为多个blob? - How to save a picture in Java into Multiple blob? 如何为每个ListItem Android保存唯一的图片 - How to save unique picture per ListItem Android 如何在Spring应用程序的html页面中添加图片 - How to add a picture in html page in Spring application 作法:将画布另存为SD卡上的图片并始终保留第一张图片 - How to: Save the canvas as image on SD card and always keeps the first picture 如何将文件(图片,pdf)保存到ibm db2中 - How to save a file(picture, pdf) into ibm db2 如何在数据库中正确保存图片路径并将其分配到按钮? - how to properly save a picture path in a database and assign it into a button? 如何在按下按钮时动态更改图片并保存该图片的状态 - How to change a picture dynamically when a button is pressed and save the state of that image
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM