首页 > 系统 > Android > 正文

android 图片

2019-11-08 00:06:32
字体:
来源:转载
供稿:网友

图片的缩放

BitmapFactory.Options options = new BitmapFactory.Options();options.inSampleSize = 4; //长、宽分别缩放至原图的1/4Bitmap bitmap = BitmapFactory.decodeFile(filepath, options);viewHolder.mImageView.setImageBitmap(bitmap);

不占用内存,获取图片信息,可以认为是dummy decoder

BitmapFactory.Options boolean inJustDecodeBounds If set to true, the decoder will return null (no bitmap), but the out… fields will still be set, allowing the caller to query the bitmap without having to allocate the memory for its pixels.

outHeight与outWidth就是图片的长和宽。 可以先用这种方式获取长宽,然后再决定图片的尺寸。

Drawable from file

Drawable drawable = Drawable.createFromPath(filepath);viewHolder.mImageView.setImageDrawable(drawable);

SET IMAGE WITH URI

Uri uri = Uri.fromFile(new File(filepath));viewHolder.mImageView.setImageURI(uri);
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表