GAE - 获得服务器端图像的宽度和高度 [英] GAE - get Image width and height on server side

查看:109
本文介绍了GAE - 获得服务器端图像的宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我像一个图片库的应用程序的工作。
这允许从他的计算机用户选择文件并上传图片。上传图片后,该图片会在画廊展出。
我保存图像的Blob存储,并通过的BlobKey得到它。
我婉得到一个缩略图(即从THRE原始图像大小)
在服务器端,我尝试使用图像API来调整基础上TE原来一个人的的BlobKey,像这样

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

}

有没有人曾与服务器端的图像API的工作,请让我知道如何获取图像的宽度和高度,从的BlobKey或字节[]

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[]

推荐答案

感谢所有阅读
我已经使用这个解决我的问题。

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

这篇关于GAE - 获得服务器端图像的宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆