DrawImage and ImageObserver

I'm trying to implement Servlet to render images from my local drive to Web-clients.
I faced the strange problem I can't solve by myself.
I'm creating BufferedImage of certain size (not very big one).
Then I'm filling it's background and drawing the oval on it.
After that I'm rendering the image loaded from the file by doing drawImage(img,0,0,width,height,null);
After that I'm encoding it into JPEG and sending back to client.
The strange thing that on clients side I see the result of filling background and drawing the oval for some of Servlet instances. I mean that if I have just one of my servlets on page or I'm calling this servlet right from Browsers address string - I see my picture. But having two servlets on page I'm getting only one of them fully rendered, other one is just showing me the oval.
It looks like drawImage() can not complete drawing of second image because it is busy with drawing the first one.
I tried to use ImageObserver as mentioned in may articles. It doesn't seem to make any big difference. I tried to implement ImageObserver.UpdateImage inside my Applet with checking infoflags. I tried to use instance of Frame to do this job for me. Neither of these approaches made any better to results I'm getting.
So the question is - how is it supposed to work?
Where is that wise article which would tell me HOW to deal with this thig properly ?
Any ideas will be appriciated!

I've been doing some more experiments around this issue since I started this topic.
I've discovered that my Servlet is existing as just one SINGLE instance for all the request it processes. So far my udateImage() implemeted within Servlet has no chance to recognize which image is it called for. As result I see only the very last picture on my page (as I discribed before).
So far my new question is - HOW to say Tomcat (or whoever is in charge of that) to instatinate new Servlet object each time it's requred ?
Meanwhile I tried to avoid this issue by implemeting other class whic is being instantinated BY Servlet for each picture requested. First problem with it was Garbage Collector. It obviously didn't know that new instantinated object is still waiting for news from someone else being ImageObserver so Garbage Collector simply dropped it when the scope "}" created it was over.
I scratched my head for a minute and said - "Not a problem!". I was thinking that I can actualy wait until my new object have all its job done. So I placed while(blah-blah-blah) {wait(10)} before the end of processing my request.
Here was my next revelation!
It appears that for just three pictures I have on my page, each one supposed to be provided by the same Servlet... for ONE of THREE request it NEVER reaches updateImage() with infoflags==ImageObserver.ALLBITS !!!
WHY WHY WHY WHY WOULD IT BE THAT WEIRD ?!!!
I've started to damn the moment when I first time decided to provide resized images by my own Servlet! It seemed to be so simpl to drawImage() into offscreen buffer and send it back jpeg-encoded... Now I've already constructed a THREE-PAGES-LONG PIECE-OF-SHIT-CODE with is already more complicated then windows-messages processor for regular dialog box, BUT it still doesn't flipping work!
WHERE IS THE LIGHT IN THIS JAVA-MAD-DARKNESS ?!

Similar Messages

  • DrawImage() and multiple classes

    First I should start by saying I am VERY new to Java. I have written a program that uses multiple classes, and i would like to place      boolean b = g.drawImage(cardPics,x2,yPos,50,75),this); in my class. I have passed Graphics g from paint. I am able to use g.drawString, etc, but when I try to drawImage, it will not even compile. I CAN use
    boolean b = g.drawImage(cardPics[i],x2,yPos,50,75),this); in paint outside of the classes, so I believe I have the image array set up right.
    This is what the compilers reads:
    cannot resolve symbol
         boolean b =g.drawImage(cardPics[i],x2,yPos,50,75),this);
    (The symbol that it is referring to is the period between g and drawImage)
    Any help is greatly appreciated.
    Thankyou
    Apryl

    Actually, I did fiigure it out. The problem was that drawImage was being handed an ImageObserver, when infact it didn't need one. But drawImage needs an imageObserver as a parameter, so instead using 'this' you replace it with null.
    Thanks for all of the help

  • Having a problem with drawImage() and dont know why...

    OK, I'm having some problems drawing my image onto the frame.. It will let me draw string, add components, etc.. but as soon as it come to trying to draw an image it just doesn't wanna..
    Here is my code:
    import java.awt.*;
    public class Messenger extends Frame {
         private boolean laidOut = false;
         private TextField words;
        private TextArea messages;
        private Button ip, port, nickname;
        public Messenger() {
             super();
             setLayout(null);
             //set layout font
             setFont(new Font("Helvetica", Font.PLAIN, 14));
             //set application icon
             Image icon =  Toolkit.getDefaultToolkit().getImage("data/dh002.uM");
             setIconImage((icon));
            //add components
            words = new TextField(30);
            add(words);
            messages = new TextArea("", 5, 20, TextArea.SCROLLBARS_VERTICAL_ONLY);
            add(messages);
            ip = new Button("IP Address");
            add(ip);
            port = new Button("Port");
            add(port);
            nickname = new Button("Nickname");
            add(nickname);
        public void paint(Graphics g) {
            if (!laidOut) {
                Insets insets = insets();
                //draw layout
                g.drawImage("data/dh003.uM", 0 + insets.left, 0 + insets.top);
                ip.reshape(5 + insets.left, 80 + insets.top, 100, 20);
                port.reshape(105 + insets.left, 80 + insets.top, 100, 20);
                nickname.reshape(205 + insets.left, 80 + insets.top, 100, 20);
                messages.reshape(5 + insets.left, 100 + insets.top, 485, 300);
                g.drawString("Type your message below:", 5 + insets.left, 425 + insets.top) ;
                words.reshape(5 + insets.left, 440 + insets.top, 485, 20);
                laidOut = true;
        public boolean handleEvent(Event e) {
            if (e.id == Event.WINDOW_DESTROY) {
                System.exit(0);
            return super.handleEvent(e);
        public static void main(String args[]) {
            Messenger window = new Messenger();
            Insets insets = window.insets();
              //init window..
            window.setTitle("Unrivaled Messenger");
            window.resize(500 + insets.left + insets.right,
                          500 + insets.top + insets.bottom);
            window.setBackground(SystemColor.control);
            window.show();
    }Im only new to Java, maybe I've left something out ? Any help will be much appreciated, thanks :)

    Thanks! Got the image to display now... but, next problem.. its a strange one, whenever the application is minimized or has something dragged/popup over the top of it, those sections of text/images disappear... anyone know a reason for this? im using the d.drawImage() like displayed in my code above.. this is the final code for my image..
    Image banner = null;
    try {
         banner = ImageIO.read(new File("data/dh003.uM"));
    } catch(IOException e) { }
    g.drawImage(banner,0 + insets.left, 0 + insets.top, this);and as for my text...
    g.setFont(new Font("Arial",1,14));
    g.drawString("Type your message below:", 5 + insets.left, 425 + insets.top);Thanks in advance!

  • BufferedImage, drawImage and ImageIO

    Hey. This is kind of driving me nuts, i have been reading previous post, and do what they say but still no luck.
    I have merged two images next to each other, and tried to write the BufferedImage to a file as a jpg.
    All i get is a black background of the size of my BufferedImage.
    Can someone please tell me what i am doing wrong?
    public class Counter {
         public Counter() {
              BufferedImage dest = new BufferedImage(34, 28, BufferedImage.TYPE_INT_RGB);
              Graphics2D destG = dest.createGraphics();
              destG.drawImage(Toolkit.getDefaultToolkit().getImage("2.gif"), 0, 0, null);
              destG.drawImage(Toolkit.getDefaultToolkit().getImage("1.gif"), 17, 0, null);
              try {
                   createImageFile("my_new_image.jpg", "jpg", dest);
              } catch (IOException io) {
                   io.printStackTrace();
         private void createImageFile(String filename, String ext, RenderedImage image) throws IOException {
              OutputStream out = new FileOutputStream(filename);
              ImageIO.write(image, ext, out);
              out.flush();
              out.close();
         public static void main(String[] args) {
              new Counter();
    Thank you anyone that answers!!!

    Hi,,, thanx for the reply,,,, the gif encoder creates the new gif file that is supposed to be a combined image for the 2 bufferedimages.... I already tried ur suggestion b4 but the result was a blank image...
    anyways thanks again for the response... already found a cool gif encoder :
    to.mumble.GIFCodec.*;
    before i used acme....
    InputStream is = new BufferedInputStream(new FileInputStream(head));
    InputStream is2 = new BufferedInputStream(new FileInputStream(body));
    InputStream is3 = new BufferedInputStream(new FileInputStream(legs));
    InputStream is4 = new BufferedInputStream(new FileInputStream(feet));
    AnimGifDecoder     ade     = new AnimGifDecoder(is);     
    AnimGifDecoder     ade2     = new AnimGifDecoder(is2);     
    AnimGifDecoder     ade3     = new AnimGifDecoder(is3);     
    AnimGifDecoder     ade4     = new AnimGifDecoder(is4);     
    BufferedImage     bi     = ade.read(BufferedImage.TYPE_BYTE_INDEXED);
    BufferedImage     bi2     = ade2.read(BufferedImage.TYPE_BYTE_INDEXED);
    BufferedImage     bi3     = ade3.read(BufferedImage.TYPE_BYTE_INDEXED);
    BufferedImage     bi4     = ade4.read(BufferedImage.TYPE_BYTE_INDEXED);
    BufferedImage ima2 = new BufferedImage(200, 200, BufferedImage.TYPE_USHORT_555_RGB);
    Graphics2D g = (Graphics2D) ima2.getGraphics();
    //g.setColor(Color.orange);
    //Font fnt = new Font("Arial", Font.BOLD, 10);
    //g.setFont(fnt);
    //g.drawString("TESTING", 0, 0);
    g.drawImage(bi, 0, 0, null);
    g.drawImage(bi2, 0,53,null);
    g.drawImage(bi3, 0,99,null);
    g.drawImage(bi4, 0,168,null);
    g.dispose();
    OutputStream     os     = new FileOutputStream(savepath);
         try
              AnimGifEncoder     age     = new AnimGifEncoder(os);
              age.add(ima2);
              age.encode();
         finally
    } catch(Exception x) {}
         }

  • Why there are nothing after I used drawImage()?

    Hello guys, I got a problem in drawImage(), and hoping that sombody can help me out.
    The code blew is copied from a Java book, it can run in my computer, without any error message, but why the image "mypc01_64.png" can not be drawn on the JPanel?
    package TwoD;
    import java.awt.*;
    import javax.swing.*;
    * @author Jack
    public class DisplayImage extends JFrame{
        /** Creates a new instance of DisplayImage */
        public DisplayImage() {
            add(new ImageCanvas());
         * @param args the command line arguments
        public static void main(String[] args) {
            // TODO code application logic here
            JFrame frame = new DisplayImage();
            frame.setTitle("DisplayDemo");
            frame.setSize(300,300);
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);       
    class ImageCanvas extends JPanel{
        ImageIcon imageIcon = new ImageIcon("/TwoD/mypc01_64.png");
        Image image = imageIcon.getImage();
        public void paintComponent(Graphics g){
            super.paintComponent(g);
            if(image!=null){
                g.drawImage(image,0,0,getWidth(), getHeight(), this);
    }the source code and the image are in the same folder named "TwoD".

    hi,
    the same code is just working fine with me. i have just changes the image to a physical image that is present in my machine, and i have tried with absolute path. make sure you can see the image. it has got something. i have tried with Sunset.jpg provided with xp.
    ImageIcon     imageIcon     = new ImageIcon("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.jpg");regards
    Aniruddha

  • Identifying/resizing animated GIF

    Hi
    This is my situation: I load user-selected image files (any format is OK, the more the better) for later transmission as byte array, always re-encoded as JPG. If the image is over some certain width/height, I scale down the image (display size issues). Until now I was reading the images with ImageIO.read, downsizing with Graphics2D.drawImage and encoding with ImageIO.write, and everything works nicely.
    Now I need to support animated GIFs as well. The current method makes animated gifs as a static first frame of the animation. My two alternatives are:
    1 - support animated GIF downsizing
    2 - detecting animated GIFs and handling them separately (no resize allowed, no re-encode)
    The first alternative sounds cumbersome, Googling around showed problems with lost transparency and requiring to downsize all frames separately and then re-encode. If I have to do this extract-downsize-encode I won't take this route, better do not perform animated GIF resizing. The second alternative sounds much simpler, and less problem-prone.
    Now I would like suggestions on how can I archive this. I'd really appreciate some code/lib to detect and optionally resize animated GIFs. It must be a free code solution.
    The only animated GIF detection code I found was this, but it requires looking for certain bytes, and I'd like a more robust solution (also it didn't worked).
    I would like to keep using ImageIO API rather than older APIs, as it seems to provide better image format support and is way simpler. A lib to do the GIF part of the job is fine.
    Thanks!

    This is my situation: I load user-selected image files (any format is OK, the more the better) for later transmission as byte array, always re-encoded as JPG. If the image is over some certain width/height, I scale down the image (display size issues).If they are JPEGs that is entirely the wrong solution. You are losing far too much image quality. What you should be doing here is saving with a lower 'q'. That's exactly what it's for - intelligent compression of images. You are just doing naive resampling. JPEG can do far better than that.
    I worked on a project where somebody downsized thousands of images like this, entirely the wrong way. Don't repeat this mistake.
    As to the rest, sounds like you need a GIF plugin for ImageIO that will let you read the header.

  • X11 Pipeline: Extreme Thrashing

    I have a graphics intensive application that I am working on, and I am getting severe thrashing while running in X. Results are excellent from an e-machine running Windows Vista.
    Here's the basic idea of the program. It uses AWT (no Swing is ever referenced). There is a collection of "sprites" which were created from GraphicsDevice.createCompatibleImage() to give them the best chance at acceleration. Then there is a backbuffer, to which the program draws. It attempts to deliver higher framerates by only updating portions of the screen which are changing. Originally, this backbuffer was also created with GraphicsDevice.createCompatibleImage(), however this leads to the thrashing I mentioned earlier.
    After reading through:
    [Troubleshooting Guide for Java SE 6 Desktop Technologies|http://java.sun.com/javase/6/webnotes/trouble/TSG-Desktop/html/toc.html]
    I managed to isolate the problem to X11 offscreen pixmaps, and running with the flag -Dsun.java2d.pmoffscreen=false removes the thrashing.
    The problem I have here is that I am now confused. It seems to me that I want my sprites accelerated, but shouldn't my backbuffer also be accelerated? I'm not using antialiasing, nor alpha compositing, nor translations. I do make heavy use of setting the clip on the graphics object. Is that where my problem resides? Am I confused on the meaning of alpha compositing... does that include 1-bit transparency?
    Quote from the above referenced document:
    "The use of pixmaps typically results in better performance. However, in certain cases, the opposite is true. Such cases typically involve the use of operations which cannot be performed using the X protocol, such as antialiasing, alpha compositing, and transforms that are more complex than simple translation transforms.
    For these operations the X11 pipeline must do the rendering using the built-in software renderer. In most cases this includes reading the contents of the pixmap to a system memory (over the network in the case of remote X server), performing the rendering, and then sending the pixels back to the pixmap. Such operations could result in extremely poor performance, especially if the X server is remote."
    Could someone enlighten me here? Why are my accelerated surfaces being copied back into system memory when all I am doing is drawing accelerated surfaces onto accelerated surfaces using drawImage() and setClip().

    You're totally right. I was preparing a code example, during which I discovered my mistake.
    I'm still curious as to why Swing is causing a problem with off screen pixmaps in X. I've seen this problem before but I was never concerned with rapid updating of the screen so I never investigated. I think it must be Swing's backbuffer causing it, but is this a problem with the Java2D X11 pipeline, or maybe a bug somewhere else in my OS?
    Here is a code example which produces the problem, running it with sun.java2d.pmoffscreen=false runs fine, but without it, X begins hogging CPU time and starves Java out resulting in pauses in execution.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    class SwingFail implements ActionListener {
      private static JFrame frame;
      class RefreshPanel extends JPanel {
        public RefreshPanel() {
          setPreferredSize(new Dimension(512, 512));
        public void paintComponent(Graphics g) {
          g.setColor(Color.black);
          g.fillRect(0, 0, 512, 512);
          g.setColor(Color.white);
          g.drawString(new Date().toString(), 25, 250);
      public SwingFail() {
        frame = new JFrame("Rapid Refresh");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel panel = (JPanel) frame.getContentPane();
        panel.add(new RefreshPanel());
        frame.pack();
        frame.setVisible(true);
      public void actionPerformed(ActionEvent e) {
        frame.repaint();
      public static void main(String[] args) {
        SwingFail sf = new SwingFail();
        javax.swing.Timer t = new javax.swing.Timer(1, sf);
        t.setCoalesce(false);
        t.start();
    }PS This is with Java 5, and the underlying OS is in bad need of an update so I wouldn't be surprised if this issue has long since been resolved, but I'd still love to hear from someone else running X11 if this works well or not. Of course hardware performance may be a factor, but the difference in CPU time should still be evident between turning offscreen pixmaps on or off.
    Edited by: DecadeOfJava on Jun 19, 2010 6:34 AM

  • What's most efficient for drawing a semi-transparent overlay?

    I have a large .TIF loaded as a RenderedImage through JAI and drawn with Graphics2D.drawRenderedImage(). It can be scaled by the user and it uses the JAI operator "Scale" to do it and is extremely fast given the size if the TIF (2528x3297).
    The problem comes when I need to take another image and use it as an "overlay". Only the red part of this image needs to actually be drawn, and that needs to have some transparency. The rest of the image should be completely transparent. I'm looking for a fast and efficient way of approaching both the drawing and scaling. Any type of image (supported by AWT/JAI at least) is acceptable, passing it through a filter at runtime to make the parts transparent or semi-transparent is fine too. I'm just looknig for a good methodology that will offer speed in both drawing and scaling in conjunction with the TIF mentioned earlier.
    I tried using a PNG that already had the desired transparency but it behaves oddly. If I load it as an Image using ImageIO.read() and then use drawImage() and getScaledInstanceOf() it draws relatively slowly, but just barely acceptable, but takes way too long to scale. If I load it as a RenderedImage with JAI and use drawRenderedImage() the painting is extremely fast when it's first loaded with no scaling and when i scale it it's fairly fast at scaling, but after it's been scaled it draws extremely slowly.
    I tried using a GIF but had pretty much the exact same issues as PNG. Slow scaling and decent drawing as an Image and quick scaling and drawing initially, but extremely slow drawing after it's been scaled.
    Strangely enough one of the best middle grounds I've seen in my experimentations was a .TIF I loaded in JAI, converted to BufferedImage, passed through a filter to make all white transparent and all black be red, and then drew as a BufferedImage.
    I'm totally lost and confused here. Could someone please help me out with some advice?

    Ah, that's the kind of confirmation I was hoping for, thanks! Though if anyone has anything else to weigh in (specific considerations and the like) then feel free!

  • Performance problems with AlphaComposite

    Hi,
    I'm writing an application using Graphics2D that on the background has a grid that has been baked on a BufferedImage, which is first drawn using drawImage and on top of that (if the user draws a selection) a selection that is an Area object. The selection should be partially transparent so I used AlphaComposite as follows:
    AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
    g2.setComposite(ac);
    g2.setPaint(new Color(168, 199, 232));
    g2.fill(ResourceManager.getSelection());
    g2.setPaint(new Color(51,153,255));
    g2.draw(ResourceManager.getSelection()); // Draw the border.
    g2.setComposite(AlphaComposite.SrcOver); // Reset to opaque.All really basic but I must be doing something wrong here because it takes around 6-7 ms to render it, while the rest of the scene takes no more than 2-3. Commenting all the AlphaComposite code reduces rendering time of it to 0.1-0.4 ms (depending on the size of the selection).
    I don't think that there's any more information that I could give you that's relevant here. I'm just wondering if I'm doing something wrong here or if the whole transparency thing is really this slow.

    Thanks :)
    I'm currently rendering to a JPanel that is used as a canvas, which - as a Swing component - is double buffered and I assume that the buffer which I'm drawing on is hardware accelerated, unless there's extra steps that I need to take to make it so. I honestly don't know what's hardware accelerated by default and what's not. I set setDoubleBuffered to false and used a VolatileImage as a buffer (which I think is always accelerated) and that still gives me awful performance.
    But 6-7ms is an expected time for software rendering of transparency? Still seems like an awful long time.

  • ImageIcon fails to load image from known source

    Hello,
    I have tried multiple ways to use ImageIcon to place an image within a JFrame.
    I have tried to place directly on the JFrame using drawImage and within a JLabel.
    I have tried multiple sources such as fully qualified regular files to the root and filenames relative to the current project. I have also tried using URLs.
    I am executing this project from Eclipse and have used both Windows and the Mac.
    My debugging code tells me the load of the image is not successful.
    Thank you for your help with this problem.
    ====================================================================
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    import javax.swing.*;
       class Main extends JFrame implements ItemListener {
         Image image;
         Image imagecopy;
         String imagefile;
         URL imageurl;
         String strslnts = "Slavery notes";
         String strnsnts = "North & South notes";
         String strwpnts = "Weapons notes";
         String strbtnts = "Battle notes";
         int frwidth, frheight, il, it;
         List stuslist;
         Main() {
              super("The Civil War as Presented by Garrett Neuman");
              imagefile = "file:///Users/teacher/Desktop/garrett/CivilWar/flags.gif";       
              image = getToolkit().getImage(imagefile);
              setIconImage(image);
              frwidth = 1024;
              frheight = 735;   //leave room for task bar
               WindowEventHandler weh = new WindowEventHandler();
               addWindowListener(weh);
               Insets insets = getInsets();
              il = insets.left; it = insets.top;
               setSize(frwidth, frheight);
              setResizable(false);
              try {imageurl = (new URL("http://www.ariped.com/01-pat_metheny_01.jpg"));}
              catch (MalformedURLException e) {stuslist.add("malformed url");};
              ImageIcon icon = new ImageIcon(imageurl);
              int fstatus = icon.getImageLoadStatus();
    //         stuslist.add(String.valueOf(fstatus));
              JLabel iconLabel = new JLabel(icon);
              setContentPane(iconLabel);
              setVisible(true);

    Thanks for the advice on SSCCE. This cracked the case for me and will be useful in the future.
    One observation I gained from testing is that even regular files seem to need to go through the URL process for the image load to be successful.
    This may or may not be useful but the following code caused the image load to fail. I tried commenting out the code line by line from the bottom up but the mere presence of the definition caused failure of the image load.
            public void paint(Graphics g) {
                  int iwidth = image.getWidth(null);
                  int frmidd = (il + frwidth - iwidth) / 2;     
                  g.drawImage(image, frmidd , (it + 30), null);
                  g.drawRect(75, 175, 210, 230);
             }

  • Question about displaying image with JLabel

    Hi
    I need to display an image. The image is determined by the user at run time, so the dimension of the image is unknown. Is it possible for JLabel to stretch the image so the whole image(instead of only part of it) will always fits into a certain dimension?
    thanks.

    For this you need to create a custom class that extends ImageIcon
    and define the methods there.
    see Java Tutorial for it.
    For eg., to scale an image , you can use
    JLabel label = new JLabel();
    Image img = new ImageIcon("Pics/Ash.jpg").getImage();
    int width = img.getWidth(null);
    int height = img.getHeight(null);
    //This would scale the Image by 200%
    Image bimg = image.getScaledInstance(width*2, height*2, Image.SCALE_SMOOTH);
    label.setIcon(new ImageIcon(bimg));
    //There is also another way
    //Use drawImage and use BufferedImage
    BufferedImage buff = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics g = buff.getGraphics();
    //Scale the Image to 200%
    g.drawImage(img, 0, 0, width*2, height*2,  null);
    lable.setIcon(new  ImageIcon(buff));Hope you get the idea!!

  • Stretch image

    Do you know how to stretch an image according to the size of the screen?

    What exactly do you mean? Do you mean the screen area(how many pixels wide and tall the screen is) or the component you're drawing onto?
    The Graphics class has several methods that you can use to draw an image in different sizes. They are all drawImage, and take increasing numbers of properties. The first one simply takes an image, an x, a y, and draws the image at its stored size. The one with the most number of parameters draws a specific region of the image to a certain spot at any size.
    The GraphicsDevice, GraphicsEnvironment, and GraphicsConfiguration classes could all be useful for determining the screen size. Unfortunately I don't have much experience in this area, so I'm not sure exactly what you should do.
    Ha, ha, you can't say ass

  • Help needed with game graphics engine

    I'm creating a game for which I've created my own component system that is independent from AWT and stuff.
    I have components such as Button, DropMenu, ScoreBoard, Character... also GamePanel class that acts
    same as the Panel class in AWT except that you can add Effects to it. Effects can be as simple as Contrast, Brightness, Gamma, GreyScale or bit more complicated such as noise, flicker, shake. Anyway they deal with pixellevel operations. I see that I must do my own graphics functions such as drawText, drawImage and stuff.
    ... now let's say that character needs to be painted. First we call my own drawImage method in Character class... then we pass it throught effects assigned to Character... lets say shake, so this is where I it get's a bit complicated for me... should the effect return new image which is then sent to Characters owner for additional effects and layers untill it reaches the main panel which uses Graphics-class to paint the character to screen. Please give me some hints to do this kind of stuff...
    Looking foreward for your answers MK.

    What do u mean? What if there are multiple effects, say character has few, and the whole screen has some and that way. I see the option that I can create double buffer for every panel, but that's wasting lots of memory. Other option I have thought about is to gather all effects to one class like this so that every effect would only affect the parameters of paintjob, and in the end we would just do special drawImage method.
    abstract Class element
    abstract void draw(Graphics g);
    class ImageElement extends Element
    Image img;
    void draw(..)=,
    class LineElement...
    class RectangleElement...
    class PaintJob
    Element element;
    int x,y;
    double rotation;
    double contrast;
    double brightness;
    double rmul, gmul, bmul;
    void applyEffect(Effect e);
    void doPaint(Graphics g);
    But this is not good, since say I wanted effect like disortion or noise, and I do not see anyway to apply them here. I am thinking also to do this more simpler, but it would be great for my game to have such wide varierty of FX applied so easily... could you give me some ideas.

  • Help Me!! Re: Using A background image In my DWT Header

    Hello,
    I have tried posting several messages regarding this issue but not sure if I am explaining my dilemma properly. So here we go, here is the link to my Generic Template page which I converted to an html to enable you to view it. (http://bridgestoprosperity.org/Templates/General.htm). Now what I am trying to do is use the image that is currently in the header as a background image , BUT i cannot figure out how to insert it as a div background image. Then once I fugure that out I am hoping there is a script that will be able to dynamically insert the page title for each page as it's opened. The title needs to be placed on the right hand side of header ABOVE the words Bridges to Prosperity USA over the background image.
    Because this is the main template for our entire site i am hoping that once I figure this out, I can just save all the new changes to the template and be done with it and from then on when I create a new page from template because it will hopefully have some code in it where it calls the Title of the page from some script that I will no longer have to create headers with embedded (non searchable) Page titles for EACH AND EVERY ONE OF OUR OVER 750 PAGES.......
    YIKES, PLEASE HELP, AND I WOULD BE FOREVER IN YOUR DEBT IF YOU COULD ACTUALLY INCLUDE CODE IN YOUR RESPONSE AND EXPLAIN EXACTLY WHERE TO PUT IT OR WHAT TO REMOVE AND WHAT TO PASTE. THE MORE DETAILED THE BETTER CAUSE I AM VERY NEW TO ALL OF THIS.
    I really appreciate it,
    Allan

    Your mistake is to drawImage and then call super.paintComponent, which paints over the image you have drawn. That's not what I said, re-read my earlier response.protected void paintComponent (Graphics g) {
       super.paintComponent(g);
       g.drawImage(icon.getImage(), 0, 0, null);
       //super.paintComponent(g);
    }I would also advise against calling icon.getImage inside the paintComponent, make a Image instance field and call the method once to store a reference to the Image.
    paintComponent is called many times during resize / move operations, and should be as lean as possible.
    db
    edit To post code, use the code tags -- [code]Your Code[/code]will display asYour CodeOr use the code button above the editing area and paste your code between the tags it generates.
    Edited by: Darryl.Burke

  • An MMORPG game

    Hi everybody!!!!!!!
    I am doing an MMORPG and I need some help:
    The game has real time combat, so i need someone to teach me, how to make a simple fighting game. You know: punch, kick, and button combination.
    Please help me ^_^

    for button combination, try using a keyDown method. it is deprecated, but here is what it looks like. btw, the undeprecated version is keyPressed
    public boolean keyDown(Event e, int key) {
          if (key == 32)
                 if (key == 112)
                       doWhateverYouWantWhenTheseAreButtonsPressed
    }as for the kicking and stuff, when u draw stuff ur gonna giv the x and y coordinates with drawImage and then u can keep adding the speed onto it(x += xspeed)(y += yspeed) and redrawing, then use an update method or double buffering to remove the flickering.

Maybe you are looking for