生成图片2.txt

来自「、生成图片1.rar 、生成图片1.rar」· 文本 代码 · 共 44 行

TXT
44 行
字号
package image;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;
   
public class CreateImage     
{    
    public static void main(String[] args) throws Exception    
    {    
        int width = 100;    
        int height = 100;    
        String s = "你好";    
            
        File file = new File("d:/image.jpg");    

        BufferedImage bi = javax.imageio.ImageIO.read(file);
        Graphics g = bi. getGraphics();
        g.drawImage(bi,10,10, null);
        g.drawString("aaaaaaaa", 10, 20);




//        Font font = new Font("Serif", Font.BOLD, 10);    
//        BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);    
//        Graphics2D g2 = (Graphics2D)bi.getGraphics();    
//        g2.setBackground(Color.WHITE);    
//        g2.clearRect(0, 0, width, height);    
//        g2.setPaint(Color.RED);    
//            
//        FontRenderContext context = g2.getFontRenderContext();    
//        Rectangle2D bounds = font.getStringBounds(s, context);    
//        double x = (width - bounds.getWidth()) / 2;    
//        double y = (height - bounds.getHeight()) / 2;    
//        double ascent = -bounds.getY();    
//        double baseY = y + ascent;    
            
//        g2.drawString(s, (int)x, (int)baseY);    
            
        ImageIO.write(bi, "jpg", file);    
    }    
} 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?