Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6472117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:18:20+00:00 2026-05-25T06:18:20+00:00

I read in a Game tutorial how to load images, and they did this:

  • 0

I read in a Game tutorial how to load images, and they did this:

public Image loadImage(... String ref ...) {
  ...
    URL url = this.getClass().getClassLoader().getResource(ref);
    BufferedImage source = ImageIO.read(url);
    GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    Image image = gc.createCompatibleImage(source.getWidth(), source.getHeight(), Transparency.BITMASK);

    image.getGraphics().drawImage(source, 0, 0, null);
    return image;
}

This is absolutely not the best way in terms of usability and clarity (= nobody could find this way just by using their healthy brains). Why is it that complicated? Does it have to be? Why can’t image loading be as easy as that:

BufferedImage image = ImageIO.read(ref);

Is there an easier way if you just want to load an image in a way that Java automatically does all the default “stuff” it has to do? Is there maybe a reason the author of that code chose another way, because he wanted to achieve some non-default behaviour? When writing an answer please understand that I am looking for an easy way to solve the problem of image loading and also the ability and understanding to apply more complicated means if nessesary.

edit:
Also both answers are good presentations of their respective authors oppinions, until now I can’t accept one answer, because no answer shows a simpler way and/or explains what exactly is happening.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:18:20+00:00Added an answer on May 25, 2026 at 6:18 am

    Well, a lot more is happening here. An url is opened, the url contents are loaded in a buffer. The image is loaded from the buffer. It is converted to a device compatible bitmap.

    I think 4 lines of code to do all this is pretty awesome. I don’t want to sound old, but when I wanted to draw a bitmap in Ye Olde C++ in DOS, I first had to visit the library to get a book about various bitmap formats, then write about 10.000 lines of code to support only a few of them… And then I just got a bitmap (which is about the easiest of images) on a local computer. No jpg, no networking, let alone internet, and certainly not cross platform.

    If you need a lot of images to be loaded from the internet, feel free to put it in a function, like you did here. It doesn’t seem weird to me that these quite unrelated functionalities aren’t by default grouped in a single statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just read this tutorial. It's about game development, and it basically says that
I'm programming a Bomberman in Java following a tutorial (this is my first game).
I have this game controller pad and I need to read it's commands for
I know this is game design related, but I have read the StackOverflow FAQ
I want to get started at game development. I have read a lot of
Read on before you say this is a duplicate, it's not. (as far as
I read this PHP RegEx page , but either I'm missing something, misreading something,
I read the Git manual, FAQ, Git - SVN crash course, etc. and they
I read in this article that a company has created a software capable of
I've been starting to get into game development; I've done some tutorials and read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.