/** * 获取网络图片 * @param url--请求地址 * @param width--定制宽度dp * @param height--定制位图dp * @return--定制的位图 */ public static Bitmap requestBitmap(String url,int width, int height){ if(url != null){ byte[] data = getByteData(url); if(data != null){ int length = data.length; //add by Hfeng BitmapFactory.Options options= new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(data, 0, length, options); int w = options.outWidth; int h = options.outHeight; int dstWidth = 0; int dstHeight = 0; if(w > width){ dstWidth = width; } else { dstWidth = w; } if(h > height){ dstHeight = height; } else{ dstHeight = h; } options.inJustDecodeBounds = false; options.inPreferredConfig = Bitmap.Config.RGB_565; options.inPurgeable = true; options.inInputShareable = true; Bitmap bitMap = BitmapFactory.decodeByteArray(data, 0, length, options); // Bitmap newBitmap = Bitmap.createScaledBitmap(bitMap, width, height, true); Bitmap newBitmap = Bitmap.createBitmap(bitMap,0,0,dstWidth,dstHeight,null,true); if(null != newBitmap){ if(newBitmap != bitMap){ bitMap.recycle(); } return newBitmap; } else { return bitMap; } // return bitMap; } } return null; }
android 对图片进行裁剪的方法
最新推荐文章于 2024-07-09 10:44:53 发布