Bitmap:
Bitmap newBmp = Bitmap.createScaledBitmap(oldBmp, displayWidth, displayHeight, true)Drawable
先把Drawable转换成Bitmap:
Bitmap Drawable2Bitmap(Drawable drawable){Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight(),drawable.getOpacity() != PixelFormat.OPAQUE ?Bitmap.Config.ARGB_8888: Bitmap.Config.RGB_565)
Canvas canvas = new Canvas(bitmap)
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight())
drawable.draw(canvas)
return bitmap
}
2.用上面压缩bitmap宽高的方法压缩bitmap
3.Bitmap转换回Drawable
Drawable Bitmap2Drawable(Context context, Bitmap bitmap){return new BitmapDrawable(context.getResources(), bitmap)
}
一般来说一个点被精确的认定为1/72英寸,在WPF中,采用的设备无关单位即1/96英寸所以程序中获取的图片大小 比真实图片的大小要大一点, 获取到图片大小后进行相应的转换即可获得图片原来的尺寸如: height=height*72/96
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)