Tayyab Husain
Tayyab Husain

Reputation: 51

want to add some text over a newly captured image in android

This is my problem:

  1. Capture an image from the camera
  2. Write some text on it
  3. save it into an app folder

the first point I have covered. help me out for the remaining two points

Thanks in advance

Upvotes: 1

Views: 968

Answers (1)

isi.kacer
isi.kacer

Reputation: 76

try this

1 - code to write text to bitmap

Bitmap bitmap = ... // your bitmap here
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint(); 
paint.setColor(Color.BLACK); 
paint.setTextSize(10); 
canvas.drawText("Some Text here", x, y, paint);

2 - code to save bitmap to storage

// Assume block needs to be inside a Try/Catch block.
String path = Environment.getExternalStorageDirectory().toString();
OutputStream fOut = null;

File file = new File(path, "File.jpg"); 
fOut = new FileOutputStream(file);

pictureBitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut); // saving the Bitmap to a file compressed as a JPEG with 85% compression rate
fOut.flush(); // Not really required
fOut.close(); // do not forget to close the stream

MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());

source : Save bitmap to location

How to write text on an image

Upvotes: 1

Related Questions