Reputation: 3033
I have an ImageView
and an EditText
placed over the ImageView
. I want the written text on EditText
to be a part of ImageView
as a single image (bitmap) as it is being shown while being written. I have tried using canvas.drawText(...)
but couldn't get the exact look while it was being written.
Update:: SOLVED ... ANSWER BELOW
Upvotes: 0
Views: 769
Reputation: 3033
Here is how I solved this. If the image I want is like :
Then the solution will be :
/**
* Merging Two Images into One Image.
* @param baseImage Bitmap as Lower Image , Image to be appeared underneath.
* @param headerImage Bitmap as Upper Image, Image to be appeared upon the lower image.
* @return finalImage Bitmap as bytes having both images merged.
*/
public static byte[] mergeImages(Bitmap baseImage, Bitmap headerImage, Bitmap footerImage ) {
Bitmap finalImage = Bitmap.createBitmap(baseImage.getWidth(), baseImage.getHeight(), baseImage.getConfig());
Canvas canvas = new Canvas(finalImage);
canvas.drawBitmap(baseImage, new Matrix(), null);
if(headerImage != null){
canvas.drawBitmap(headerImage, new Matrix(), null);
}
if(footerImage != null){
Matrix matrix = new Matrix();
matrix.setTranslate(0, baseImage.getHeight() - footerImage.getHeight());
canvas.drawBitmap(footerImage, matrix, null);
}
ByteArrayOutputStream stream = new ByteArrayOutputStream();
finalImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] bytes = stream.toByteArray();
return bytes;
}
Upvotes: 2
Reputation: 1690
Once I made something similar you are trying to. I used Textview to do that. I set it's background resource and text seperately.
//for image
int pos = imageList[mPosition];//integer array keeps r.mipmap.x
tvShare.setBackgroundResource(pos);
//for text you can change settings
tvShare.setTypeface(null, Typeface.NORMAL);
tvShare.setGravity(Gravity.CENTER);
//how I converted it to bitmap
Bitmap image;
image = loadBitmapFromView(tvShare,getApplicationContext());
Upvotes: 0