Java 如何在这些图片中添加文字
如何在这张图片中写一些文字,我会添加一些信息Java 如何在这些图片中添加文字,java,android,Java,Android,如何在这张图片中写一些文字,我会添加一些信息 YuvImage image = new YuvImage(data, ImageFormat.NV21, maxwidth, maxheight, null); Rect rectangle = new Rect(); rectangle.bottom = maxheight; rectangle.top = 0; rectangle.left = 0; rectangle.right = maxwidth; ByteArrayOutputStre
YuvImage image = new YuvImage(data, ImageFormat.NV21, maxwidth, maxheight, null);
Rect rectangle = new Rect();
rectangle.bottom = maxheight;
rectangle.top = 0;
rectangle.left = 0;
rectangle.right = maxwidth;
ByteArrayOutputStream output = new ByteArrayOutputStream();
image.compressToJpeg(rectangle, 95, output);
如果您的意思是向图像添加一些文本就是添加EXIF信息,
然后您可以查看此链接: 如果您需要在图像上绘制一些文本,那么以下内容可能会有所帮助:
将以下代码放在
image.compressToJpeg(矩形,95,输出)之后代码>
建议将此行更改为image.compressToJpeg(矩形,100,输出)代码>用于在绘制时获得更好的图像质量
// Decode the JPEG byte array from 'output' to 'Bitmap' object
Bitmap bmp = BitmapFactory.decodeByteArray(output.toByteArray(), 0, output.size());
// Use 'Canvas' to draw text ont 'Bitmap'
Canvas cv = new Canvas(bmp);
// Prepare 'Paint' for text drawing
Paint mPaint = new Paint();
mPaint.setColor( Color.RED );
mPaint.setStyle( Style.STROKE );
mPaint.setTextSize(20);
// Draw text on the 'Bitmap' image
cv.drawText("TEXT To SHOW", 10, 10, mPaint);
// Reset the stream of 'output' for output writing.
output.reset();
// Compress current 'Bitmap' to 'output' as JPEG format
bmp.compress(CompressFormat.JPEG, 95, output);
然后,您可以使用输出执行任何需要的操作。