• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Quick Question about Images

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I was wondering wether it is more computationally expensive to say draw an image 200 by 200...

g.drawImage(image,x,y,this);

than it is to just draw a rectangle / polygon of the same size...

g.setColor(Color.yellow);
g.fillRect(x,y,200,200);

I am doing an animation, and would like to know if there is any difference, I guessed drawing an image would be more costly, but I'm not sure.

Thanks for any help.
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not an expert at graphics per se, but I understand a bit. I believe that drawing an actual in-memory image via drawImage() is more efficient (i.e. faster) than drawing shapes yourself (e.g. fillRect(), drawLine(), etc). In either case, your app will need to draw in image to the screen, but when you use fillRect(), etc, it also needs to perform the calculations and actually create the image.

In the example you give, the difference would probably be unnoticeable, but I suspect you were just providing a simplistic example.

If you're talking about persisting the images, though, then storing the image itself would generally (but not always) be more expensive than storing the instructions to render the image. Take your example. To store that particular image, depending on your file format, you'd have to save out every byte that makes up the 200x200 yellow square (although of course, formats like GIF and PNG dramatically help out). To save out the instructions, you'd simply need to save something that says to draw a 200x200 yellow rectangle. That's why "vector" graphics (e.g. that describe the geometric shapes to be drawn) often result in much more compact file sizes than "raster" graphics (e.g. that describe how each pixel in the image must be drawn).

But back to your question... at the point of doing your animation, you'll already have everything in memory that you need to draw the image. So doing the calculations over and over again is just a waste of cycles. The one caveat, of course, is that I am assuming that the frames of your animation are not going to change.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We had some discussion about performance recently. Here.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I couldn't get that link to work, is that page still available?

Thanks
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The URL was misspelt. Sorry. Try Here.
 
passwords must contain 14 characters, a number, punctuation, a small bird, a bit of cheese and a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic