Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (428)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Automatic Image Question  (Read 3341 times)
0 Members and 1 Guest are viewing this topic.
Offline Steve

Junior Newbie




I love YaBB 1G - SP1!


« Posted 2002-10-19 06:48:17 »

Hello,

 Does anyone know how to actually create one of those automatic images? I have searched through the archives but couldn't find any specific examples.  I am currently using Toolkit.createImage() .  But how do I actually get the loaded image into my BufferedImage that I get from the createCompatibleImage method?  I tried getting the Graphics2D from the BufferedImage and drawing the loaded image to it but it didn't work(no errors just no Image).

Thanks,
Steve
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #1 - Posted 2002-10-19 07:37:27 »

I prefer to call those images "accelerated images" instead of "automatic". The full term would be "images, which may be accelerated under the hood".

Currently 2D may accelerate images returned
by the following methods:
- Component.createImage(w,h)  - opaque image
- Component.createImage(w, h, Transparency.BITMASK); - 1-bit transparent image
- GraphicsConfiguration.createCompatibleImage(w, h) - opaque
- GraphicsConfiguration.createCompatibleImage(w, h, BITMASK) - 1-bit transparent
- Toolkit.getImage(filename)/createImage - image files loaded using Tookit image loading mechanism

You don't need to copy the image returned by these methods to other images to 'accelerate' them, just use them, i.e. either render to them:
Image image = createImage(w, h);
Graphics g = image.getGraphics();
g.fillRect(0, 0, 100, 100);
// etc

or just copy them to the screen or other image.

I'm not sure why rendering an image to another image didn't work for you, please provide more details. Which of the Toolkit.createImage did you use?


Offline Steve

Junior Newbie




I love YaBB 1G - SP1!


« Reply #2 - Posted 2002-10-19 15:38:47 »

Hello,

 Thanks for the info. I was getting rather confused on how to take advantage of hardware and somehow got it in my mind that by default all rendering would be in software. The archived posts I read kept talking about that createCompatibleImage method. So I should be okay by just using the toolkit?  

following is the code I am using and still cannot draw to the buffered image can anyone see what I am doing wrong? (Although I don't really need to do it anyway)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
import java.awt.geom.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.*;


public class test implements ImageObserver
{

      private Image _image;
      private int _intImageCount;
     
      public void start()
      {
                  Frame f = new Frame();
                  f.setIgnoreRepaint(true);
                  f.setUndecorated(true);
                  f.setBackground(Color.BLACK);
                  GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(f);
                  f.createBufferStrategy(2);
                  BufferStrategy buffer = f.getBufferStrategy();
                  loadImage();
                  int frames = 0;
                  long lStartRenderingTime = System.currentTimeMillis();
                  while(frames < 2000)
                  {
                        Graphics2D graphics = (Graphics2D) buffer.getDrawGraphics();
                        clear(graphics);
                        AffineTransform at = new AffineTransform();
                        graphics.drawImage(_image,at,f);
                        buffer.show();
                        graphics.dispose();
                        frames++;
                  }
                  long lEndRenderingTime = System.currentTimeMillis();
                  GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(null);
                  f.dispose();
                 
                  System.out.println("Rendering Loop Time --> " + (lEndRenderingTime - lStartRenderingTime));
                  System.out.println("Frames --> " + frames);
                  System.out.println("FPS --> " + (1000 / ((lEndRenderingTime - lStartRenderingTime) / frames)) );
      }
     
      protected void clear(Graphics2D graphics)
      {
            graphics.setColor(Color.BLACK);
        graphics.setClip(0,0,1024,768);
        graphics.fillRect(0,0,1024,768);
      }
     
      public void loadImage()
      {
            Image image = Toolkit.getDefaultToolkit().createImage("c:\\corsairImages\\Corsair.png");
            while(image.getHeight(null) == -1 && image.getWidth(null) == -1)
            {
                  //Just Wait
           }
            //_image = image;
           _image = createCompatibleImage(image);
            _intImageCount++;
      }
     
      private Image createCompatibleImage(Image loadedImage)
      {
            GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
            BufferedImage image = gc.createCompatibleImage(loadedImage.getWidth(null),loadedImage.getHeight(null),Transparency.BITMASK);
            image.createGraphics().drawImage(loadedImage,new AffineTransform(),this);
            return image;
      }
     
      public static void main(String args[])
      {
            test t = new test();
            t.start();
      }
     
      public boolean imageUpdate(Image img,int infoflags,int x,int y,int width,int height)
      {
            int intResult = infoflags & ImageObserver.ALLBITS;
            if(intResult == ImageObserver.ALLBITS)
                  System.out.println("Buffered Image Loaded");
            else
                  System.out.println("image loading...........");
            return true;
      }

}
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #3 - Posted 2002-10-20 08:07:46 »

It looks like the problem is in the way you're reading the image. Your code seem to assume that the image is loaded when the width and height of the image are not -1's. That may not be true, so you're basically rendering an empty (that is, transparent) image to the BufferedImage.

You actually should use ImageTracker class to make sure your image is fully read before using it.

Or, as a shortcut, some people use swing's ImageIcon class:
ImageIcon icon = new ImageIcon(myImageFile); // this construcror makes sure the image is fully read
Image image = icon.getImage();

Also, you don't actually need to copy the image you've read into another image in order to use it. It'd be automatically accelerated for you when you copy it to the screen/backbuffer at least two times.
Offline TheAnalogKid

JGO Coder


Projects: 2



« Reply #4 - Posted 2002-10-21 16:30:57 »

Question in the same way:

Is it possible to know if an image is accelerated via a BufferedImage or Image?  VolatileImage provides ImageCapabilities about that but what about other image types?

Thanks.

Offline Steve

Junior Newbie




I love YaBB 1G - SP1!


« Reply #5 - Posted 2002-10-21 19:57:45 »

Hello,

 Thanks again for the info. When I used ImageIcon then the above code worked fine.


,
Steve
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #6 - Posted 2002-10-22 04:32:17 »

TheAnalogKid: no, there is no wayto find out if an image is accelerated (BufferedImage, or Image).

The acceleration for the images other than Volatile is supposed to be hidden, or transparent to the user.
Offline TheAnalogKid

JGO Coder


Projects: 2



« Reply #7 - Posted 2002-10-22 13:24:14 »

Thanks for your answer trembovetski!

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (79 views)
2014-04-15 18:08:23

BurntPizza (71 views)
2014-04-15 03:46:01

UprightPath (82 views)
2014-04-14 17:39:50

UprightPath (66 views)
2014-04-14 17:35:47

Porlus (82 views)
2014-04-14 15:48:38

tom_mai78101 (106 views)
2014-04-10 04:04:31

BurntPizza (166 views)
2014-04-08 23:06:04

tom_mai78101 (262 views)
2014-04-05 13:34:39

trollwarrior1 (212 views)
2014-04-04 12:06:45

CJLetsGame (221 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!