2013-05-15 20 views
2

我怎麼可以在這張圖片上寫一些文字,我會添加一些信息。我怎麼可以添加一些文字到這些圖片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; 
ByteArrayOutputStream output = new ByteArrayOutputStream(); 
image.compressToJpeg(rectangle, 95, output); 

回答

2

如果你的意思是一些文本添加到圖像添加EXIF信息,
那麼你可以看看這個鏈接: Write/Geotag JPEGs (EXIF data) in Android

如果你彪平局部分文字爲的圖片上,則以下內容可能有所幫助:
將以下代碼放在image.compressToJpeg(rectangle, 95, output);之後。
建議在繪圖時將此行更改爲image.compressToJpeg(rectangle, 100, output);以獲得更好的圖像質量。

// 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); 

然後,您可以使用輸出做任何你需要的。

+0

完美的作品非常好。我需要畫一些文字。 – user2387843

相關問題