BitmapFctory

android ImageButton显示本地图片

荒凉一梦 提交于 2021-02-09 04:52:39
得到本地图片(png,jpeg,gif)的路径后,将图片显示在ImageButton上。这里先读出图片大小,在设置采样率,使得大图片也能一览全貌。 参考: android Bitmap学习总结 void foo(){ String filepath = bundle.getString("path"); Options opts = new Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(filepath, opts); int samp = LtUtil.getPictureSampleSize( opts.outWidth, opts.outHeight); opts.inJustDecodeBounds = false; opts.inSampleSize = samp; Bitmap bm = BitmapFactory .decodeFile(filepath, opts); if (bm != null) { pictureButton.setImageBitmap(bm); } } 来源: oschina 链接: https://my.oschina.net/u/937845/blog/129945