Jump to content
  • Advertisement
Sign in to follow this  

Scaling BufferedImage in Java

This topic is 583 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Recently I've been porting my code from Android Java to Java. Apart from a number of APIs, much of the code remain the same. And I got solutions to several APIs by checking the docs or googling. But one  Android APIs to Java still eludes me

Creating a scaled bitmap (BufferedImage) in Java

The exact (remaining) Android scaling functionality I need to port to Java is this

myBitmap  = Bitmap.createScaledBitmap( originalBitmap, 480, 800, false );

What I could find for Java is the code below (the first loads image but doesn't allow parameters to scale to different height and width and the second creates new image but doesn't scale an existing bufferedImage )

myBitmap = ImageIO.read(new File( filePath + filename ));  
myBitmap = new BufferedImage(480, 800,   BufferedImage.TYPE_INT_RGB);

//(which is not scaling an existing image)

How can I set size (w,h) parameters to scale an existing bitmap to different dimensions? I guess its out there somewhere but I'm just missing it. Couldn't find it in this doc drop-down or am I looking in the wrong place

[attachment=35871:java bitmaps.jpg]


Share this post

Link to post
Share on other sites

If it's not in the API list, you can be reasonably sure it doesn't exist for BufferedImage, IDEs for Java are typically quite good at guessing what methods you can use for a class.


Next step is usually generalizing your search (scaling image sounds like a common enough problem for someone to have posted about it), something like "java scale image" or something similar. That gives me




and a few others, that look useful, but I am sure you can find those too :)

Share this post

Link to post
Share on other sites

Yeah the first of the links you posted had the solution, thanks

I had actually come across this during my search but I didn't bother going beyond the first 2 answers because the first two had 26 upvotes between them while the third had just 4. More so at the time, I was looking at so many other SO pages

But on Reading your post I looked more closely and I found the 3rd answer was the solution. Very simple eventually. In fact it was similar and a simpler version to the one I was looking at here just before reading your post  

[attachment=35877:thumbs up.jpg]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!