我有一个名为Order
的类,它包含一个指向另一个名为PrescriptionImage
的类的指针数组。我想查询所有这些图像并为它们添加水印。之后我需要保存这些图像(基本上更新它们)。
我无法找到为图像添加水印的方法,并且对通过云代码处理图像感到困惑。很多教程都将它用于javascript并使用html代码。
Parse.Cloud.define("stampPrescription", function(request, response){
// String that contains the current date
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
var dateAsString = dd+"-"+mm+"-"+yyyy;
// object id for the Order object being called
var orderObjectId = request.params.orderObjectId;
var address = request.params.address;
var order = Parse.Object.extend("Order");
var queryForOrder = new Parse.Query(order);
queryForOrder.include("Prescriptionimage");
queryForOrder.get(orderObjectId , {
success: function(results){
console.log("value found is "+results.id);
var rxImages = results.get("prescriptionImageArray");
for (var i = 0; i < rxImages.length; i++) {
var imageFile = rxImages[i];
// I retrive the images and store in a variable
// TODO: Need help with below line
// place watermark with dateAsString and address at bottom of the image
}
response.success("done";
}, //Ends block for successfuly query
error: function(e){
console.log("Error in query "+e.message);
respone.error("Error in query "+e.message);
}
}); // Ends queryForOrder block
}); //Ends the function
我的主要问题是,我通过在android中使用paint1在android手机(客户端)的图像上放置水印。我现在想将此代码转移到服务器端,即解析云代码以提高效率和速度。有人可以帮我解决这个问题吗?目前下面是我在android中用来修改位图的代码。
public Bitmap mark(Bitmap src, int alpha, int size, boolean underline) {
int w = src.getWidth();
int h = src.getHeight();
Bitmap result = Bitmap.createBitmap(w, h, src.getConfig());
Canvas canvas = new Canvas(result);
canvas.drawBitmap(src, 0, 0, null);
Paint paint = new Paint();
paint.setColor(Color.parseColor("#551A8B"));
paint.setAlpha(alpha);
paint.setTextSize(size);
paint.setAntiAlias(true);
paint.setUnderlineText(underline);
final Calendar c = Calendar.getInstance();
SimpleDateFormat time = new SimpleDateFormat("HH:mm:ss");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
String currentTime = time.format(c.getTime());
String currentDate = dateFormat.format(c.getTime());
canvas.drawText(name, w / 2, 3 * h / 4 - 15, paint);
canvas.drawText(currentTime, w / 2, 3 * h / 4 + 5, paint);
canvas.drawText(currentDate, w / 2, 3 * h / 4 + 25, paint);
canvas.drawText(chemistAddress1, w / 2, 3 * h / 4 + 45, paint);
return result;
}
如果我需要标记多个图像然后上传,则会显着减慢进程并占用更多内存。我不想冒OOM
例外的风险,所以想把上面的过程转移到云代码上,但是我找不到上面那个可以在解析云代码上运行的等价物。