android保存文本绘制位图到jpeg文件

时间:2015-01-21 00:05:07

标签: android bitmap save jpeg

我尝试制作一个Android应用程序 它必须包含位图到jpeg文件方法

这是我必须做的事情

1.创建BitmapDrawable对象

BitmapDrawable bitmapDrawable = (BitmapDrawable)res.getDrawable(R.drawable.my_pic);

2.创建位图对象

    Bitmap bit = bitmapDrawable.getBitmap();

3.在画布对象上创建设置位图

    canvas.drawBitmap(bit,0,0,null)

4.drawText“helloworld”在画布上

    Paint pnt = new Paint();
    pnt.setColor(Color.BLACK);
    canvas.drawText("helloworld",100,100,pnt);
    canvas.save();
    canvas.restore();

这个代码是我试图将Bitmap(或画布)保存到Jepg文件

一个。

    bit.compress(Bitmap.CompressFormat.JEPG, 100 , fileOutputStream);

但这可以保存原始图像(没有文字) 所以,我用了代码b。

    view.setDrawingCacheEnabled(true);
    Drawable drawable =getResources().getDrawable(R.drawable.my_pic);
    view.layout(0,0,drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());
    view.bulidDrawingCache(true);

    Bitmap save_bit = view.getDrawingCache();  

    save_bit.compress(Bitmap.CompressFormat.JPEG, 100, fos);

这导致nullpoint异常,并且logcat向我发送消息'查看太大而无法适应绘图缓存,需要31325840字节,只有3686400可用'

如何将文本绘制的位图保存到文件中 请给我你的意见

0 个答案:

没有答案