我有许多带有alpha的PNG图像,我已使用XnConvert将其转换为WEBP。转换本身很好,并且维护了Alpha通道,直到上传到BlobStore
在上传到blobstore之前,它看起来像这样:
之后看起来像这样:
它由服务URL作为JPG提供,因此删除了alpha通道。在App Engine控制台的BlobStore查看器中,它已将content-type设置为application / octet-stream,即使上传的文件具有.webp文件扩展名。
根据Images API documentation,应该支持WEBP。
上传图片时,我没有做任何奇特的事情:
List<BlobKey> blobs = blobstoreService.getUploads(req).get("file");
BlobKey blobKey = blobs.get(0);
ImagesService imagesService = ImagesServiceFactory.getImagesService();
ServingUrlOptions servingOptions = ServingUrlOptions.Builder.withBlobKey(blobKey);
String servingUrl = imagesService.getServingUrl(servingOptions);
EDIT:
这是服务网址的示例: example serving url
我尝试使用 Chrome 以及Android客户端访问它。 这是用于在Android客户端访问它的代码,虽然我不认为它是相关的:
URL url = new URL(Assets.getServingUrl(resourceName));
URLConnection connection = url.openConnection();
connection.connect();
String contentType = connection.getContentType();
String fileExt;
if(contentType.contains("webp"))
fileExt = ".webp";
else if(contentType.contains("png"))
fileExt = ".png";
else if(contentType.contains("jpeg") || contentType.contains("jpg"))
fileExt = ".jpg";
// download the file
InputStream input = new BufferedInputStream(url.openStream(),8192);
OutputStream output = MyApp.getAppContext().openFileOutput(resourceName + fileExt,Activity.MODE_PRIVATE);
byte data[] = new byte[1024];
int count;
while ((count = input.read(data)) != -1) {
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
希望通过Google Images API提供图像,因为图像可以动态调整大小。
谁能帮助我指出正确的方向来解决这个问题?
EDIT2:
我尝试直接通过blobstore提供blob,如下所示:blobstoreService.serve(new BlobKey(assetEntity.blobKey), res);
而不是通过图像服务,然后它工作正常。但是,这不是一种选择,因为以这种方式服务它们所需的实例小时数会增加。但至少这会将问题缩小到图像服务。
答案 0 :(得分:4)
您可以将选项=-rw
附加到您的网址。所以你会有像
http://lh3.ggpht.com/MvNZDvZcBaq_B2MuAj0-Y74sc24WAsOVIQiJzsowu1rVG-ACzGO80xxD9y5OI5dWSCa_Nt41aMmWSSYAbpFE8dW7BhxozH2ikcVLjw=s600-rw
您正在使用jpeg缩略图,因为这是使用webp时的默认设置,因为所有浏览器尚未完全支持该格式。