import java.awt.*;
import java.awt.image.BaseMultiResolutionImage;
import java.awt.image.BufferedImage;

public class CustomCursorResolution {
    public static void main(String[] args)
    {
        Dimension bestCursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(32, 32);
        assert bestCursorSize.width == bestCursorSize.height; // effectively 64 for systems with (also) a HiDPI screen
        final int cursorSize = bestCursorSize.width;

        // construct blue diagonal cross with a frame, in two resolutions
        BufferedImage bufferedImageLowRes = createCursorImage(cursorSize / 2);
        BufferedImage bufferedImageHighRes = createCursorImage(cursorSize);

        Image image;
        image = new BaseMultiResolutionImage(bufferedImageLowRes, bufferedImageHighRes); // triggers bug
        //image = bufferedImageHighRes; // workaround avoiding low res alpha mask

        Frame frame = new Frame();
        Cursor cursor;
        cursor = Toolkit.getDefaultToolkit().createCustomCursor(
                image, new Point(cursorSize / 2, cursorSize / 2), null);
        frame.setCursor(cursor);
        frame.setSize(new Dimension(500, 500));
        frame.setBackground(Color.LIGHT_GRAY);
        frame.setVisible(true);
    }

    private static BufferedImage createCursorImage(int cursorSize) {
        BufferedImage bufferedImage = new BufferedImage(cursorSize, cursorSize, BufferedImage.TYPE_INT_ARGB);
        Graphics2D bg = bufferedImage.createGraphics();
        bg.setBackground(new Color(1.0f, 1.0f, 1.0f, 0.0f));
        bg.clearRect(0, 0, cursorSize, cursorSize);
        bg.setColor(Color.WHITE);
        bg.fillRect(0, 0, cursorSize / 2, cursorSize); // white background in the left half, transparent background in right half
        bg.setColor(Color.BLUE);
        bg.drawRect(0, 0, cursorSize - 1, cursorSize - 1);
        bg.setStroke(new BasicStroke(2));
        bg.drawLine(0, 0, cursorSize, cursorSize);
        bg.drawLine(0, cursorSize, cursorSize, 0);
        return bufferedImage;
    }
}
