Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在这些图片中添加文字_Java_Android - Fatal编程技术网

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);
然后,您可以使用输出执行任何需要的操作。