相关疑难解决方法(0)

如何在上传到服务器之前减小图像文件大小

许多应用程序允许共享从图库中挑选的图像.

他们上传原始图片文件吗?这是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) …
Run Code Online (Sandbox Code Playgroud)

upload android image

73
推荐指数
5
解决办法
7万
查看次数

Firebase推送键 - 允许使用的字符

我想知道推键中允许哪种字符.它是否还生成符号下划线(_)?我总是得到一个带字母的按键 - .

firebase firebase-realtime-database

11
推荐指数
1
解决办法
5989
查看次数