Rajhrita
Rajhrita

Reputation: 105

Showing a text on the picture taken from Camera and saving it in Gallery

I want to add a text on the picture taken from device camera. So I am launching my activity once Camera intent action is fired. My question is how to show a text on the picture and once user clicks on save button the picture will be saved in device's gallery with the text.Please give some idea.

Thanks

Upvotes: 2

Views: 841

Answers (2)

Vipul
Vipul

Reputation: 28093

Following Snippet will give you some pointers

Here come your logic.

Here i am loading png file from drawable resource.You need to fetch it from directory.

If you want to make it more attractive Use Custom fonts by saving them in Assets/fonts

Don't directly hard-code Text you want to put rather load it from somewhere.

Use some different color.

I have manually set the Text Size .You should put some logic (Dont hard-code it)

In drawText i have harddoded Text height as 30.You should apply some logic to get Text Height.

Finally You have Background Bitmap save it.

ImageView imageView = (ImageView) findViewById(R.id.image);
Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.sample).copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(background);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.WHITE);
paint.setStyle(Style.FILL);
paint.setTextSize(50);
paint.setShadowLayer(2.0f, 1.0f, 1.0f, Color.BLACK);

canvas.drawText("Hello Image", (background.getWidth() - paint.measureText("Hello Image")) / 2, background.getHeight() - 30, paint);

imageView.setImageBitmap(background);

Upvotes: 1

MobileEvangelist
MobileEvangelist

Reputation: 2628

I think this post really helps you Link is here...

You should make use of FrameLayout and then add your imageView to it in this post given example how to set image just add textview with background transparent after it , FrameLayout displays it upon image and you can also position it(just write your textview in RelativeLayout )

Hope this explanation works for you...

Upvotes: 0

Related Questions