问题描述
我们有一个应用程序,用于从blobstore服务一系列图像。一个
的例子就在这里:
这是一个庞大的png,所以这个下载量为536K。
如果我们把它调整到400,它仍然很大(263k): b
$ b
我们如何可以请求或存储图片的某种更好的
压缩?我们有一个移动客户端用于我们的应用程序,并且通过
等待273K使它真的很慢。
我们有一个应用程序,用于从blobstore服务一系列图像。一个
的例子就在这里:
这是一个庞大的png,所以这个下载量为536K。
如果我们把它调整到400,它仍然很大(263k): b
$ b
我们如何可以请求或存储图片的某种更好的
压缩?我们有一个移动客户端用于我们的应用程序,并且通过
等待273K使它真的很慢。
。压缩和调整图像大小:
//从blobstore获取图像
ImagesService imagesService = ImagesServiceFactory.getImagesService();
Image oldImage = ImagesServiceFactory.makeImageFromBlob(blobKey);
// compress&调整大小
OutputSettings settings = new OutputSettings(ImagesService.OutputEncoding.JPEG);
settings.setQuality(90);
Transform transform = ImagesServiceFactory.makeResize(newWidth,newHeight)
图片newImage = imagesService.applyTransform(transform,oldImage,settings);
byte [] blobData = newImage.getImageData();
//将数据保存到blobstore
FileService fileService = FileServiceFactory.getFileService();
AppEngineFile file = fileService.createNewBlobFile(image / jpeg,someFilename);
FileWriteChannel writeChannel = fileService.openWriteChannel(file,true);
writeChannel.write(ByteBuffer.wrap(blobData));
writeChannel.closeFinally();
//将blobKey写入新写入的数据
BlobKey blobKey = fileService.getBlobKey(file);
We have an app that servers a series of images from blobstore. Anexample is here:
It was a huge png, so this downloads at 536K.
If we resize it to 400 across, it's still huge (263k):
How can we request or store the picture in some kind of bettercompression? We have a mobile client for our app, and waiting through273K is making it really slow.
There is Images API. To compress and resize image:
// get image from blobstore
ImagesService imagesService = ImagesServiceFactory.getImagesService();
Image oldImage = ImagesServiceFactory.makeImageFromBlob(blobKey);
// compress & resize it
OutputSettings settings = new OutputSettings(ImagesService.OutputEncoding.JPEG);
settings.setQuality(90);
Transform transform = ImagesServiceFactory.makeResize(newWidth, newHeight)
Image newImage = imagesService.applyTransform(transform, oldImage, settings);
byte[] blobData = newImage.getImageData();
//save data to blobstore
FileService fileService = FileServiceFactory.getFileService();
AppEngineFile file = fileService.createNewBlobFile("image/jpeg", someFilename);
FileWriteChannel writeChannel = fileService.openWriteChannel(file, true);
writeChannel.write(ByteBuffer.wrap(blobData));
writeChannel.closeFinally();
// get the blobKey to newly written data
BlobKey blobKey = fileService.getBlobKey(file);
这篇关于如何使用Google App Engine Blobstore压缩图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!