×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Jun 2009
    Location
    Tel-Aviv Israel
    Posts
    410

    Creating a javax.microedition.lcdui.Image Image on a J2Se environment

    Hey,
    I have designed a component for J2Me, and here is the paint method:

    Code:
       
        import javax.microedition.lcdui.Graphics;  
        import javax.microedition.lcdui.Image;  
        class Component {
        ...
    	public void paint(Graphics g) {
    		if (background != null)
    			g.drawImage(image, bounds.getLocation().x, bounds.getLocation().y, 0);
    	}
        ...
        }
    I want to paint this component on a J2Se application, I tried to paint the component onto a J2Me Image and extracted the int[] into an InputStream, and create a new image on the J2Se platform, with this object:

    Code:
        public class ComponentStreamer {
        	private Component component;
        	private Image j2Me_Image;
        	
        	public void setComponent(Component component) {
        		this.component = component;
        	}
        	
        	public InputStream getInputStream() throws IOException {
        		if(component==null)
        			return null;
                //THIS LINE THROWS THE EXCEPTION
        		j2Me_Image=Image.createImage(component.getSize().width, component.getSize().height); 
        		component.paint(j2Me_Image.getGraphics());
                    return getImageInputStream(j2Me_Image);
        	}
        }
    I've tried the Object, but the commented line throws an exception:

    Code:
        Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: javax.microedition.lcdui.ImmutableImage.decodeImage([BII)V
        	at javax.microedition.lcdui.ImmutableImage.decodeImage(Native Method)
        	at javax.microedition.lcdui.ImmutableImage.getImageFromStream(Image.java:999)
        	at javax.microedition.lcdui.ImmutableImage.<init>(Image.java:955)
        	at javax.microedition.lcdui.Image.createImage(Image.java:554)
    How can over come this error?
    Thanks,
    Adam Zehavi.

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

    Re: Creating a javax.microedition.lcdui.Image Image on a J2Se environment

    Long time, no see!

    Without getting all the Java docs out... I seem to remember that you need to use a MemoryImageSource to create an Image from a pixel array.

    Graham.

  3. #3
    Regular Contributor
    Join Date
    Jun 2009
    Location
    Tel-Aviv Israel
    Posts
    410

    Re: Creating a javax.microedition.lcdui.Image Image on a J2Se environment

    Hey, Graham, How are you man,

    It has been really long time...

    Thanks again for your help, I'll check this out.

    Adam.
    Thanks,
    Adam Zehavi.

  4. #4
    Regular Contributor
    Join Date
    Jun 2009
    Location
    Tel-Aviv Israel
    Posts
    410

    Question Re: Creating a javax.microedition.lcdui.Image Image on a J2Se environment

    Hey Graham,

    This Was not what I was looking for, the object you described creates many other things but a javax.microedition.lcdui.Image, I need a simple way to be able to create a javax.microedition.lcdui.Image on a J2Se runtime Environment without running the entire J2Me platform, when I do it with the code I posted in my initial post I get the error I posted "java.lang.UnsatisfiedLinkError".

    do you have any other ideas? it is crucial to create a javax.microedition.lcdui.Image!

    Thanks,
    Adam.
    Thanks,
    Adam Zehavi.

  5. #5
    Regular Contributor
    Join Date
    Jun 2009
    Location
    Tel-Aviv Israel
    Posts
    410

    Re: Creating a javax.microedition.lcdui.Image Image on a J2Se environment

    Well, I found a work around.

    I added a delegate to my image loading process on the J2Me application, which uses a J2SeImmutableImage from the microemulator 2.0.3, I got it from maven, and I loaded a the image like this:

    this is on the J2Me platform, runs both on emulator and J2Se application for loading the images:

    Code:
    public final class PlatformImageLoader {
    	public static interface ExternalImageLoader {
    		Image loadImage(String filePath);
    	}
    	private static ExternalImageLoader imageLoader;
    	
    	public static void setImageLoader(ExternalImageLoader imageLoader) {
    		PlatformImageLoader.imageLoader = imageLoader;
    	}
    	public static final String MaterialDirectory = "/materials";
    	public static final Image loadMaterialImage(String path) throws IOException {
    		if(imageLoader!=null)
    			return imageLoader.loadImage(path);
    		InputStream is = PlatformImageLoader.class.getResourceAsStream(MaterialDirectory + path);
    		return Image.createImage(is);
    	}
    }
    and here is the delegate to load the images on the J2Se platform:
    Code:
    PlatformImageLoader.setImageLoader(new ExternalImageLoader() {
    			
    	@Override
    	public Image loadImage(String filePath) {
    		String fullFilePath = getCurrentProject().getExternalMaterialsDirectory().getFile().getAbsolutePath().replace(File.separator, "/")+filePath;
    		File imageFile = new File(fullFilePath);
    		J2SEImmutableImage image;
    		try {
    			image = new J2SEImmutableImage(ImageIO.read(imageFile));
    			return image;
    		} catch (IOException e) {
    			e.printStackTrace();
    			throw new J2MeRuntimeException("Unable to load image",e);
    		}
    	}
    });
    I'm sure someday someone would thank me for this...

    thanks for your help.
    Thanks,
    Adam Zehavi.

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

    Re: Creating a javax.microedition.lcdui.Image Image on a J2Se environment

    Sorry, yes, there is no such class, you have to use a java.awt.Image. You can write your own javax...Image class if you want, to wrap the awt equivalent, if you need source code compatibility with MIDP.

    But... you'd figured that out already...

Similar Threads

  1. javax.microedition.lcdui.TextField not displayed on E75
    By javanerd.com.au in forum Mobile Java General
    Replies: 1
    Last Post: 2009-11-12, 07:35
  2. javax.microedition.lcdui.List and unexpected IndexOutOfBoundsException
    By patrick@onestep.co.uk in forum Mobile Java General
    Replies: 0
    Last Post: 2008-03-14, 17:56
  3. Text wrapping in javax.microedition.lcdui.List
    By DrChandra in forum Mobile Java General
    Replies: 4
    Last Post: 2006-04-15, 01:21
  4. App Closed javax.microedition.lcdui...
    By jinesh_l in forum Mobile Java General
    Replies: 3
    Last Post: 2005-09-10, 13:53
  5. Porting javax.microedition.lcdui.game to Midp 1.0
    By ktorimaru in forum Mobile Java General
    Replies: 5
    Last Post: 2004-02-04, 18:54

Posting Permissions

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