How does java export a picture and splice it into a picture file
This article mainly explains the "java how to export a picture and splice it to a picture file", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "java how to export a picture and splice it into a picture file"!
Public static void test2 () {
Try {
/ / read the first picture
/ / File fileOne = new File ("D:qq.jpg")
/ / BufferedImage ImageOne = ImageIO.read (fileOne)
/ / int width = ImageOne.getWidth (); / / Picture width
/ / int height = ImageOne.getHeight (); / / Picture height
/ / do the same for the second picture
File fileTwo = new File ("D:qq.jpg")
BufferedImage ImageTwo = ImageIO.read (fileTwo)
Int width = ImageTwo.getWidth (); / / Picture width
Int height = ImageTwo.getHeight (); / / Picture height
Int height2 = 20
BufferedImage ImageOne = new BufferedImage (width, height2
BufferedImage.TYPE_4BYTE_ABGR)
/ / ImageOne.get
Graphics g = ImageOne.getGraphics (); / /
G.fillRect (0,0, width, height)
G.setColor (Color.blue)
Font mFont = new Font (Song style, Font.PLAIN, 12)
G.setFont (mFont)
String text = "add text test"
G.drawString (text, 0,10)
/ / read RGB from the picture
Int [] ImageArrayOne = new int [width * height2]
ImageArrayOne = ImageOne.getRGB (0,0, width, height2
ImageArrayOne, 0, width)
Int [] ImageArrayTwo = new int [width * height]
ImageArrayTwo = ImageTwo.getRGB (0,0, width, height, ImageArrayTwo
0, width)
/ / generate a new picture
BufferedImage ImageNew = new BufferedImage (width, height + height2
BufferedImage.TYPE_INT_RGB)
ImageNew.setRGB (0, 0, width, height2, ImageArrayOne, 0, width); / / set the RGB of the upper part
/ / ImageNew.setRGB (width,0,width,height,ImageArrayTwo,0,width); / / set the RGB in the right half
ImageNew.setRGB (0, height2, width, height, ImageArrayTwo, 0, width); / / set the RGB of the lower part
File outFile = new File ("d:qq2.jpg")
ImageIO.write (ImageNew, "jpg", outFile); / / write pictures
} catch (Exception e) {
E.printStackTrace ()
}
}
Thank you for your reading, the above is the content of "java how to export a picture and splice it to a picture file". After the study of this article, I believe you have a deeper understanding of how java exports a picture and splice it to a picture file, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!