简体   繁体   English

Android:从SD卡上的已知路径将图像绘制到ImageView上

[英]Android: Drawing Image onto ImageView from a known path on SD Card

I have a screen that contains an ImageView which is not visible to user. 我有一个包含用户不可见的ImageView的屏幕。 User would have to browse for a picture from their Gallery, in which I have successfully coded. 用户必须浏览他们的图库中的图片,我已成功编码。 I've used toast to ensure that the path to the Image selected is correct and have stored the path to a string. 我已经使用toast来确保所选Image的路径是正确的并且已经存储了到字符串的路径。 My problem is after selecting the image, how can I draw the selected image on the ImageView by using the path? 我的问题是在选择图像后,如何使用路径在ImageView上绘制所选图像? Is it even possible? 它甚至可能吗?

Try the below code to set Bitmap images from a file stored inside a SD-Card. 尝试以下代码从存储在SD卡中的文件中设置位图图像。

File imgFile = new  File("/sdcard/Images/test_image.jpg");
if(imgFile.exists()){

    Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

    ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);
    myImage.setImageBitmap(myBitmap);

}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM