简体   繁体   English

用Java缩放图像/图标

[英]Scaling images/icons in Java

A project I am working on needs to be resized when the monitor resolution changes. 当显示器分辨率更改时,需要调整我正在处理的项目的大小。 Due to legacy code and other issues, we do it by using a custom library which scales all the components to the appropriate sizes when the resolution changes. 由于遗留代码和其他问题,我们通过使用自定义库来实现此目的,该库可在分辨率更改时将所有组件缩放到适当的大小。

However, when we scale some of the images/icons used in the project, they become blurry/fuzzy/aliased. 但是,当我们缩放项目中使用的某些图像/图标时,它们会变得模糊/模糊/混叠。 Mostly because they are all raster gifs. 主要是因为它们都是光栅gif。

One solution we thought might work to mitigate this issue is to either use Vector images and convert them into raster images on the fly (and cache them for performance improvements). 我们认为可以缓解此问题的一种解决方案是使用Vector图像并将其即时转换为光栅图像(并对其进行缓存以提高性能)。

What do you all think? 你们怎么想 Would this be a good way to go? 这是个好方法吗? Or are there better alternatives to my chosen method? 还是我选择的方法有更好的选择?

If this is a better way, then can someone give pointers to how to go about the svg conversion to say jpg or png(preferably). 如果这是更好的方法,那么有人可以指出如何进行svg转换,比如说jpg或png(最好)。 Available (and commercially usable) libraries? 可用(可商业使用)的库?

Thanks 谢谢

The algo's in java are pretty good. Java中的算法非常好。 The fundamental problem sounds as if your original images/icons are already too small so scaling them up leaves you with artefacts. 根本的问题听起来好像您的原始图像/图标已经太小,因此按比例放大会留下人为因素。 A real simple approach is to have the images sent along with the app to be at the larger size and only scale down. 真正简单的方法是使与应用程序一起发送的图像具有更大的尺寸,并且仅按比例缩小。 I would say a policy on images sizes (pixels height and width) is necessary as you seem to indicate that only some have problems. 我想说,关于图像尺寸(像素高度和宽度)的政策是必要的,因为您似乎表明只有其中一些存在问题。

Of course if you can go for vector graphics, you can scale infinitely and this may be a better long term investments depending upon your application and the likely hood of needing to support large output formats (not just screens but printing). 当然,如果可以使用矢量图形,则可以无限缩放,这可能是更好的长期投资,具体取决于您的应用程序以及可能需要支持大输出格式(不仅是屏幕,而且是打印)的方法。 It may well be fairly complex to approach things this way. 这样处理事情可能很复杂。 (More information would be needed to help you further with the points in this para.) (需要更多信息来帮助您进一步了解此段中的要点。)

蜡染可以将svgs转换为png或jpegs

The icons in the Metal (cross-platform) PL&F are drawn into a buffered image, in order to blend in with whatever machine it happens to find itself running on. 金属(跨平台)PL&F中的图标被绘制到缓冲图像中,以便与碰巧发现正在运行的任何机器融合。 It's a fast technique, doesn't add dependencies and there's no need to learn any extra APIs (or languages!). 这是一种快速的技术,无需添加依赖项,也无需学习任何其他API(或语言!)。 See src.zip in your Sun JDK. 请参见Sun JDK中的src.zip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM