/**
* 网络图片转换为Bitmap
*
* @Author: ChengBin
* @Time: 16/4/5 下午2:41
*/
public static Bitmap netPicToBmp(String src) {
try {
Log.d("FileUtil", src);
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
//设置固定大小
//需要的大小
float newWidth = 200f;
float newHeigth = 200f;
//图片大小
int width = myBitmap.getWidth();
int height = myBitmap.getHeight();
//缩放比例
float scaleWidth = newWidth / width;
float scaleHeigth = newHeigth / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeigth);
Bitmap bitmap = Bitmap.createBitmap(myBitmap, 0, 0, width, height, matrix, true);
return bitmap;
} catch (IOException e) {
// Log exception
return null;
}
}
网络图片转换为Bitmap
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 1.Caltech-UCSD Birds200 鸟类图像数据 Caltech-UCSD Birds200 是一个鸟...
- 0x00 背景 作为移动领域所力推的图片格式,WebP图片在商业领域证明了其应有的价值。基于其他格式的横向对比,其...