Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6699933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:45:17+00:00 2026-05-26T06:45:17+00:00

I have an simple EditText inside an Activity and I want to create a

  • 0

I have an simple EditText inside an Activity and I want to create a Bitmap Image from that EditText and content of the EditText. The Image should look same as the EditText and its content.

Here is how I want the Image should look like, though this is an EditText but I want a Bitmap which should look same as this. So, how can I achieve this? Any idea would be great.

enter image description here

This is my code,

public class EditTextPinchZoomActivity extends Activity {

    EditText editText;
    ImageView imageView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        imageView = (ImageView) findViewById(R.id.image_view);
        editText = (EditText) findViewById(R.id.edit_text);
        editText.buildDrawingCache();
    }

    public void myOnClick(View view) {

        switch (view.getId()) {
        case R.id.btn:
            imageView.setImageBitmap(editText.getDrawingCache());

            break;
        default:
            break;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:45:18+00:00Added an answer on May 26, 2026 at 6:45 am

    You can get the bitmap by building the drawing cache. This should work.

    EditText edit = (EditText)findViewById(R.id.edit);
    edit.buildDrawingCache();
    ImageView img = (ImageView)findViewById(R.id.test);
    img.setImageBitmap(edit.getDrawingCache());
    

    Lalit when you try to build the cache in the onCreate method, the drawing hasn’t happened yet so the drawingCache should have nothing. Either put the buildDrawingChache method in the onClick method. Or use the following code in onCreate.

    ViewTreeObserver vto = editText.getViewTreeObserver(); 
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 
        @Override 
        public void onGlobalLayout() {
            editText.buildDrawingCache();
            } 
    });
    

    But I think building the cache in the onClick method will be proper as the screen will be drawn by then. And other thing I remebered is, if you entering text after the onCreate, then you should build the cache after that. So try the first method.

    ViewTreeObserver

    Its a global layout listener to a view or viewgroup which keeps getting called when anyhing changes to the layout. I normally use this in cases where I need to get width and height’s of views in the onCreate method. Without this the value will always be 0 as no drawing or measuring has taken place.

    Suppose you had a requirement to keep updating your imageview of the edittext as you type, you can use this and just remove the first line where I remove the listener. The listener will be called for every character you type even when the cursor blinks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a relatively simple layout that contains an EditText . The activity itself
friends, i have a EditText on simple activity with a button. when every i
I have simple win service, that executes few tasks periodically. How should I pass
I'm trying to create a simple Android UI that consists of a EditText and
I have a simple activity with only one edittext which was set to http://
I have a simple Activity that uses a android:theme=@android:style/Theme.Dialog in the manifest. My activity
This one should be pretty simple. The use case is that I have a
I have an Activity that consists of a large scrollview (that contains EditText fields)
I have an EditText that I want to monitor KeyEvents for, and I have
I have a simple Activity with 3 EditText fields. User, Pass, Confirmation After typing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.