What causes poor image quality in Java JLabel icons?

后端 未结 3 1474
渐次进展
渐次进展 2021-01-17 22:06

Java JLabel icons are displaying with distorted pixels in JFrame. This is happening consistently with different png images (all 32x32). I am not sc

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-17 22:38

    You may think you're displaying the images at 32x32 size, but your example of the tiled images says that's not so. You have a 9x2 grid of icons, which should be 288x64 pixels, but in your sample image the grid is 302x66.

    If you carefully examine your tiled image, you can see that the individual tiles are being displayed 34px wide - see the magenta border that extends from 32px to 66px. (Note, some of the tiles are displayed 33px wide; it appears to be 33, 34, 34, 33, 34...)

    In order to stretch the tiles to the wider width, certain columns are being doubled (red borders) and this creates the visual glitches you are seeing.

    Have you tried fixing the size of the JLabel instead of allowing it to size based on its contents?

提交回复
热议问题