Java bitmap font: blitting 1-bit image with different colors

后端 未结 2 1588
长发绾君心
长发绾君心 2021-01-18 10:28

I\'d like to implement a simple bitmap font drawing in Java AWT-based application. Application draws on a Graphics object, where I\'d like to implement a simple

2条回答
  •  无人及你
    2021-01-18 11:19

    You might turn each bitmap into a Shape (or many of them) and draw the Shape. See Smoothing a jagged path for the process of gaining the Shape.

    E.G.

    500+ FPS?!?

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.awt.geom.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import java.util.Random;
    
    /* Gain the outline of an image for further processing. */
    class ImageShape {
    
        private BufferedImage image;
    
        private BufferedImage ImageShape;
        private Area areaOutline = null;
        private JLabel labelOutline;
    
        private JLabel output;
        private BufferedImage anim;
        private Random random = new Random();
        private int count = 0;
        private long time = System.currentTimeMillis();
        private String rate = "";
    
        public ImageShape(BufferedImage image) {
            this.image = image;
        }
    
        public void drawOutline() {
            if (areaOutline!=null) {
                Graphics2D g = ImageShape.createGraphics();
                g.setColor(Color.WHITE);
                g.fillRect(0,0,ImageShape.getWidth(),ImageShape.getHeight());
    
                g.setColor(Color.RED);
                g.setClip(areaOutline);
                g.fillRect(0,0,ImageShape.getWidth(),ImageShape.getHeight());
                g.setColor(Color.BLACK);
                g.setClip(null);
                g.draw(areaOutline);
    
                g.dispose();
            }
        }
    
        public Area getOutline(Color target, BufferedImage bi) {
            // construct the GeneralPath
            GeneralPath gp = new GeneralPath();
    
            boolean cont = false;
            int targetRGB = target.getRGB();
            for (int xx=0; xx

    I have to figure there is a factor of ten error in the FPS count on the top left of the blue image though. 50 FPS I could believe, but 500 FPS seems ..wrong.

提交回复
热议问题