java,调整图片大小
我在java中调整图片大小时遇到问题!
我从 xml 文档中获取图片,但大多数都是横向模式! 我需要将它们调整大小/转换为纵向模式,以便它们适合我的 GUI 布局。
有没有办法做到这一点?
im having a problem with resizing pictures in java!
i get the pictures from an xml document but most of them are in landscape mode!
i need to have them resized/converted into portrait mode so they fit into my GUI layout.
is there a method for doing this??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将宽度和高度缩放相同的值以获得具有相似分辨率的图像。
但你的问题到底是什么?如何扩展或者什么?
我写这个是为了根据目标宽度和高度将高度和宽度缩放相同的值
You can scale width and height by the same value to get the image with a similar resolution.
But what you problem really is? How to scale or what?
I wrote this for scale both height and width by the same value based on the target width and height
为了将图片从横向模式转换为纵向模式而不旋转,您首先必须裁剪图片。然后,您可能需要缩小图片的尺寸。
假设您的风景图片为 500 x 300 像素,而您希望肖像图片为 150 X 250 像素。
您可以通过裁剪中心将风景图片裁剪为 180 X 300 像素。然后您可以将裁剪后的图片缩小到 150 x 250 像素。
下面是一些用于裁剪图像的 Java 代码:
image 是 java.awt.Image,toolkit 是默认的 java.awt.Toolkit。
In order to convert a picture from landscape mode to portrait mode, without rotating, you first have to crop the picture. Then, you may have to reduce the size of the picture.
Let's say your landscape picture is 500 x 300 pixels, and you want your portrait picture to be 150 X 250 pixels.
You could crop the landscape picture to 180 X 300 pixels by cropping the center. Then you can reduce the cropped picture down to 150 x 250 pixels.
Here's some Java code for cropping an image:
image is a java.awt.Image, and toolkit is the default java.awt.Toolkit.