FrameLayout fr=(FrameLayout)findViewById(R.id.FrameLayout01);
BitmapFactory.Options options =new BitmapFactory.Options();
options.inJustDecodeBounds =true;
// 获取这个图片的宽和高
Bitmap bitmap =BitmapFactory.decodeFile("/sdcard/test.jpg", options); //此时返回bm为空
options.inJustDecodeBounds =false;
//计算缩放比
int be = (int)(options.outHeight/ (float)200);
if (be <= 0)
be = 1;
options.inSampleSize = be;
//重新读入图片,注意这次要把options.inJustDecodeBounds 设为 false哦
bitmap=BitmapFactory.decodeFile("/sdcard/test.jpg",options);
int w = bitmap.getWidth();
int h = bitmap.getHeight();
System.out.println(w+" "+h);
ImageView iv=new ImageView(this);
iv.setImageBitmap(bitmap);


File file=new File("/sdcard/feng.png");
try {
FileOutputStream out=newFileOutputStream(file);
if(bitmap.compress(Bitmap.CompressFormat.PNG, 100, out)){
out.flush();
out.close();
}
} catch (FileNotFoundException e){
// TODO Auto-generated catchblock
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catchblock
e.printStackTrace();
}

更多相关文章

  1. android读取系统相机及相册图片(亲测可用)
  2. react native android 调试时图片没有显示出来
  3. Android 图片平铺效果bitmap
  4. Android 保存图片到SQLite
  5. Android 将图片转化为缩略图再加载
  6. 一起学android之设置资源图片为圆角图片 (28)
  7. Android异步加载图片并缓存到内存和SD卡上
  8. Android中ImageSwitcher结合Gallery展示SD卡中的资源图片
  9. ImageView 设置图片

随机推荐

  1. 【Android】:跳转系统界面汇总
  2. Android ConstraintLayout
  3. 对android中MIME类型的理解
  4. Android SDK Emulator: Compile Cyanogen
  5. android的线性布局
  6. android googlemap权限问题
  7. android双击事件
  8. 三款Android游戏源码
  9. Android shape 参数
  10. Android定义宽高比控件