Joa*_*him 4 google-app-engine android blobstore webp
我有许多带有 alpha 的 PNG 图像,我已使用 XnConvert 将它们转换为 WEBP。转换本身进行得很顺利,并且 Alpha 通道保持不变,直到上传到BlobStore
在上传到 blobstore 之前,它看起来像这样:

之后看起来像这样:

它由服务 URL 作为 JPG 提供,因此 Alpha 通道被删除。在 App Engine 控制台的 BlobStore 查看器中,它已将内容类型设置为 application/octet-stream,即使上传的文件具有 .webp 文件扩展名。
根据Images API 文档,它应该支持 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);
Run Code Online (Sandbox Code Playgroud)
EDIT:
这是一个服务 url 示例: 示例服务 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();
Run Code Online (Sandbox Code Playgroud)
希望通过 Google Images API 提供图像,因为图像可以动态调整大小。
谁能帮我指出解决这个问题的正确方向吗?
EDIT2:
我尝试直接通过 blobstore 提供 blob,如下所示:blobstoreService.serve(new BlobKey(assetEntity.blobKey), res);而不是通过图像服务,然后它就可以正常工作。然而,这不是一个选择,因为以这种方式提供服务所需的实例时间会增加。但至少这将问题范围缩小到图像服务。
您可以将该选项附加=-rw到您的网址。所以你会得到类似的东西
http://lh3.ggpht.com/MvNZDvZcBaq_B2MuAj0-Y74sc24WAsOVIQiJzsowu1rVG-ACzGO80xxD9y5OI5dWSCa_Nt41aMmWSSYAbpFE8dW7BhxozH2ikcVLjw=s600-rw
Run Code Online (Sandbox Code Playgroud)
您得到的是 jpeg 缩略图,因为这是使用 webp 时的默认缩略图,因为所有浏览器尚未完全支持该格式。
| 归档时间: |
|
| 查看次数: |
2040 次 |
| 最近记录: |