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?
Asked
Active
Viewed 1,153 times
1
-
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 Answers
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: