【问题标题】:Get width and height of Image app engine获取Image应用引擎的宽度和高度
【发布时间】:2013-01-24 20:44:35
【问题描述】:
ImagesService imagesService = ImagesServiceFactory.getImagesService();
BlobKey bk = currentProfile.getProfileBlobKey();
Image oldImage = ImagesServiceFactory.makeImageFromBlob(bk);
Transform resize = ImagesServiceFactory.makeResize(500, 500);
Image newImage = imagesService.applyTransform(resize, oldImage);
int imageWidth = newImage.getWidth();
int imageHeight = newImage.getHeight();

此代码似乎不起作用,因为ImagesServiceFactory.makeImageFromBlob(bk); 没有返回真实图像。有谁知道这个的解决方法?这似乎是预期的行为。这个问题在here 中讨论过,但他们没有解决方案来获取字节[]的高度和宽度

【问题讨论】:

    标签: java google-app-engine


    【解决方案1】:

    试试这个:

    FileService fileService = FileServiceFactory.getFileService();
    AppEngineFile blobFile = fileService.getBlobFile(blobKey);
    FileReadChannel readChannel = fileService.openReadChannel(blobFile, false);
    byte[] imageData = getBytes(Channels.newInputStream(readChannel));
    Image oldImage = ImagesServiceFactory.makeImage(imageData);
    // now you have the real Image
    

    还有这个用于读取输入流的小 sn-p:

    public static byte[] getBytes(InputStream is) throws IOException {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    
        int len;
        byte[] data = new byte[10000];
        while ((len = is.read(data, 0, data.length)) != -1) {
            buffer.write(data, 0, len);
        }
    
        buffer.flush();
        return buffer.toByteArray();
    }
    

    【讨论】:

      【解决方案2】:

      您尝试过 ImageReader 类吗?

      【讨论】:

      • 没有,有什么好的文档,找不到任何文档
      猜你喜欢
      • 2021-03-08
      • 2012-12-29
      • 2022-01-21
      • 2017-12-26
      • 1970-01-01
      • 2012-10-10
      • 2021-06-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多