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



我正在使用一个像图片库的应用程序。这允许用户从他的计算机中选择文件并上传图像。上传图像后,该图像将显示在一个画廊。我将图像保存在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或字节创建的图像的宽度和高度[]

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

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

图像对象的高度/重量细节:

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

最新更新