在項目中須要對縮略圖進行大圖查看,就相似微信的點擊查看大圖,只不過這裏做只採用了一張圖片,沒有左右滑動的效果。android
這裏的圖片是從儲存卡中獲取,首先得須要該圖片的本地地址,而後將本地圖片轉換成Bitmap,設置獲取比例爲1.微信
關鍵代碼以下:ide
public class ShowBigPhoto {
private Context context;
private String path;this
public ShowBigPhoto(Context context, String path){
this.context = context;
this.path = path;
}
public void showDetailPhoto(){
// 全屏顯示的方法
final Dialog dialog = new Dialog(context, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
ImageView imgView = getView();
dialog.setContentView(imgView);
dialog.show();
// 大圖顯示以後,點擊圖片消失
imgView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}
//設置當前imgView的圖片
private ImageView getView() {
ImageView imgView = new ImageView(context);
imgView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
imgView.setImageBitmap(decodeBigPhoto());
return imgView;
}
private Bitmap decodeBigPhoto(){
if (path != null) {
Bitmap bigBitmap;
BitmapFactory.Options opt = new BitmapFactory.Options();
bigBitmap = BitmapFactory.decodeFile(path);
opt.inSampleSize = 1;
opt.inJustDecodeBounds = false;code
bigBitmap = BitmapFactory.decodeFile(path, opt);
//iv_photo.setImageBitmap(bigBitmap);
return bigBitmap;
// releaseBitmap();
}
return null;圖片
}get
在須要進行顯示的activity中,new一個ShowBigPhoto,並調用方法showDetailPhoto()便可。it