How would I resize a Java Image so that its size would be 1000 by 1000 px. It would be cool if it's like 1-3 lines of code. Thanks!
Asked
Active
Viewed 1,107 times
-1
-
The LoC constraint is oddly funny. Anyhow. This is not a coding service. What have you tried so far? – Ingo Bürk Sep 28 '14 at 16:15
-
possible duplicate of [How can I resize an image using Java?](http://stackoverflow.com/questions/244164/how-can-i-resize-an-image-using-java) – Ingo Bürk Sep 28 '14 at 16:15
2 Answers
1
Try this. It works for me:
Image yourResizedImage = yourImage.getScaledInstance(YOUR_WIDTH, YOUR_HEIGHT, java.awt.Image.SCALE_SMOOTH) ;

tsabsch
- 2,131
- 1
- 20
- 28
-
When i try to do the Graphics.drawImage it doesent work after i rote your line of code? o.o – Oliver Sep 29 '14 at 16:22
0
BufferedImage im = new BufferedImage(1000,1000,BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g = (Graphics2D)im.getGraphics();
g.drawImage(oldImg, 0, 0, 1000, 1000, null);
At the end of this im will have the scaled image

ControlAltDel
- 33,923
- 10
- 53
- 80