【问题标题】:Saving an edittext to bitmap将编辑文本保存到位图
【发布时间】:2014-07-03 21:07:52
【问题描述】:

我将我的布局保存到一个位图中,其中包含一个 ImageView 和一个 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();
        }
}

但是我保存的图像是这样的:

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

【问题讨论】:

  • 添加这一行:this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);你的 saveToImage() 方法。
  • 不幸的是,在没有键盘时也会显示闪烁的光标:(
  • @deimos1988 你的问题解决了吗?!
  • 要禁用闪烁的光标,您可以在捕获位图时使用 editText.setCursorVisible(false)

标签: android bitmap save


【解决方案1】:

要在保存位图之前移除闪烁的光标,您可以这样做

editText.setCursorVisible(false);

然后再将其设置回true

【讨论】:

    【解决方案2】:

    您只需要在开始捕获布局时同时删除underlinecursor。您可以通过以下方式删除下划线:

    yourEditText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    

    和光标:

    yourEditText.setCursorVisible(false);
    

    如果您通过以下方式禁用 saveToImage 方法中的光标会更好:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-01
      • 2013-03-16
      • 1970-01-01
      • 2015-04-06
      • 1970-01-01
      • 1970-01-01
      • 2011-05-08
      • 1970-01-01
      相关资源
      最近更新 更多