许多应用程序允许共享从图库中挑选的图像。
他们上传原始图片文件吗?这是1-3 MB?或者他们处理?
在任何情况下,我如何从文件路径中获取图像,通过降低分辨率来减小其大小,并将其保存在其他地方并尝试上传?
我试过了:
Bitmap photo = decodeSampledBitmapFromFile(filePath, DESIRED_WIDTH,
DESIRED_HEIGHT);
FileOutputStream out = new FileOutputStream(filePath);
photo.compress(Bitmap.CompressFormat.JPEG, 100, out);
public static Bitmap decodeSampledBitmapFromFile(String path, int reqWidth,
int reqHeight) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
final int height = options.outHeight;
final int width = options.outWidth;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
int inSampleSize = 1;
if (height > reqHeight) {
inSampleSize = Math.round((float) height / (float) reqHeight);
}
int expectedWidth = width / inSampleSize;
if (expectedWidth > reqWidth) {
inSampleSize = Math.round((float) width / (float) reqWidth);
}
options.inSampleSize = inSampleSize;
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(path, options);
}
但这是他们正确的方法吗?因为我在这里看到了答案compression operation takes rather big amount of time
凤凰求蛊
GCT1015
相关分类