android ImageButton显示本地图片

得到本地图片(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);
		}
	}

你可能感兴趣的:(android,imagebutton,BitmapFctory)