我有坐标,我想在jpg映像上绘制一条线或矩形,该图像保存在我的android设备中,然后保存新文件。
是否可以?我正在尝试使用ImageIO
,但它在Android中不可用,或者出现问题,也不可接受?
有什么想法或代码吗?
这就是我能够在现有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 );
另请参见:
- https://stackoverflow.com/a/13119762/3474698
- https://stackoverflow.com/a/8801391/3474698