1

HI'm having an imageview having EditText on that Image. I want to create single Image of that imageview with EditText.

I tryed this,

editTextOptOneInput.buildDrawingCache();
imageViewOptOne.setImageBitmap(editTextOptOneInput.getDrawingCache());
imageViewOptOne.buildDrawingCache();
Bitmap bitmap1 = imageViewOptOne.getDrawingCache();

but chamge my image to black as my text color is black(I guess).

Akshay
  • 6,029
  • 7
  • 40
  • 59
  • Try using `myContainer.buildDrawingCache();`, instead. `myContainer` being the layout which contains both your EditText and your ImageView. Remove the other two **conflicting** `.buildDrawingCache()` **instructions**. – Phantômaxx Dec 10 '14 at 14:28
  • I'm having a relative layout with multiple `Imageview` has visibility gone. Only one `Imageview` with image, Edittext with text and another `Imageview` with delete icon is there. I don't want that delete icon in my final image, what should i do?? – Akshay Dec 10 '14 at 14:33
  • Sorry I don't get it.. – Akshay Dec 10 '14 at 14:36
  • 2
    You may use only **1** `buildDrawingCache()`, the subsequent ones will replace the previous contents. So, you better **group the EditText and the ImageView into a container** and shoot that one. OR... Instead of using an EditText, just use a **TextView**. This one can have one or more **compound** drawable **inside**. So, you may shoot the TextView only. – Phantômaxx Dec 10 '14 at 14:36

4 Answers4

2

You may use only 1 buildDrawingCache(), the subsequent ones will replace the previous contents.
So, you better group the EditText and the ImageView into a container and shoot that one.

OR...

Instead of using an EditText, just use a TextView.
This one can have one or more compound drawable inside.

So, you may shoot the TextView only.

This is a preferred solution, since it reduces the View and (possibly) the layout count.

[EDIT]

To use compound drawables simply use in xml the android:drawableLeft = "@drawable/your_drawable" (and/or drawableRight, drawableTop, drawableBottom) attribute/s of your TextView.
To set them in Java, use setCompoundDrawablesWithIntrinsicBounds(int left, int top, int right, int bottom), as found in the official docs: http://developer.android.com/reference/android/widget/TextView.html#setCompoundDrawablesWithIntrinsicBounds(int, int, int, int)

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
0

You need get drawing cache of Parent of that imageview & EditText.

parentLayout.buildDrawingCache();
Bitmap bitmap1 = parentLayout.getDrawingCache();

Where parentLayout contains imageview & EditText.

Ganesh AB
  • 4,652
  • 2
  • 18
  • 29
0

I don't understand why you need that but as I understand you should create new Bitmap object from drawing cache before set as source of ImageView

Romadro
  • 626
  • 4
  • 10
0

Reminder:

If you are capturing the result image+text from screen, the quality of the output image is certainly compromised

If you want to keep the original quality of image, you should use Canvas and Bitmap to help you

Canvas c=new Canvas();
c.setBitmap(bitmap);   // *mutable* copy of bitmap of the image for the ImageView
c.drawText(text,  x,  y,  paint);  // font size and typeface can be set through "Paint" class

bitmap.compress(CompressFormat.PNG, 100, new FileOutputStream(out)); // export output
Patrick Chan
  • 1,019
  • 10
  • 14