Scalable images in Java

北城以北 提交于 2019-12-11 11:27:52

问题


I anticipate using some images in my Java application. These images will be drawn onto my JPanel using g.drawImage(). The JPanel is resizable and the images should scale as the JPanel increases/decreases in size

Two questions:

  1. What image format is best for this type of desired scalable image? For instance, in this application, an image of size 100x100 may be scaled into an image of size 30x30 or 10x10 or 300x300.
  2. How can I write code to do this scaling?

回答1:


Take a look at Java: maintaining aspect ratio of JPanel background image

I'd also take a read through The Perils of Image.getScaledInstance() and I'd also have a look at java-image-scaling (I've not used it personally, but I've heard good things about it).

As to the image format. I doubt it will really make that much of difference, the quality will be determined by the quality of the original image. Try and use a large image and scale it down, rather then trying to scale a small image up.




回答2:


  1. It doesn't matter, I don't think. (If you wanted images not to get blurry when you scale them up, look into vector images).

  2. You might want to use Image.getScaledImage(int, int, int), in a listener that is called on window resize.



来源:https://stackoverflow.com/questions/12485435/scalable-images-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!