将编辑文本保存到位图 [英] Saving an edittext to bitmap

查看:115
本文介绍了将编辑文本保存到位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将布局保存到一个位图,其中包含一个ImageView和一个EditText.

I am saving my layout to a bitmap, which contains an ImageView and an EditText.

我正在使用以下代码:

public void saveToImage(RelativeLayout content){

    Bitmap bitmap = Bitmap.createBitmap(content.getWidth(), content.getHeight(), Bitmap.Config.ARGB_8888);

    Canvas c = new Canvas(bitmap);
    content.layout(0, 0, content.getLayoutParams().width, content.getLayoutParams().height);
    content.draw(c);


    try{
        File file,f = null;                    
        if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) 
            {  
                 file =new File(android.os.Environment.getExternalStorageDirectory(),"TTImages_cache");
                 if(!file.exists())
                {
                  file.mkdirs();

                 } 
                 f = new File(file.getAbsolutePath()+file.separator+ "filename"+".png");
            }
          FileOutputStream ostream = new FileOutputStream(f);                                   
          bitmap.compress(CompressFormat.PNG, 10, ostream);
          ostream.close();

         } 


         catch (Exception e){
         e.printStackTrace();
        }
}

但是我保存的图像如下所示:

However the image I save looks like this:

在保存位图时,我想删除带下划线的文本和edittext中的文本光标.有可能吗?

I would like to remove the underlined text and the text cursor in the edittext when saving the bitmap. Is that possible?

推荐答案

开始捕获布局时,只需删除underlinecursor.您可以通过以下方式删除下划线:

You just need to remove both underline and cursor when you start capturing the layout. You can remove the underline by:

yourEditText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

和光标通过:

yourEditText.setCursorVisible(false);

如果通过以下方法禁用saveToImage方法中的光标,那就更好了:

It would be better if you disable the cursor inside your saveToImage method by:

public void saveToImage(RelativeLayout content){
    yourEditText.setCursorVisible(false);
       ....
       ....
    //your code for saving the layout
}

,然后将布局保存在内存中后,只需重置yourEditText以显示光标即可.

and then after the layout is saved in the memory, just reset the yourEditText to show the cursor.

public void saveToImage(RelativeLayout content){
    //your code for saving the layout
       ....
       ....
    yourEditText.setCursorVisible(true);
}

这篇关于将编辑文本保存到位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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