×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    47

    Thread image to GIF images J2me

    hi,

    is it possible to have just a threading image to be GIF format?

    As previously jappit mention to me about usng a GIF encoder, but i dont understand how the code works.

    Anyone have any ideas or guides or examples for me to be able to view?


    Thank you in advance

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Thread image to GIF images J2me

    What are you talking about?

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    47

    Re: Thread image to GIF images J2me

    i am asking how to be able to convert a threading image and convert it to GIF and save it in the phone,

    and jappit suggest me using GIF encoder, and i have no clues on how to do it, thus i am asking for help here.

    I am wondering who can provide guides/explanation or examples.

    Thank you

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Thread image to GIF images J2me

    What do you mean by a "threading image"?

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    47

    Re: Thread image to GIF images J2me

    threading image = a canvas which includes threading

  6. #6
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Thread image to GIF images J2me

    OK... I looked back for your original post, so I understand now.

    You want to produce a series of still images, and then build them into an animated GIF, is that correct?

    OK... so, jappit has provided you with sample code for a GIF encoder. But this code requires J2SE libraries, it will not work with MIDP libraries. You will need to alter it to use what libraries are available. I suspect this will not be possible for MIDP1, but should be for MIDP2 (or MIDP1 + Nokia API).

    I'm afraid that code is the guide and example... you could try google for "gif format", if you want to know more about the file structure. Converting the code to MIDP will require some time and effort on your part.

  7. #7
    Registered User
    Join Date
    Nov 2008
    Posts
    47

    Re: Thread image to GIF images J2me

    Hi i am currently using MIDP2.1 so does it means it will be able to work? But do you have any ideas how to be able for me to start on doing to convert to GIF format?

    Thanks for the help =)

  8. #8
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Thread image to GIF images J2me

    Sure...

    You need to add the code jappit gave you to your applications. Your IDE will complain about all the AWT classes (like BufferedImage), because they don't exist in MIDP. Look in the J2SE documents to see what functionality you are missing, then at the MIDP docs to see how you can replace it. For example, using Image.

  9. #9
    Nokia Developer Champion
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Thread image to GIF images J2me

    yup,
    what jappit meant is that j2me doesnt support the gif format itself, so u will need a encoder (not on ur pc or something but in ur midlet itself) to be able to create something like a gif...
    for the rest the explanation given by graham is just self-explanatory actually...

  10. #10
    Registered User
    Join Date
    Nov 2008
    Posts
    47

    Re: Thread image to GIF images J2me

    hi,
    which means that i implement the gif encoder, it will not have errors? j2me support the gif encoder given by jappit? Cause i have no idea about doing this and i really need help badly =( it concern my results.

    Hope you can help and will appreciate it very much

    Thank you

  11. #11
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Thread image to GIF images J2me

    No. In summary...
    • There is no GIF encoder in MIDP
    • The code you have will not work on MIDP
    • You will need to convert the code in the way I described

    There is no alternative to doing the work, and converting the code. If you use an IDE like eclipse, it will help you. It will show you what you need to change. Read the J2SE and MIDP Java Docs, they will help you work out how to change the code.

  12. #12
    Registered User
    Join Date
    Nov 2008
    Posts
    31

    Re: Thread image to GIF images J2me

    hi, those words in red are those error i encounter in netbeans, and i really need help in solving it, i have no idea how to do it =(

    thanks you in advance.

    Code:
        import java.io.*;
        import java.awt.*;
        import java.awt.image.*;
       
    
      
        public class AnimatedGifEncoder {
    
          protected int width; // image size
    
          protected int height;
    
          protected Color transparent = null; // transparent color if given
    
          protected int transIndex; // transparent index in color table
    
          protected int repeat = -1; // no repeat
    
          protected int delay = 0; // frame delay (hundredths)
    
          protected boolean started = false; // ready to output frames
    
          protected OutputStream out;
    
          protected BufferedImage image; // current frame
          protected byte[] pixels; // BGR byte array from frame
    
          protected byte[] indexedPixels; // converted frame indexed to palette
    
          protected int colorDepth; // number of bit planes
    
          protected byte[] colorTab; // RGB palette
    
          protected boolean[] usedEntry = new boolean[256]; // active palette entries
    
          protected int palSize = 7; // color table size (bits-1)
    
          protected int dispose = -1; // disposal code (-1 = use default)
    
          protected boolean closeStream = false; // close stream when finished
    
          protected boolean firstFrame = true;
    
          protected boolean sizeSet = false; // if false, get size from first frame
    
          protected int sample = 10; // default sample interval for quantizer
    
          public void setDelay(int ms) {
            delay = Math.round(ms / 10.0f);      }
    
     
          public void setDispose(int code) {
            if (code >= 0) {
              dispose = code;
            }
          }
    
       
          public void setRepeat(int iter) {
            if (iter >= 0) {
              repeat = iter;
            }
          }
    
     
          public void setTransparent(Color c) {
            transparent = c;
          }
       
          public boolean addFrame(BufferedImage im) {        if ((im == null) || !started) {
              return false;
            }
            boolean ok = true;
            try {
              if (!sizeSet) {
                // use first frame's size
                setSize(im.getWidth(), im.getHeight());
              }
              image = im;
              getImagePixels(); // convert to correct format if necessary
              analyzePixels(); // build color table & map pixels
              if (firstFrame) {
                writeLSD(); // logical screen descriptior
                writePalette(); // global color table
                if (repeat >= 0) {
                  // use NS app extension to indicate reps
                  writeNetscapeExt();
                }
              }
              writeGraphicCtrlExt(); // write graphic control extension
              writeImageDesc(); // image descriptor
              if (!firstFrame) {
                writePalette(); // local color table
              }
              writePixels(); // encode and write pixel data
              firstFrame = false;
            } catch (IOException e) {
              ok = false;
            }
    
            return ok;
          }
    
        
          public boolean finish() {
            if (!started)
              return false;
            boolean ok = true;
            started = false;
            try {
              out.write(0x3b); // gif trailer
              out.flush();
              if (closeStream) {
                out.close();
              }
            } catch (IOException e) {
              ok = false;
            }
    
            // reset for subsequent use
            transIndex = 0;
            out = null;
            image = null;
            pixels = null;
            indexedPixels = null;
            colorTab = null;
            closeStream = false;
            firstFrame = true;
    
            return ok;
          }
    
          /**
           * Sets frame rate in frames per second. Equivalent to
           * <code>setDelay(1000/fps)</code>.
           * 
           * @param fps
           *          float frame rate (frames per second)
           */
          public void setFrameRate(float fps) {
            if (fps != 0f) {
              delay = Math.round(100f / fps);        }
          }
    
     
      
          public void setQuality(int quality) {
            if (quality < 1)
              quality = 1;
            sample = quality;
          }
    
     
          public void setSize(int w, int h) {
            if (started && !firstFrame)
              return;
            width = w;
            height = h;
            if (width < 1)
              width = 320;
            if (height < 1)
              height = 240;
            sizeSet = true;
          }
    
         
          public boolean start(OutputStream os) {
            if (os == null)
              return false;
            boolean ok = true;
            closeStream = false;
            out = os;
            try {
              writeString("GIF89a"); // header
            } catch (IOException e) {
              ok = false;
            }
            return started = ok;
          }
    
       
          public boolean start(String file) {
            boolean ok = true;
            try {
              out = new BufferedOutputStream(new FileOutputStream(file));
              ok = start(out);
              closeStream = true;
            } catch (IOException e) {
              ok = false;
            }
            return started = ok;
          }
    
          protected void analyzePixels() {
            int len = pixels.length;
            int nPix = len / 3;
            indexedPixels = new byte[nPix];
            NeuQuant nq = new NeuQuant(pixels, len, sample);
            // initialize quantizer
            colorTab = nq.process(); // create reduced palette
            // convert map from BGR to RGB
            for (int i = 0; i < colorTab.length; i += 3) {
              byte temp = colorTab[i];
              colorTab[i] = colorTab[i + 2];
              colorTab[i + 2] = temp;
              usedEntry[i / 3] = false;
            }
            // map image pixels to new palette
            int k = 0;
            for (int i = 0; i < nPix; i++) {
              int index = nq.map(pixels[k++] & 0xff, pixels[k++] & 0xff, pixels[k++] & 0xff);
              usedEntry[index] = true;
              indexedPixels[i] = (byte) index;
            }
            pixels = null;
            colorDepth = 8;
            palSize = 7;
            // get closest match to transparent color if specified
            if (transparent != null) {
              transIndex = findClosest(transparent);
            }
          }
    
        
          protected int findClosest(Color c) {
            if (colorTab == null)
              return -1;
            int r = c.getRed();
            int g = c.getGreen();
            int b = c.getBlue();
            int minpos = 0;
            int dmin = 256 * 256 * 256;
            int len = colorTab.length;
            for (int i = 0; i < len;) {
              int dr = r - (colorTab[i++] & 0xff);
              int dg = g - (colorTab[i++] & 0xff);
              int db = b - (colorTab[i] & 0xff);
              int d = dr * dr + dg * dg + db * db;
              int index = i / 3;
              if (usedEntry[index] && (d < dmin)) {
                dmin = d;
                minpos = index;
              }
              i++;
            }
            return minpos;
          }
    
          
          protected void getImagePixels() {
            int w = image.getWidth();
            int h = image.getHeight();
            int type = image.getType();
            if ((w != width) || (h != height) || (type != BufferedImage.TYPE_3BYTE_BGR)) {
              // create new image with right size/format
              BufferedImage temp = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
              Graphics2D g = temp.createGraphics();
              g.drawImage(image, 0, 0, null);
              image = temp;
            }
            pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
          }

  13. #13
    Nokia Developer Champion
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Thread image to GIF images J2me

    those are errors as mentioned by graham, as the compiler is for j2SE and NOT for j2ME !!! Which means that some types, classes, API's and libraries will be missing in j2me cause its a stripped down version of j2se...

    I am afraid u cant expect people here to write the complete code for you, you will have to learn the basics of java programming and/or at least the differences between j2se and j2me (do u even know what those terms mean ?).... Looking at ur questions it seems to me u just thought i'll be making a program which shows gif's and i will be making it on my mobile, even though I dont havve a clue what and how it works...
    I am sorry to give u this bad news : but programming is a quite complex art and u wont be able to learn it overnight...

    good luck tho !

  14. #14
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,405

    Re: Thread image to GIF images J2me

    Hi shirodas,

    to use that code you have to port it from Java SE to Java ME. Specifically, you should port:

    * Color objects to int values (the way colors are handled in Java ME)
    * Graphics2D objects to javax.microedition.lcdui.Graphics
    ones
    * BufferedImage objects to javax.microedition.lcdui.Image
    ones

    For further help, you can also look at the ported code here: http://www.jappit.com/blog/2008/12/0...d-gif-encoder/.

    Pit

  15. #15
    Registered User
    Join Date
    Nov 2008
    Posts
    31

    Re: Thread image to GIF images J2me

    hi jappit
    thanks alot you saved us big time!
    did you do the ported code for us?

    so we just follow the instructions there at your site
    and we can convert into gif already?

    what about the j2SE and jsme porting? do i have to do that step?

    thanks alot

Similar Threads

  1. Replies: 1
    Last Post: 2006-11-15, 07:03
  2. how to cut some part of Image
    By mshouab in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2006-08-04, 09:05
  3. HELP: Mutable Image to Immutable Image?
    By rj_cybersilver in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2005-03-26, 09:58
  4. loading images from device's image folder
    By dotcdotc in forum Symbian Media (Closed)
    Replies: 15
    Last Post: 2004-11-28, 06:58
  5. Using gif image as wallpaper....
    By SkyWire in forum General Development Questions
    Replies: 1
    Last Post: 2004-05-10, 06:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •