Reputation: 6142
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).
Upvotes: 1
Views: 707
Reputation: 38098
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)
Upvotes: 2
Reputation: 1029
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
Upvotes: 0
Reputation: 626
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
Upvotes: 0
Reputation: 4698
You need get drawing cache of Parent of that imageview & EditText.
parentLayout.buildDrawingCache();
Bitmap bitmap1 = parentLayout.getDrawingCache();
Where parentLayout contains imageview & EditText.
Upvotes: 0