Issue
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
Solution
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;
}
Answered By - BST Kaal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.