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

这是我必须做的

1.创建BitmapDrawable对象

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

2.创建Bitmap对象

Bitmap bit = bitmapDrawable.getBitmap();

3.在canvas对象上创建set Bitmap

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可用'

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