Couln't  save a buffered image as BMP with java 1.4

Dear friends,
I tried to save a buffered image as BMP with java 1.4. When I run the program ,it executes sucessfully, but no image wasn't created. When I tried the same code with java 1.5 got the right result.
This is the code I have written.
public static void saveBMPFile(BufferedImage bufferredImage, String fileName) throws Exception{
          // TODO Auto-generated method stub
          try {
               Iterator iter =
                    ImageIO.getImageWritersByMIMEType("image/bmp");
          // Get first writer
               if (iter.hasNext()) {
                    ImageWriter writer = (ImageWriter) iter.next();
                    ImageWriteParam iwp = writer.getDefaultWriteParam();
                    iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                    iwp.setCompressionType("BI_RGB");                    
                    FileImageOutputStream fios = new FileImageOutputStream(new File(fileName));
                    writer.setOutput(fios);
                    IIOImage image = new IIOImage(bufferredImage, null, null);
                    writer.write(null, image, iwp);
                    bufferredImage.flush();
                    fios.flush();
                    fios.close();
     } catch (Exception e) {                 
     throw e;
please help me to find its solution.
thanks & regards
K P Jyothish

Please use code tags http://forum.java.sun.com/help.jspa?sec=formatting
I can see no else for "if (iter.hasNext()) {", so if no encode is found, no error message would be displayed.

Similar Messages

  • Save byte array (image) to file with servlet

    Good day.
    I should must to save a png image to file.
    I have a byte array of the image.
    This work is in a servlet.
    How can I do it?
    Best regards.
    Stefano Errani

    Good day.
    I have a byte[] and then I have used
    FileOutputStream fos = new FileOutputStream(getServletContext().getRealPath("/public_html/mcfoto/foto1.png"));
    fos.write(bt, 0, bt.length); // byte[] bt
    fos.close();
    This on my web server that has public_html as root web directory.
    The server is in multi domain.
    In this mode I have an error.
    Then I have tryied to use
    FileOutputStream fos = new FileOutputStream("http://www.stefanoerrani.it/mcfoto/foto1.png");
    and
    FileOutputStream fos = new FileOutputStream(getServletContext().getRealPath("http://www.stefanoerrani.it/mcfoto/foto1.png"));
    In both ways I have obtained an error.
    At last I have tryied in my localhost (local machine) using
    FileOutputStream fos = new FileOutputStream(getServletContext().getRealPath("/mcfoto/foto1.png"));
    All run correclty.
    The Application Server is Tomcat with Apache HTTP Server.
    The first server (of www.stefanoerrani.it) has Linux as OS.
    My local server has Windows as OS.
    I should want, if it's possible, an help.
    Best regards.
    Stefano Errani

  • Drag and Drop Image to PDF with Java Script

    Hi,
    I have to create some PDF reports and contained within these reports there are numerous images, some as many as 30-40. This is really time consuming. Can anyone please advise if there is some java script available so I may Drag & Drop an image onto a button or directly onto the PDF report.
    I have attached an example video of the current process and as you will see the process is very long to say the least. Any assistance would be appreciated.
    Kind Regards
    Terry Lewis

    Hi Gilad,
    Apologies for that I edited the wrong video in my Youtube account.
    You mentioned that its not possible with JS.
    Are you aware of any other options?
    Kind regards
    Terry
    P.S. I have amended the video situation.

  • How to convert JPG image to BMP ? (Printing jpg images in smartforms from content server)

    Hi,
    We have employee photos(JPG Format) stored in Content server. And now we want to print the photos in smartforms. For this I had written the below code to read the photo from content server in binary format as below.
    REPORT ZTEST1.
    PARAMETERS P_PERNR TYPE PERNR_D.
    DATA: PS_CONNECT_INFO TYPE TOAV0,
          IT_BINARY TYPE TABLE OF SDOKCNTBIN.
    CALL FUNCTION 'HR_IMAGE_EXISTS'
      EXPORTING
        P_PERNR                     = P_PERNR
    *   P_TCLAS                     = 'A'
    *   P_BEGDA                     = '18000101'
    *   P_ENDDA                     = '99991231'
    IMPORTING
    *   P_EXISTS                    =
       P_CONNECT_INFO              = PS_CONNECT_INFO
    * EXCEPTIONS
    * ERROR_CONNECTIONTABLE       = 1
    *   OTHERS                      = 2
    IF SY-SUBRC <> 0.
    * Implement suitable error handling here
    ENDIF.
    IF PS_CONNECT_INFO IS NOT INITIAL.
      CALL FUNCTION 'SCMS_DOC_READ'
        EXPORTING
       STOR_CAT                    = SPACE
       CREP_ID                     = PS_CONNECT_INFO-ARCHIV_ID
          DOC_ID                      = PS_CONNECT_INFO-ARC_DOC_ID
    *   PHIO_ID                     =
    *   SIGNATURE                   = 'X'
    *   SECURITY                    = ' '
    *   NO_CACHE                    = ' '
    *   RAW_MODE                    = ' '
    * IMPORTING
    *   FROM_CACHE                  =
    *   CREA_TIME                   =
    *   CREA_DATE                   =
    *   CHNG_TIME                   =
    *   CHNG_DATE                   =
    *   STATUS                      =
    *   DOC_PROT                    =
    TABLES
    *   ACCESS_INFO                 =
    *   CONTENT_TXT                 =
       CONTENT_BIN                 = IT_BINARY
    * EXCEPTIONS
    * BAD_STORAGE_TYPE            = 1
    *   BAD_REQUEST                 = 2
    *   UNAUTHORIZED                = 3
    * COMP_NOT_FOUND              = 4
    *   NOT_FOUND                   = 5
    *   FORBIDDEN                   = 6
    *   CONFLICT                    = 7
    * INTERNAL_SERVER_ERROR       = 8
    *   ERROR_HTTP                  = 9
    * ERROR_SIGNATURE             = 10
    *   ERROR_CONFIG                = 11
    *   ERROR_FORMAT                = 12
    * ERROR_PARAMETER             = 13
    *   ERROR                       = 14
    *   OTHERS                      = 15
      IF SY-SUBRC <> 0.
    * Implement suitable error handling here
      ENDIF.
    ENDIF
    Now the issue is I want to convert that binary data to bitmap image and upload the same in to SE78. So that I can use that BMP image from SE78 in my smartforms.
    I had used the class CL_IGS_IMAGE_CONVERTER to covert the image into bmp but it is giving error that error in IMAGE DATA CORRUPT & Error Code 3. The conversion code used is as below.
    ******* CONVERT THE JPG IMAGE INTO BMP PHOTO. **********
      DATA: L_IGS_IMGCONV TYPE REF TO CL_IGS_IMAGE_CONVERTER,
    L_IMG_BLOB    TYPE W3MIMETABTYPE,
    L_IMG_SIZE    TYPE W3PARAM-CONT_LEN,
    L_IMG_TYPE    TYPE W3PARAM-CONT_TYPE,
             L_IMG_SUBTYPE TYPE W3PARAM-CONT_TYPE,
    L_IMG_URL     TYPE W3URL,
    L_ERR_CODE    TYPE I,
    L_ERR_TEXT    TYPE STRING,
             P_DEST TYPE CHAR32 VALUE 'IGS_RFC_DEST'.
      DATA: G_IMG_BLOB     TYPE W3MIMETABTYPE,
          G_IMG_TYPE     TYPE W3PARAM-CONT_TYPE,
          G_IMG_SIZE     TYPE W3PARAM-CONT_LEN.
      IF NOT IT_BINARY[] IS INITIAL.
        G_IMG_BLOB[] = IT_BINARY.
        CREATE OBJECT L_IGS_IMGCONV
          EXPORTING
            DESTINATION = P_DEST.
        CALL METHOD L_IGS_IMGCONV->SET_IMAGE
          EXPORTING
            BLOB      = G_IMG_BLOB
            BLOB_SIZE = G_IMG_SIZE.
        CASE PS_CONNECT_INFO-RESERVE.
          WHEN 'TIF'.
            G_IMG_TYPE = 'image/tiff'.
          WHEN 'JPG'.
            G_IMG_TYPE = 'image/jpeg'.
          WHEN 'PNG'.
            G_IMG_TYPE = 'image/png'.
          WHEN 'GIF'.
            G_IMG_TYPE = 'image/gif'.
          WHEN 'BMP'.
            G_IMG_TYPE = 'image/x-ms-bmp'.
          WHEN OTHERS.
            EXIT.
        ENDCASE.
    L_IGS_IMGCONV->INPUT  = G_IMG_TYPE.
        L_IGS_IMGCONV->OUTPUT = 'image/x-ms-bmp'.
    *    PERFORM GET_SIZE USING PICTURE_CONTAINER
    * L_IGS_IMGCONV->WIDTH
    * L_IGS_IMGCONV->HEIGHT.
        CALL METHOD L_IGS_IMGCONV->EXECUTE
          EXCEPTIONS
            OTHERS = 1.
        IF SY-SUBRC IS INITIAL.
          CALL METHOD L_IGS_IMGCONV->GET_IMAGE
            IMPORTING
              BLOB      = L_IMG_BLOB
              BLOB_SIZE = L_IMG_SIZE
              BLOB_TYPE = L_IMG_TYPE.
          SPLIT L_IMG_TYPE AT '/' INTO L_IMG_TYPE L_IMG_SUBTYPE.
        ELSE.
          CALL METHOD L_IGS_IMGCONV->GET_ERROR
            IMPORTING
              NUMBER  = L_ERR_CODE
              MESSAGE = L_ERR_TEXT.
          BREAK-POINT.
        ENDIF.
      ENDIF.
    ENDIF.
    So could you please some one help me how to convert JPEG Photo to BMP programatically.
    Regards,
    Mayur.

    johnandersonpalmdesert wrote:
    My printer is requesting a vector file.
    Jpeg File format does not support vectors.  Photoshop has limited vector support and tools.  Photoshop can not save vector file formats like SVG.  What File type does your printer want?
    Adobe Illustrator is Adobe vector application.

  • Help! Fix my javascript to save a bmp with suffix in the same folder as the previous save.

    Here's my current javascript:
    #target photoshop
    // sets document preferences to inches
    app.preferences.rulerUnits = Units.INCHES
    // these are our values for the END RESULT width and height (in inches) of our image
    var fWidth = 11.73;
    var fHeight = 5.97;
    var CurrentDLPFile=app.activeDocument
    var CurrentDLPFileName= CurrentDLPFile.name
    var CurrentDLPFilePath="~/Desktop/fetch"
    var f = File.saveDialog('Save Where?',''); 
    // in case we double clicked the file
    app.bringToFront();
    // resizes the canvas to 11.73 x 5.97 inches
    CurrentDLPFile.resizeCanvas(UnitValue(fWidth,"in"),UnitValue(fHeight,"in"));
    // flattens all layers
    CurrentDLPFile.flatten();
    // saves as photoshop file
    if (f!=null) CurrentDLPFile.saveAs(f,undefined);
    // splits channels
    CurrentDLPFile.splitChannels();
    // converts active K seperation to bitmap form
    var bitsaveoptions = new BitmapConversionOptions()
    bitsaveoptions.method = BitmapConversionType.HALFTONESCREEN
    bitsaveoptions.angle = 45
    bitsaveoptions.frequency = 55
    bitsaveoptions.resolution = 300
    bitsaveoptions.shape = BitmapHalfToneType.ROUND
    app.activeDocument.changeMode(ChangeMode.BITMAP,bitsaveoptions);
    // THIS IS WHERE I'M HAVING ISSUES- I want to save the file (which at this point is a bmp), with a suffix of 1 in the same folder; and then close the file.
    var doc = app.activeDocument;
    var docName = doc.name;
    docName = docName.match(/(.*)(\.[^\.]+)/) ? docName = docName.match(/(.*)(\.[^\.]+)/):docName = [docName, docName];
    var suffix = '_1';
    var saveName = new File(decodeURI(doc.path)+'/'+docName[1]+suffix+'.bmp');
    function saveFile(app.activeDocument, saveName);

    I figured it out, here's for anyone else who is struggling with a similar problem:
    var CurrentDLPFile=app.activeDocument
    // saves active doc as photoshop file
    if (f!=null) CurrentDLPFile.saveAs(f,undefined);
    //renames active document to whatever was saved
    var CurrentDLPFile = app.activeDocument.name
    //assigns the location of the saved psd
    var psdPath = activeDocument.path
    saveBMP = new BMPSaveOptions();
    saveBMP.alphaChannels = false;
    saveBMP.depth = BMPDepthType.ONE;
    saveBMP.flipRowOrder = false;
    saveBMP.rleCompression = false;
    saveBMP.osType = OperatingSystem.WINDOWS;
    var doc = app.activeDocument; 
    var Name = doc.name.replace(/\.[^\.]+$/, '');  
    var Suffix = "1"; 
    var saveFile = File(psdPath + "/" + Name + Suffix + ".bmp");
    activeDocument.saveAs(saveFile, saveBMP, true, Extension.LOWERCASE); 
    activeDocument.close( SaveOptions.DONOTSAVECHANGES );

  • Image darker when saved than on-screen buffered image

    Hi,
    Here is my little application. I am trying to simulate an rgb screen look based on image data. ie, the new image is an exaggerated tv look of the original image.
    When I try to encode/save a jpeg from my buffered image, the saved image is darker (colours also seem to be different) than what i see in my application frame. I like what I see in the JFrame and would like to have that saved. I am just an artist hack so excuse the cobbled together code. I have also included the original image, the image as it is saved, and an image as a rough approximation of the image in the JFrame.
    In the code you will see I have tried different ways to encode the image (commented out)
    Any ideas about this issue or how to make this program more sound please let me know.
    the code:
    http://zukanter.com/javaImageTest/displayImageRGBBuffer.java
    the orignal loaded into the appp:
    http://zukanter.com/javaImageTest/myPic.jpg
    the saved image:
    http://zukanter.com/javaImageTest/_003.jpeg
    the image as it is in the application window:
    http://zukanter.com/javaImageTest/_003Screen.jpg

    Hi
    My 2c.
    I`ve had a quick look at your code and the output and I`m assuming that the vertical RGB lines are what you intended.
    Jpeg works in blocks, and averages pixel valiues across them.
    If introducing those primaries into the graphic and then compressing it makes it darker that`s likely the result of the primary colours being averaged by the compression algorithm.
    You should look at resizing the image first, drawing it onto an offscreen buffer, then doing an overlay (alpha channel) with the primary colors instead, IMHO.
    regards

  • Cant export large satellite image in BMP format

    I loaded a satellite  image stored in TIFF format 35681x16716 x 24 bits per pixel
    I wanted to convert it to BMP but when I want to save as there was no such option why?
    There wasn't PNG either. GIMP a free software program was able to load the TIFF and export as PNG
    CS5 cant even do that.  But GIMP could not export to BMP as it died on export.
    So my question is how do I get this to work? How do I export this huge image to BMP?

    I wanted to convert it to BMP but when I want to save as there was no such option why?
    Because all image formats are constrained in some way and PS in particular will not save/ export anything beyond 32000 pixesl to those legacy formats, even if they may in theory allow more. It simply can't be done.
    Mylenium

  • Graphics to Buffered Image

    Hello there.
    Ill try to explain this the simplest way possible. Lets say i have a map, and sprites on that map. The map by itself its static, it will only move along as a camera move. Im calling, methods directly in Paint from my applet to draw the map, and draw the sprites. What i am willing to do it, Drawing the map into a separate Graphics or a BufferedImage, so i can draw the map on the final graphics. This would also make i draw the map only once, witch would be good as well, cause actually map drawing is on a loop.
    Thanx in advance for any help.
    For a better undestanding:
    I have a map, and i have sprites, and a window class. Each is drawd by a different class. My Paint method is something similar to this:
    public void paint(Graphics g) {
       MapClass.drawMap(g);
       SpriteClass.drawSprites(g);
       WindowClass.drawWindows(g);
    }now, this makes me draw the map on the game loop, and if i wanted to move the map around i would have to translate the graphics to move only the map and sprites. However, i belive this could be easyer if i have a separate map for example, and i could use my paint method like this:
    public void paint(Graphics g) {
       g.drawImage(MapClass.getMap(), camX, camY, screenX, screenY);
       g.drawImage(SpriteClass.getSprites(),  camX, camY, screenX, screenY);
       WindowClass.drawWindows(g);
    }So i could control camera movements easy, and i can save the map into memory so i dont have to draw it over and over again. Ive googled into how to create a buffered image from a graphics but couldnt do it. Lets say i have this method doing the paint ( a simple one )
    // class Sprites
    public void drawSprites(Graphics g) {
        g.drawImage( sprite, spriteX, spriteY, sizeX, sizeY);
    }Now, i would have something like that
    public BufferedImage getSprites() {
       Graphics g = new Graphics();
       g.drawImage( sprite, spriteX, spriteY, sizeX, sizeY);
       BufferedImage img = new BufferedImage(parms, parms2);
       img = g; // ?
       return img;
    }So i could just paint this img on the main graphics, and move it easy, and pheraphs store it in memory.
    Thanx for any kind of help.
    []´s Ziden

    crosspost
    Please only post your message in 1 forum, your question is anwered there. Graphics to BufferedImage ?

  • Webcam capture & save as JPEG image

    Hi,
    I'm creating an application to capture image via webcam using directshow. I've managed to capture the stream using samplegrabber.
    the problem is when I save the grabbed image to a JPEG, the colors are incorrect.
    provided the link of the captured image from the webcam http://www.filefreak.com/pfiles/44160/test2.jpg
    the right hand side of the image should be brown colored, not blue as in the picture.
    I've also test to save as a bmp image, the color are ok.
    this is how i save the grabbed webcam frame into a jpeg file
    sampleGrabber->GetCurrentBuffer(&bufferSize, (long*)frameBuffer); 
    //save into jpeg 
    struct jpeg_compress_struct cinfo; 
    struct jpeg_error_mgr jerr; 
    JSAMPLE * image_buffer=NULL; 
    FILE * outfile;      
    JSAMPROW row_pointer[1];     
    int row_stride;  
    cinfo.err = jpeg_std_error(&jerr); 
    jpeg_create_compress(&cinfo); 
    if ((outfile = fopen("test2.jpg", "wb")) == NULL) { 
            fprintf(stderr, "can't open %s\n", "test2.jpg"); 
        return; 
    image_buffer = (unsigned char*)frameBuffer; 
    jpeg_stdio_dest(&cinfo, outfile); 
    cinfo.image_width = videoWidth;      
    cinfo.image_height = videoHeight; 
    cinfo.input_components = 3;      
    cinfo.in_color_space = JCS_RGB;      
    jpeg_set_defaults(&cinfo); 
    jpeg_set_quality(&cinfo, 255, TRUE ); 
    jpeg_start_compress(&cinfo, TRUE); 
    row_stride = videoWidth * 3;     
    while (cinfo.next_scanline < cinfo.image_height) { 
        row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride]; 
        (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); 
    jpeg_finish_compress(&cinfo); 
    fclose(outfile); 
    jpeg_destroy_compress(&cinfo); 
    //end save jpeg 
    Thanks.
    Regards

    Hi,
    Thanks
    for participating on the MSDN Forum! I think your question is mainly related
    with DirectX, but not Visual C++ Language. Thus, I suggest you post your
    question on the microsoft.public.win32.programmer.directx.video newsgroup, there you find DirectX experts and your
    question should be answered in no time.
    The people there will have enough experience with DirectX to give you the best
    advice or answer!
    http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.win32.programmer.directx.video&lang=en&cr=US
    Thanks! Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • I have created a 468x60 animated banner in Edge Animate. How do I save the animated image to my desktop? (not in html code)

    I have created a 468x60 animated banner in Edge Animate. How do I save the animated image to my desktop? (not in html code)

    Hi,
    This feature is not available in Adobe Edge animate. You can not export as image from Edge animate.
    Publish options available in edge describe here
    Edge Animate Help | Publish your content
    Regards,
    Devendra

  • Problem in sending buffered image to remote machine

    iam able to capture ithe desktop screen as a buffered image by using buffered image class in java.awt.image.but iam bot able to send that buffered image to remote machine.it is only possible to send some part of that buffered image.but iam not able to transmit the whole buffere image of my desktop.can u help.

    Hi,
    For this topic you should have a look ( 2004-07-08 The Java Specialists' Newsletter [Issue 091] )
    from Dr. Heinz Kabutz. Indeed, the newsletter is quite useful and sometimes also amazing.
    I really enjoy reading it.
    In this newsletter he is exactly doing what you wanted to know.
    He uses an ObjectOutputStream, but compresses the screenshot beforehand as follows:
        import com.sun.image.codec.jpeg.*;
        Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
        Rectangle shotArea = new Rectangle(
            defaultToolkit.getScreenSize());
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bout);
        encoder.encode(robot.createScreenCapture(shotArea));
        return bout.toByteArray();Hope that helps

  • How do i save STACKS of images (e.g. TIFF) as a SINGLE file in IMAQ?

    I would like to save stacks of images (movies and time series) as single files (TIFF in particular) but i can only find support in IMAQ for saving single images to single files. Does anyone know how to save STACKS? (As far as i know that is a common feature in most frame grabbers).
    I am using a PCI-1408 card for analog acquisition and NI-IMAQ driver in Windows 2000.

    Bernhard,
    There are no utilities in IMAQ to save image sequences in a single file.
    One possible solution, if you aren't trying to compress the images, is to extract the 2D array of pixel intensities and save them as a standard array. You would be able to store as many arrays as you want in a single file.
    If you want to compress the images, there are utilities for creating AVI files. I have used a wavelet compression utility that I wrote LV drivers for, also. If you are willing to spend a little money, that might be a good solution. You can contact me at bruce@ammonsengineering if you want to discuss it further.
    Bruce
    Bruce Ammons
    Ammons Engineering

  • How do I fix extremely slow rendering with buffered images?

    I've found random examples of people with this problem, but I can't seem to find any solutions in my googling. So I figured I'd go to the source. Basically, I am working on a simple platform game in java (an applet) as a surprise present for my girlfriend. The mechanics work fine, and are actually really fast, but the graphics are AWFUL. I wanted to capture some oldschool flavor, so I want to render several backgrounds scrolling in paralax (the closest background scrolls faster than far backgrounds). All I did was take a buffered image and create a graphics context for it. I pass that graphics context through several functions, drawing the background, the distant paralax, the player/entities, particles, and finally close paralax.
    Only problem is it runs at like 5 fps (estimated, I havn't actually counted).
    I KNOW this is a graphics thing, because I can make it run quite smoothly by commenting out the code to draw the background/paralax backgrounds... and that code is nothing more complicated than a graphics2d.drawImage
    So obviously I am doing something wrong here... how do I speed this up?
    Code for main class follows:
    import javax.swing.JApplet;
    import java.awt.*;
    import java.awt.image.BufferedImage;
    import java.awt.event.*;
    import Entities.*;
    import Worlds.*;
    // run this applet in 640x480
    public class Orkz extends JApplet implements Runnable, KeyListener
         double x_pos = 10;
         double y_pos = 400;
         int xRes=640;
         int yRes=480;
         boolean up_held;
         boolean down_held;
         boolean left_held;
         boolean right_held;
         boolean jump_held;
         Player player;
         World world;
         BufferedImage buffer;
         Graphics2D bufferG2D;
         int radius = 20;
         public void init()
              //xRes=(int) this.getSize().getWidth();
              //yRes=(int) this.getSize().getHeight();
            buffer=new BufferedImage(xRes, yRes, BufferedImage.TYPE_INT_RGB);
            bufferG2D=buffer.createGraphics();
              addKeyListener(this);
         public void start ()
                player=new Player(320, 240, xRes,yRes);
                world=new WorldOne(player, getCodeBase(), xRes, yRes);
                player.setWorld(world);
               // define a new thread
               Thread th = new Thread (this);
               // start this thread
               th.start ();
         public void keyPressed(KeyEvent e)
              //works fine
         }//end public void keypressed
         public void keyReleased(KeyEvent e)
              //this works fine
         public void keyTyped(KeyEvent e)
         public void paint( Graphics g )
               update( g );
        public void update(Graphics g)
             Graphics2D g2 = (Graphics2D)g;              
             world.render(bufferG2D);                
             g2.drawImage(buffer, null, null);
         public void run()
              // lower ThreadPriority
              Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
              long tm;
              long tm2;
              long tm3;
              long tmAhead=0;
              // run a long while (true) this means in our case "always"
              while (true)
                   tm = System.currentTimeMillis();
                   player.moveEntity();
                  x_pos=player.getXPos();
                  y_pos=player.getYPos();
                  tm2 = System.currentTimeMillis();
                    if ((tm2-tm)<20)
                     // repaint the applet
                     repaint();
                    else
                         System.out.println("Skipped draw");
                    tm3= System.currentTimeMillis();
                    tmAhead=25-(tm3-tm);
                    try
                        if (tmAhead>0) 
                         // Stop thread for 20 milliseconds
                          Thread.sleep (tmAhead);
                          tmAhead=0;
                        else
                             System.out.println("Behind");
                    catch (InterruptedException ex)
                          System.out.println("Exception");
                    // set ThreadPriority to maximum value
                    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
         public void stop() { }
         public void destroy() { }
    }Here's the code for the first level
    package Worlds;
    import java.awt.Color;
    import java.awt.Graphics2D;
    import java.awt.image.BufferedImage;
    import java.util.*;
    import javax.swing.*;
    import javax.imageio.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.io.File;
    import java.net.URL;
    import java.awt.geom.AffineTransform;
    import Entities.Player;
    public class WorldOne implements World
         Player player;
         //Location of Applet
         URL codeBase;
         // Image Resources
         BufferedImage paralax1Image;
         BufferedImage paralax2Image;
         BufferedImage backgroundImage;
         // Graphics Elements     
         int xRes;
         int yRes;
         double paralaxScale1,paralaxScale2;
         double worldSize;
         int frameX=1;
         int frameY=1;
         public WorldOne(Player player, URL codeBase, int xRes, int yRes)
              this.player=player;
              this.codeBase=codeBase;
              this.xRes=xRes;
              this.yRes=yRes;
              worldSize=4000;
            String backgroundImagePath="worlds\\world1Graphics\\WorldOneBack.png";
            String paralax1ImagePath="worlds\\world1Graphics\\WorldOnePara1.png";
            String paralax2ImagePath="worlds\\world1Graphics\\WorldOnePara2.png";
            try
            URL url1 = new URL(codeBase, backgroundImagePath);
             URL url2 = new URL(codeBase, paralax1ImagePath);
             URL url3 = new URL(codeBase, paralax2ImagePath);
            backgroundImage = ImageIO.read(url1);
            paralax1Image  = ImageIO.read(url2);
            paralax2Image = ImageIO.read(url3);
            paralaxScale1=(paralax1Image.getWidth()-xRes)/worldSize;
            paralaxScale2=(paralax2Image.getWidth()-xRes)/worldSize;
            catch (Exception e)
                 System.out.println("Failed to load Background Images in Scene");
                 System.out.println("Background Image Path:"+backgroundImagePath);
                 System.out.println("Background Image Path:"+paralax1ImagePath);
                 System.out.println("Background Image Path:"+paralax2ImagePath);
         }//end constructor
         public double getWorldSize()
              double xPos=player.getXPos();
              return worldSize;
         public void setFramePos(int frameX, int frameY)
              this.frameX=frameX;
              this.frameY=frameY;
         public int getFrameXPos()
              return frameX;
         public int getFrameYPos()
              return frameY;
         public void paralax1Render(Graphics2D renderSpace)
              int scaledFrame=(int)(paralaxScale1*frameX);
              renderSpace.drawImage(paralax1Image,-scaledFrame,0,null); //Comment this to increase performance Massively
         public void paralax2Render(Graphics2D renderSpace)
              int scaledFrame=(int)(paralaxScale2*frameX);
              renderSpace.drawImage(paralax2Image,-scaledFrame,0,null); //Comment this to increase performance Massively
         public void backgroundRender(Graphics2D renderSpace)
              renderSpace.drawImage(backgroundImage,null,null); //Comment this to increase performance Massively
         public void entityRender(Graphics2D renderSpace)
              //System.out.println(frameX);
              double xPos=player.getXPos()-frameX+xRes/2;
             double yPos=player.getYPos();
             int radius=15;
             renderSpace.setColor (Color.blue);
            // paint a filled colored circle
             renderSpace.fillOval ((int)xPos - radius, (int)yPos - radius, 2 * radius, 2 * radius);
              renderSpace.setColor(Color.blue);
         public void particleRender(Graphics2D renderSpace)
              //NYI
         public void render(Graphics2D renderSpace)
              backgroundRender(renderSpace);
              paralax2Render(renderSpace);
              entityRender(renderSpace);
              paralax1Render(renderSpace);
    }//end class WorldOneI can post more of the code if people need clarification. And to emphasize, if I take off the calls to display the background images (the 3 lines where you do this are noted), it works just fine, so this is purely a graphical slowdown, not anything else.
    Edited by: CthulhuChild on Oct 27, 2008 10:04 PM

    are the parallax images translucent by any chance? The most efficient way to draw images with transparent areas is to do something like this:
         public static BufferedImage optimizeImage(BufferedImage img)
              GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();                    
              GraphicsConfiguration gc = gd.getDefaultConfiguration();
              boolean istransparent = img.getColorModel().hasAlpha();
              BufferedImage img2 = gc.createCompatibleImage(img.getWidth(), img.getHeight(), istransparent ? Transparency.BITMASK : Transparency.OPAQUE);
              Graphics2D g = img2.createGraphics();
              g.drawImage(img, 0, 0, null);
              g.dispose();
              return img2;
         }I copied this from a util class I have and I had to modify it a little, I hope I didn't break anything.
    This piece of code does a number of things:
    - it allows the images to be hardware accelerated
    - the returned image is 100% compatible with the display, regardless of what the input image is
    - BITMASK transparent images are an incredible amount faster than translucent images
    BITMASK means that a pixel is either fully transparent or it is fully opaque; there is no alpha blending being performed. Alpha blending in software rendering mode is very slow, so this may be the bottleneck that is bothering you.
    If you require your parallax images to be translucent then I wouldn't know how to get it to draw quicker in an applet, other than trying out java 6 update 10 to see if it fixes things.

  • How to save a drawn image in our own format

    hai,
    i'm developing a designing tool. in that user can draw any type of diagrams. i have to save the drawn image in my own extention... how can i do it. provide me some sample code if u can...

    mituli wrote:
    Thanks,
    but I am using Image.getScaledImage() to get scaled image(obviously). This returns an Image object. When I call getGraphics() on this object it throws an exception:
    Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: getGraphics() not valid for images created with createImage(producer) at sun.awt.image.ToolkitImage.getGraphics(ToolkitImage.java:292)Try using createGraphics() instead.
    In javadoc i found out that this method can be used only on off-screen image. What is off-screen image?Use BufferedImages, you'll have a lot less problems.
    Anyway I can't use this object in ImageIO.write because it requires RenderedImage object which can only be BufferedImage object.
    I tried to cast Image to BufferedImage but can't be ... If you need to get your Image painted onto a BufferedImage, you can do it like this:
    BufferedImage bi = new BufferedImage(myImageWidth, myImageHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D  g = bi.createGraphics();
    g.drawImage(myImage, 0, 0, null);

  • Error-29, Cannot burn a DVD or save a disc image from within FCPX using Mountain Lion

    Really stumped on this one.
    Running Mountain Lion, freshly downloaded version of FCPX, on a 2009 MacPro with 16 G RAM.
    Trying to share a 4 minute movie I edited.
    - No problem exporting as a quicktime move...worked fine
    - Big problem trying to either burn a DVD, save a disc image, or export to an Apple device.
    The progress bar gets about 90% complete, and then it stops and a message window comes up that says:
    There was an error burning your disc. The operation couldn't be completed. (DSPPublishing error-29)
    Thoughts?

    From Crash Analyzer:
    DSPPublishing error -29 (Final Cut Pro X)
    This error can occur when burning a disc if your menu has incompatible assets.
    Suggested Actions
    If your menu has a background image, make sure the image is not too large. Try reducing the size of the image and saving it as a JPEG or PNG.
    Report generated by Crash Analyzer in Pro Maintenance Tools

Maybe you are looking for

  • How to set Default DateTime values in Crystal Reports 2008

    Hi All, I'm using Crystal Reports 2008. I have two fields FromDate and ToDate in reports. While running report, FromDate field should be displayed with CurrentDate + 00:00:00 in the UI and for ToDate it should be displayed with CurrentDate + 23:59:59

  • How to add a custom button on Application Toolbar for ME21N, ME22N & ME23N

    Hi Experts, I am new to this forum. I hope someone will help me. My Requirement is as : I want to add a new custom button on Application Toolbar for ME21N, ME22N & ME23N. There are already standard buttons in this toolbar which is Document Overview O

  • Transfer photos from Mac notebook to iMac

    Best way to transfer Photos from Mac notebook to my imac

  • Plugins and twain for CS5

    I spent four hours trying to find the plugins and twain drivers for CS5 that the "read me" file for CS5 said was available for download. They even gave a link for them.  Finally called them and spent another hour and and a half on the phone and was t

  • Text messages just delete!

    When I am writing a text message and the phone rings, the message just deletes! Does it really delete, or does it just dissapear and I don't know where to find it? Is there no outbox, or drafts folder that I can set up?