我正在使用一个像图片库这样的应用程序。这允许用户从他的计算机中选择文件并上传图像。上传图像后,该图像将显示在图库中。我将图片保存在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)
*/}
有没有人在服务器端使用image api,请告诉我如何获得从blobkey或byte[]创建的图像的宽度和高度
发布于 2011-12-09 17:00:21
感谢所有人的阅读,我已经用这个解决了我的问题
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();发布于 2011-12-08 18:46:42
图像对象具有高度/体重详细信息:
int width = oldImage.getWidth();
int height = oldImage.getHeight();https://stackoverflow.com/questions/8426945
复制相似问题