1

I have the coordinates and I would like to draw a line or rectangular on a jpg image which is saved in my android device and then save the new file.
Is it possible? I am trying to us ImageIO but it isn't available in android or something goes wrong and it isn't acceptable?
Any idea or code?

Michael
  • 32,527
  • 49
  • 210
  • 370
Theojim
  • 103
  • 3
  • 8
  • Yes, it's possible, with the help of the [canvas object](http://developer.android.com/reference/android/graphics/Canvas.html). – Phantômaxx May 07 '15 at 14:52

1 Answers1

0

This is how I was able to draw a green box on an existing JPEG.

Bitmap workingBitmap = BitmapFactory.decodeFile( mFullFilePath );
Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);

// bitmap needs to be mutable
Canvas tmpCanvas = new Canvas(mutableBitmap);

// setup paint parameters
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth( 5 );
paint.setColor(Color.GREEN);

// Rect object was passed; use below to test
// Rect rect = new Rect( 0, 0, 10, 10 );
tmpCanvas.drawRect(rect, paint);

// write the updated file out as a JPG
writeExternalToCache( mutableBitmap, mFullFilePath );

see also:

Community
  • 1
  • 1
RobinM
  • 141
  • 2
  • 6