从文件创建路径位图/绘制对象

编程入门 行业动态 更新时间:2024-10-15 12:35:05
本文介绍了从文件创建路径位图/绘制对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图创建一个位图或绘制对象从现有的文件的路径。

I'm trying to create a Bitmap or Drawable from existing file path.

String path = intent.getStringExtra("FilePath"); BitmapFactory.Options option = new BitmapFactory.Options(); option.inPreferredConfig = Bitmap.Config.ARGB_8888; mImg.setImageBitmap(BitmapFactory.decodeFile(path)); // mImg.setImageBitmap(BitmapFactory.decodeFile(path, option)); // mImg.setImageDrawable(Drawable.createFromPath(path)); mImg.setVisibility(View.VISIBLE); mText.setText(path);

但 setImageBitmap(), setImageDrawable()不显示从路径的图像。我打印路径与多行文字,它看起来像: /storage/sdcard0/DCIM/100LGDSC/CAM00001.jpg

But setImageBitmap(), setImageDrawable() doesn't show an image from the path. I've printed path with mText and it looks like : /storage/sdcard0/DCIM/100LGDSC/CAM00001.jpg

我究竟做错了什么?任何人都可以帮我吗?

What am i doing wrong? Anyone can help me?

推荐答案

从文件创建路径的位图:

Create bitmap from file path:

File sd = Environment.getExternalStorageDirectory(); File image = new File(sd+filePath, imageName); BitmapFactory.Options bmOptions = new BitmapFactory.Options(); Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(),bmOptions); bitmap = Bitmap.createScaledBitmap(bitmap,parent.getWidth(),parent.getHeight(),true); imageView.setImageBitmap(bitmap);

如果你想扩展位图到父的高度和宽度,然后使用 Bitmap.createScaledBitmap 的功能。

If you want to scale the bitmap to the parent's height and width then use Bitmap.createScaledBitmap function.

我觉得你给了错误的文件路径。 :)希望这会有所帮助。

I think you are giving the wrong file path. :) Hope this helps.

更多推荐

从文件创建路径位图/绘制对象

本文发布于:2023-11-24 12:44:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1625250.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位图   路径   对象   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!