Android中怎样由图片的id号R.drawable.XX得到图片文件XX的绝对路径

qingtaopeng 2012-06-12 06:24:47

Android中怎样由图片的id号R.drawable.XX得到图片文件XX的绝对路径, 因为我想调用函数
Bitmap resizedBitmap=BitmapFactory.decodeFile(filepaths, options);其中的filepaths就是我要的drawable目录下图片文件的绝对路径.
...全文
3831 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
daixw0415 2012-09-20
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

请问一下怎样在普通类中(没有继承Activity的类)对drawable中的图片进行压缩呢!非常感谢
[/Quote]

Bitmap.createBitmap(Bitmap source, int x, int y,int width, int height, Matrix m, boolean filter)方法可以通过对源图像进行缩放操作得到一个新的被缩放后的图像。具体缩放的信息有Matrix指定的。
如:
Bitmap sourceBitmap = aBitmap;
Matrix m = new Matrix();
m.postScale(0.5f,0.5f);//缩小为原来的一半大小
Bitmap newBitmap = Bitmap.createBitmap(sourceBitmap,0,0,sourceBitmap.getWidth(),sourceBitmap.getHeight(),m,true);
这样就可以生成newBitmap了。
loveyanwen 2012-09-20
  • 打赏
  • 举报
回复
楼上正解
b87936260 2012-09-19
  • 打赏
  • 举报
回复
传Context参数进去就可以了
  • 打赏
  • 举报
回复
请问一下怎样在普通类中(没有继承Activity的类)对drawable中的图片进行压缩呢!非常感谢
qingtaopeng 2012-06-14
  • 打赏
  • 举报
回复
谢谢各位。
横龙村夫 2012-06-13
  • 打赏
  • 举报
回复
建议你放在assert文件夹下面,然后操作assert
RDroid 2012-06-12
  • 打赏
  • 举报
回复
BitmapFactory.decodeResource(Resources res, int id, BitmapFactory.Options opts)
qingtaopeng 2012-06-12
  • 打赏
  • 举报
回复
因为我要对drawable目录下图片进行缩放,BitmapFactory.decodeFile的其他重载及BitmapFactory.decodeResource(Resources res, int id)都用不上,唯独要用BitmapFactory.decodeFile(filepaths, options)。
RDroid 2012-06-12
  • 打赏
  • 举报
回复
BitmapFactory.decodeResource(Resources res, int id)
jefferyyangkai 2012-06-12
  • 打赏
  • 举报
回复
BitmapFactory.decodeFile这个有其他的重载,可以传resId进去的,你仔细看看。

80,493

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧