开发者

Problem while saving multiple pictures inside OnDraw()

开发者 https://www.devze.com 2023-04-06 08:48 出处:网络
I am new to Android and I am having trouble to save he multiple pictures in onDraw(Canvas canvas); Here my code to draw the images in canvas

I am new to Android and I am having trouble to save he multiple pictures in onDraw(Canvas canvas);

Here my code to draw the images in canvas

canvas.drawBitmap(resize, 40, 100, null);
canvas.drawBitmap(resizeImage1, 400, 100, null);
canvas.drawText(CameraText, 100, 175, paint);

Here my code to save the images.

Bitmap toDisk = Bitmap.createBitmap(resizeImage1);
canvas.setBitmap(toDisk);
toDisk.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(new File("/mnt/sdcard/pig.jpg")));

My problem here is that I can pass the single variable only resizeImage1. I cannot pass CameraText,resize. How can I do this开发者_开发问答?


Don't you need to try to save the canvas graphic not the bitmap?

That way you can apply your modification to the image (via canvas) then save

The canvas object changes the bitmap you assigned using setBitmap and then you apply changes to the bitmap using the canvas functions. So something along this lines should be similar to what you're looking (copied from your example code)

Bitmap toDisk = Bitmap.createBitmap(resizeImage1);
canvas.setBitmap(toDisk);
canvas.drawBitmap(resize, 40, 100, null);
canvas.drawBitmap(resizeImage1, 400, 100, null);
canvas.drawText(CameraText, 100, 175, paint);
toDisk.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(new File("/mnt/sdcard/pig.jpg")));
0

精彩评论

暂无评论...
验证码 换一张
取 消