I want to change the my name and designation which in on ImageView but not making a layout. I want to write it on image at runtime. I just want to select the image and put my name and after writing on image I want to upload on server.I am unable to write on image without making layout .
Asked
Active
Viewed 299 times
1
-
1try with use frame layout you can write name on image – Nov 30 '15 at 07:18
-
1Possible duplicate of [ANDROID -- How to display text on an image?](http://stackoverflow.com/questions/5019517/android-how-to-display-text-on-an-image) – Iamat8 Nov 30 '15 at 07:19
-
it means you want to generate image with your name address etc runtime not a layout. is it ok? – Vishal Patel Nov 30 '15 at 07:19
-
Please read the que sir ...i dont want tomake layout i had already mention . – AKMAL ANSARI Nov 30 '15 at 07:24
-
You could generate your final image directly with PHP on the server using some parameters for your script to be processed dynamically. – Samoth Nov 30 '15 at 08:19
4 Answers
0
I think you can try
Use RelativeLayout
<RelativeLayout
.....
.....>
<ImageView
..
../>
<Other layout like TextView>
</RelativeLayout>
And then Take screenshot
0
You can create a class extends Imageview,
and override onDraw method,
in that
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(Color.WHITE);
paint.setStyle(Style.FILL);
canvas.drawPaint(paint);
paint.setColor(Color.BLACK);
paint.setTextSize(20);
canvas.drawText("Some Text", 10, 25, paint);
}
put this method.

RBK
- 2,481
- 2
- 30
- 52
0
Try this one it return you bitmap with your text i just put code it may help you.
private BitmapDrawable writeTextOnDrawable(int drawableId, String text) {
Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId)
.copy(Bitmap.Config.ARGB_8888, true);
Typeface tf = Typeface.create("Helvetica", Typeface.BOLD);
Paint paint = new Paint();
paint.setStyle(Style.FILL);
paint.setColor(Color.WHITE);
paint.setTypeface(tf);
paint.setTextAlign(Align.CENTER);
paint.setTextSize(convertToPixels(mContext, 11));
Rect textRect = new Rect();
paint.getTextBounds(text, 0, text.length(), textRect);
Canvas canvas = new Canvas(bm);
//If the text is bigger than the canvas , reduce the font size
if(textRect.width() >= (canvas.getWidth() - 4)) //the padding on either sides is considered as 4, so as to appropriately fit in the text
paint.setTextSize(convertToPixels(mContext, 7)); //Scaling needs to be used for different dpi's
//Calculate the positions
int xPos = (canvas.getWidth() / 2) - 2; //-2 is for regulating the x position offset
//"- ((paint.descent() + paint.ascent()) / 2)" is the distance from the baseline to the center.
int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2)) ;
canvas.drawText(text, xPos, yPos, paint);
return new BitmapDrawable(getResources(), bm);
}
public static int convertToPixels(Context context, int nDP)
{
final float conversionScale = context.getResources().getDisplayMetrics().density;
return (int) ((nDP * conversionScale) + 0.5f) ;
}

Vishal Patel
- 2,931
- 3
- 24
- 60
-
public void onClick(View arg0) { // TODO Auto-generated method stub writeTextOnDrawable(R.drawable.testcard, "ABCD"); } it is not working when i am calling it on click of a button nothing happens – AKMAL ANSARI Nov 30 '15 at 08:49
-
-
There is not any error, nothing reflecting on Image View. Already put setonClickListener on button. – AKMAL ANSARI Nov 30 '15 at 09:09
-
its work for me complete chek your image not white .. iv.setImageBitmap(writeTextOnDrawable(R.mipmap.ic_launcher, "yoyoyoyo").getBitmap()); – Vishal Patel Nov 30 '15 at 09:24
-
-
Nope, I think Samoth suggestion is correct for me..."You could generate your final image directly with PHP on the server using some parameters for your script to be processed dynamically" – AKMAL ANSARI Nov 30 '15 at 13:56
0
If you do not want to create a layout then you can use a TextView and set the selected image to its background and write the text by setting its gravity else you can override the onDraw method of ImageView.

NoDataDumpNoContribution
- 10,591
- 9
- 64
- 104

Pooja
- 31
- 5
-
To me it looks like an attempt to answer the question. – NoDataDumpNoContribution Nov 30 '15 at 08:56