【发布时间】:2015-08-12 12:27:01
【问题描述】:
我正在开发一个处理图片并使用parse.com 服务作为后端的应用程序。在某些时候,我不得不在以下两者之间做出选择:
- 存储同一张图片的不同版本,例如
100x100用于缩略图,400x400用于更大视图,1000x1000用于全屏视图; - 仅存储
1000x1000版本,并在需要时将其缩小,可能在服务器端。
我目前正在研究的解决方案是两者的混合:我持有100x100 用于缩略图,1000x1000 用于全屏视图,并希望将其缩小以满足任何其他需要。我开始研究 Cloud Code 功能来实现这一目标。我的愿望是将当前视图的宽度传递给函数,以便使图像适应客户的需要。
var Image = require("parse-image");
Parse.Cloud.define("getPicture", function(request, response) {
var url = request.params.pictureUrl;
var objWidth = request.params.width / 2;
Parse.Cloud.httpRequest({
url: url
}).then(function(resp) {
var i = new Image();
return i.setData(resp.buffer);
}).then(function(i) {
var scale = objWidth / i.width();
if (scale >= 1) {
response.success(i.data());
}
return i.scale({
ratio: scale
});
}).then(function(i) {
return i.data();
}).then(function(data) {
response.success(data);
});
});
我有两个问题:
这种方法是否正确,或者我应该更好地存储一个中等大小的图像版本(如
400x400)?这会决定对云代码函数的调用过多吗? (我不知道parse.com对云函数调用的数量有任何限制,但可能有)-
i.data()返回的是什么类型的对象,我如何从中获取Bitmap?通过我正在调用的 Android 应用程序:HashMap<String, Object> params = new HashMap<>(); params.put("pictureUrl",getUrl()); params.put("width", getWidth()); ParseCloud.callFunctionInBackground("getPicture", params, new FunctionCallback<Object>() { @Override public void done(Object object, ParseException e) { //here I should use BitmapFactory.decodeByteArray(...) //but object is definitely not a byte[] ! //From debugging it looks like a List<Integer>, //but I don't know how to get a Bitmap from it. } });
【问题讨论】:
标签: javascript java android parse-platform