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

发布于 2024-12-19 22:21:16 字数 840 浏览 1 评论 0原文

我正在使用像图库这样的应用程序。 这允许用户从他的计算机中选择文件并上传图像。上传图像后,该图像将显示在图库中。 我将图像保存在 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[]

I'm working with an application like an image gallery.
This allow user select file from his computer and upload the image. After upload the image, that image will be display in a gallery.
I save the image in blobstore, and get it by blobkey.
I wan to get a thumbnail image (that was resized from thre original image)
On server side, I try to use image api to resize te original one based on it's blobkey, like this

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)
*/

}

Are there anyone had work with image api on server side, please let's me know how to get width and height of an image that create from a blobkey or an byte[]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遥远的绿洲 2024-12-26 22:21:16

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

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

Thanks all for reading
I've solved my problem using this

    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();
木格 2024-12-26 22:21:16

图像对象具有高度/重量详细信息:

int width = oldImage.getWidth();
int height = oldImage.getHeight();

Image object have height/weight details:

int width = oldImage.getWidth();
int height = oldImage.getHeight();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文