安卓上传图片前压缩(Bitmap 转 Stream)
ITPOW2018/9/24 21:54:16
代码:
Bitmap bitmap = ImageHelper.getFitSampleBitmap(f.value, 1000, 1778); // 压缩尺寸 // Bitmap bitmap = BitmapFactory.decodeFile(f.value); ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 80, baos); // 压缩质量 InputStream stream = new ByteArrayInputStream(baos.toByteArray());
ImageHelper 是我自己写的压缩图片尺寸的方法,网上有现成的很多,这里就不提供了。然后将 steam 写入上传流就可以了。
<<返回首页<<