gpt4 book ai didi

java - 获取图像应用引擎的宽度和高度

转载 作者:行者123 更新时间:2023-11-30 09:27:36 25 4
gpt4 key购买 nike

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但是他们没有一个解决方案来获得字节[]的高度和宽度

最佳答案

试试这个:

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

还有这个读取输入流的小片段:

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();
}

关于java - 获取图像应用引擎的宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14510377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com