gpt4 book ai didi

image - GAE - 在服务器端获取图像宽度和高度

转载 作者:太空宇宙 更新时间:2023-11-03 15:37:06 25 4
gpt4 key购买 nike

我正在使用类似图片库的应用程序。这允许用户从他的计算机中选择文件并上传图像。上传图片后,该图片将显示在图库中。我将图像保存在 blobstore 中,并通过 blobkey 获取它。我想获得缩略图(根据原始图像调整大小)在服务器端,我尝试使用图像 api 根据它的 blobkey 调整原始图像的大小,就像这样

public String getImageThumbnail(String imageKey) {
BlobKey blobKey = new BlobKey(imageKey);
Image oldImage = ImagesServiceFactory.makeImageFromBlob(blobKey);
/*
* can not get width anf height of "oldImage"
* then I try to get imageDate of old Image to create a new image like this
*/
byte[] oldImageData = oldImage.getImageData();

Image newImage1 = ImagesServiceFactory.makeImage(oldImageData);
/*
* however
* oldImage.getImageData(); return null/""
* and cause the Exception when call this ImagesServiceFactory.makeImage(oldImageData)
*/

有没有人在服务器端使用过图像 api,请让我知道如何获取从 blobkey 或 byte[] 创建的图像的宽度和高度

最佳答案

感谢大家阅读我已经用这个解决了我的问题

    ImagesService imagesService = ImagesServiceFactory.getImagesService();
BlobKey blobKey = new BlobKey(imageKey);
BlobInfo blobInfo = new BlobInfoFactory().loadBlobInfo(blobKey);
byte[] bytes = blobstoreService.fetchData(blobKey, 0, blobInfo.getSize());
Image oldImage = ImagesServiceFactory.makeImage(bytes);
int w = oldImage.getWidth();
int h = oldImage.getHeight();

关于image - GAE - 在服务器端获取图像宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8426945/

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