Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我生成的应用引擎和云存储缩略图图像的文件大小比原始图像大_Java_Google App Engine_Google Cloud Storage - Fatal编程技术网

Java 我生成的应用引擎和云存储缩略图图像的文件大小比原始图像大

Java 我生成的应用引擎和云存储缩略图图像的文件大小比原始图像大,java,google-app-engine,google-cloud-storage,Java,Google App Engine,Google Cloud Storage,我的函数适用于我,但缩略图文件大小大于原始文件大小 原始文件:30Kb 缩略图文件:50Kb 我的职能 public static void thumbnailImage(String filename, int width, int height) throws IOException{ GcsService gcsService = GcsServiceFactory.createGcsService(new RetryParams.Builder()

我的函数适用于我,但缩略图文件大小大于原始文件大小

原始文件:30Kb

缩略图文件:50Kb

我的职能

public static void thumbnailImage(String filename, int width, int height) throws IOException{
    GcsService gcsService = GcsServiceFactory.createGcsService(new RetryParams.Builder()
              .initialRetryDelayMillis(10)
              .retryMaxAttempts(10)
              .totalRetryPeriodMillis(15000)
              .build());
    AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService();
    ImagesService imagesService = ImagesServiceFactory.getImagesService();
    // Make an image from a Cloud Storage object, and transform it.
    BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
    BlobKey blobKey = blobstoreService.createGsBlobKey("/gs/" + appIdentity.getDefaultGcsBucketName() +"/"+ filename);

    Image thumb = null;
    try{
        Image blobImage = ImagesServiceFactory.makeImageFromBlob(blobKey);          
        Transform resize = ImagesServiceFactory.makeResize(width, height);
        thumb = imagesService.applyTransform(resize, blobImage);

    }catch(Exception e){
        e.printStackTrace();
    }
    String extension = Files.getFileExtension(filename);
    filename = stripExtension(filename);
    filename = String.format("%1$s_%2$s.%3$s", filename, thumbnail, extension);

    if(thumb!=null)
    // Write the transformed image back to a Cloud Storage object.
    gcsService.createOrReplace(
        new GcsFilename(appIdentity.getDefaultGcsBucketName(), filename),
        new GcsFileOptions.Builder().mimeType("image/jpeg").acl("public-read").build(),
        ByteBuffer.wrap(thumb.getImageData()));
}
原始文件只有
30KB
,但缩略图是
50KB
。它们具有相同的V分辨率和H分辨率
96dpi
和位深度
24
。还有什么我错过的吗?有很多类似的问题,我不确定我的问题是否重复

编辑:

这是谷歌云上的链接

缩略图:


谢谢tx802和jterrace

我现在找到了解决办法。我将OutputSettings添加到transform函数以将编码更改为JPEG

thumb = imagesService.applyTransform(resize, blobImage, new OutputSettings(OutputEncoding.JPEG));

现在我的缩略图只有5Kb。

您的源图像是jpg,缩略图是png。你会得到更好的压缩与jpg缩略图。我不知道为什么在这里转换为png,但在我的云是jpgYou可能需要对输出文件。谢谢你,这是我正在寻找的。但我不需要设置质量,只需将编码更改为JPEG即可。