和你一起终身学习,这里是程序员Android
经典好文推荐,通过阅读本文,您将收获以下知识点:
从资源中获取Bitmap
Bitmap ----> byte[]
byte[] ----> Bitmap
Bitmap 缩放方法
Drawable ----> Bitmap
圆角图片
获取带倒影的图片
bitmap ----> Drawable
drawable缩放 ,先转 bitmap 后缩放
1. 从资源中获取Bitmap
// 1.从资源中获取Bitmap
2. Bitmap ----> byte[]
// 2.Bitmap ---> byte[] public byte[] BitmapToBytes(Bitmap bitmap) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); press(pressFormat.PNG, 100, baos); return baos.toByteArray(); }
3. byte[] ----> Bitmap
// 3.byte[] ---->bitmap
4. Bitmap 缩放方法
// 4.Bitmap 缩放方法
5. Drawable ----> Bitmap
// 5. Drawable----> Bitmap
6. 圆角图片
-实现效果如下:
圆角图片
实现代码如下:
// 6.圆角图片
7. 获取带倒影的图片
实现效果如下:
带倒影的圆角图片
实现代码如下:
// 7.获取带倒影的图片
8. bitmap ----> Drawable
// 8. bitmap ---Drawable
9. drawable缩放 ,先转 bitmap 后缩放
drawable
缩放 ,先转bitmap
,调用5
中的方法 后缩放。
public static Drawable ZoomDrawable(Drawable drawable, int w, int h) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); // 调用5 中 drawable转换成bitmap Bitmap oldbmp = DrawableToBitmap(drawable); // 创建操作图片用的Matrix对象 Matrix matrix = new Matrix(); // 计算缩放比例 float sx = ((float) w / width); float sy = ((float) h / height); // 设置缩放比例 matrix.postScale(sx, sy); // 建立新的bitmap,其内容是对原bitmap的缩放后的图 Bitmap newbmp = Bitmap.createBitmap(oldbmp, 0, 0, width, height, matrix, true); return new BitmapDrawable(newbmp); }// 9. drawable进行缩放 ---> bitmap 然后比对bitmap进行缩放
如果觉得《android bitmap 获取像素点 太慢_Drawable与 Bitmap 转换总结》对你有帮助,请点赞、收藏,并留下你的观点哦!