如何保存在画布上的图像和文字 [英] how to save image and text on canvas

查看:114
本文介绍了如何保存在画布上的图像和文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了帆布绘制图像在画布上我也借鉴一些文本

画布。这两个东西图片和文字,现在独立。我想,当我

绘制文本应该b打印图像。我可以保存图片和文字也就是现在的

图片,我想送形象,在另一个活动的文字。


这里是我的code:

  @覆盖

  保护无效的OnDraw(帆布油画){

   位图B = BitmapFactory.de codeResource(getResources(),R.drawable.ic);

   canvas.drawBitmap(二,10,10,NULL);

画布的drawText(你好,这是我的形象,10,10,NULL);

   }
 

解决方案

@sachit。大家知道在现实生活中,Canvas是唯一一刷,你可以用它来绘制在纸上。这里的文件是你的形象本身。

所以不要担心。只需发送位图B,也就是现在你的文字图像。

和发送可以转换b,来的ByteArray 像

  ByteArrayOutputStream流=新ByteArrayOutputStream();
            b.com preSS(Bitmap.Com pressFormat.JPEG,90,流);
        ByteArray中的字节数组= stream.toByteArray();
 

现在,你可以发送的字节数组到另一个活动.. 干杯......

i have made a canvas and draw an image on canvas i have also draw some text on

canvas. both the things image and text are now independent. i want that when i

draw text it should b printed on image. and i can save the image and text which is now

on image and i want to send image with text in another activity.


here is my code:

 @Override

  protected Void onDraw(Canvas canvas) {

   Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.ic);

   canvas.drawBitmap(b,10,10,null);

canvas,drawText("hello this is my image",10,10,null);

   }

解决方案

@sachit. As you know in a real life, the Canvas is only a brush, that you can use to draw the on the paper. Here the paper is your image itself.

So don't worry. Just send the Bitmap b, which is now the image with your text.

And for sending you can convert the b to bytearray like

ByteArrayOutputStream stream = new ByteArrayOutputStream();
            b.compress(Bitmap.CompressFormat.JPEG, 90, stream);
        ByteArray byteArray = stream.toByteArray();

Now you can send the byteArray to another activity.. Cheers.......

这篇关于如何保存在画布上的图像和文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆