Displaying a image on mobile using canvas

hi all...
im new to j2ME and i need help on how to display an image on mobile using canvas. I've tried using the following codes.. however when i tried to run on my toolkit, i hit this error:
Unable to create MIDlet MyCanvasDrawings
java.lang.IllegalAccessException
     at com.sun.midp.midlet.MIDletState.createMIDlet(+19)
     at com.sun.midp.midlet.Selector.run(+22)
Im not too sure of wads is the problem with my codes. Here's my codes:
import javax.microedition.lcdui.*;
public class MyCanvasDrawings extends Canvas
private Display display;
public MyCanvasDrawings(Display display)
     this.display = display;
public void paint(Graphics g)     
{//paint
     Image img = Image.createImage("testImage.png");
     g.drawImage(img,getWidth()/2, getHeight(), g.HCENTER|g.VCENTER);
}//paint     
}

import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class MyCanvasDrawings extends Canvas
     public MyCanvasDrawings()
     public void paint(Graphics g)
     {//paint
          Image img1 = null;
               try {
                    img1 = Image.createImage("/ProcureprofitLogo1.jpg");
               //     img1 = Image.createImage("/welcomeText3.jpg");
               } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
          g.drawImage(img1,getWidth()/2, 130, g.HCENTER|g.VCENTER);
     }//paint
But i dont know how to add command

Similar Messages

  • Display the images in excel using jsp

    Hi
    I am unable to display the images in excel using jsp. I can display the data. but cannot display the images. It is simply showing the icon without the image. Is there any way to display the images. Pls give some sample code to display the images in excel.
    Thanks in advance.

    Presumably whoever created the images in that Excel document just put links to somewhere on their hard drive. Those links don't mean anything when you put the document on somebody else's computer, which is what you are doing. At least, that is my guess.
    You could spend some time looking at the Excel file to see how the images were put in there. Or you could ask the person who put the images in there.

  • Can't display an image with SWT using J9

    Hello,
    I'm programming a user interface using SWT and J9 as JVM under Window Mobile 5.0
    Everything seems to work more or less fine with SWT widgets, but I can't display any Image.
    I've tried the following codes :
    Image image = new Image(display,getClass().getResourceAsStream("image.bmp"));when placing image.bmp in the same jar that my main class, or in the same folder when not using a jar file.
    and
    Image image = new Image(display,"\\image.bmp");(when placing image.bmp in the root folder)
    I've tried with a gif file, it doesn't work neither.
    Both codes work fine in my normal computer (replacing "//image.bmp" by "C://image.bmp" for instance)
    Any help would be highly appreciated ;-)
    Message was edited by:
    cOsi

    Here is a basic example to display image and make it flicker. Use it and try to improve to get the exact frame rate you want.
    Remember this is not the actual solution, its just to give you an idea.
    The best solution is the one you find it by yourself
    Attachments:
    Flicker.vi ‏8 KB

  • I want to display BLOB image in JSP Using  html tags IMG src=

    GoodAfternoon Sir/Madom
    I Have got the image from oracle database but want to display BLOB image using <IMG src="" > Html tags in JSP page . If it is possible than please give some ideas or
    Send me sample codes for display image.
    This code is ok and working no problem here Please send me code How to display using html tag from oracle in JSP page.
    <%@ page import="java.sql.*" %>
    <%@ page import="java.io.*" %>
    <%@ page import="javax.swing.ImageIcon;" %>
          <%
            out.print("hiiiiiii") ;
                // declare a connection by using Connection interface
                Connection connection = null;
                /* Create string of connection url within specified format with machine
                   name, port number and database name. Here machine name id localhost
                   and database name is student. */
                String connectionURL = "jdbc:oracle:thin:@localhost:1521:orcl";
                /*declare a resultSet that works as a table resulted by execute a specified
                   sql query. */
                ResultSet rs = null;
                // Declare statement.
                PreparedStatement psmnt = null;
                  // declare InputStream object to store binary stream of given image.
                   InputStream sImage;
                try {
                    // Load JDBC driver "com.mysql.jdbc.Driver"
                    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
                        /* Create a connection by using getConnection() method that takes
                        parameters of string type connection url, user name and password to
                        connect to database. */
                    connection = DriverManager.getConnection(connectionURL, "scott", "root");
                        /* prepareStatement() is used for create statement object that is
                    used for sending sql statements to the specified database. */
                    psmnt = connection.prepareStatement("SELECT image FROM img WHERE id = ?");
                    psmnt.setString(1, "10");
                    rs = psmnt.executeQuery();
                    if(rs.next()) {
                          byte[] bytearray = new byte[1048576];
                          int size=0;
                          sImage = rs.getBinaryStream(1);
                        //response.reset();
                          response.setContentType("image/jpeg");
                          while((size=sImage.read(bytearray))!= -1 ){
                response.getOutputStream().write(bytearray,0,size);
                catch(Exception ex){
                        out.println("error :"+ex);
               finally {
                    // close all the connections.
                    rs.close();
                    psmnt.close();
                    connection.close();
         %>
         Thanks

    I have done exactly that in one of my applications.
    I have extracted the image from the database as a byte array, and displayed it using a servlet.
    Here is the method in the servlet which does the displaying:
    (since I'm writing one byte at a time, it's probably not terribly efficient but it works)
         private void sendImage(byte[] bytes, HttpServletRequest request, HttpServletResponse response) throws IOException {
              ServletOutputStream sout = response.getOutputStream();
              for(int n = 0; n < bytes.length; n++) {
                   sout.write(bytes[n]);
              sout.flush();
              sout.close();
         }Then in my JSP, I use this:
    <img src="/path-to-servlet/image.jpg"/>
    The name of the image to display is in the URL as well as the path to the servlet. The servlet will therefore need to extract the image name from the url and call the database.

  • JPEG images on mobile

    How can i display JPEG images on mobile phone (i.e. Nokia3410)? Can i use JPEGDecoder for this purpose and will it work? If anyone has allready written this code can you provide me with piece of it.

    I tried the server route, but a 30kb JPEG becomes a 210kb PNG, and for downloading over the air on a cell phone, that 7x increase is a painful problem. Downloading the JPEG directly to the J2ME device is definitely the way to go. Pretty lame that J2ME doesn't currently support JPEG natively.
    After many nights of searching the Net for an answer to this question, a kind soul pointed me to the following site, which is 80% of the answer we're looking for:
    http://webuser.fh-furtwangen.de/~dersch/
    Helmut Dersch
    has written/ported a JPEG Decoder that can run in J2ME:
    JPEGDecoder: pure-Java JPEG-Decoder for limited Java APIs (e.g. J2ME)I know that it works (he has a sample app that actually runs on my Treo with a panoramic JPEG image loaded from the resource files). Unfortunately, I haven't been smart enough to write the code yet that would download a JPEG off the web and render it on the screen (without all the Panoramic stuff). Should be simple, though.
    I am sure that it will take 90 seconds for one of you smart folks. If you actually write the code to do this, PLEASE post the source code so that all of us will learn!
    Thanks!!!

  • How to Display an Image in swing

    I Want to display an image in swing using the scrollPane, so I can scroll an image in a box

    A very simple way is to use a JLabel :
    JLabel label = new JLabel(new ImageIcon("myImage.jpg"));
    JScrollPane scroller = new JScrollPane(label);

  • Help displaying an image using the canvas!!!!!!!!

    Hey guys
    I don't know whether I am not grasping some concepts well.I have been going mad trying to get the code working
    Here is the code
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.io.*;
    * @author Administrator
    * @version
    public class MyMIDlet extends javax.microedition.midlet.MIDlet implements CommandListener{
    private Display display;
    private MyCanvas canvas;
    private Command exitcommand = new Command("Exit",Command.SCREEN,1);
    private Image source;
    public MyMIDlet() {
    protected void startApp() throws MIDletStateChangeException{
    if (display == null){
    initMIDlet();
    protected void pauseApp() {
    protected void destroyApp(boolean unconditional)throws MIDletStateChangeException {
    exitMIDlet();
    public void commandAction(Command c, Displayable d) {
    if (c == exitcommand){
    exitMIDlet();
    protected void initMIDlet() {
    display = Display.getDisplay(this);
    canvas = new MyCanvas(this);
    System.err.println("Canvas instiated succesfully");
    canvas.addCommand(exitcommand);
    canvas.setCommandListener(this);
    display.setCurrent(canvas);
    public void exitMIDlet() {
    notifyDestroyed();
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    import java.io.*;
    public class MyCanvas extends Canvas implements Runnable {
    private MIDlet midlet;
    private Image offscreen;
    private Image currentimage;
    private Graphics g;
    //MID profile application
    /** Creates a new instance of MyCanvas */
    public MyCanvas(MIDlet midlet) {
    this.midlet = midlet;
    try{
    currentimage = Image.createImage("/bird0.png");
    }catch(IOException e){
    System.err.println(e.getMessage());
    if (currentimage!= null){
    System.err.println("Image create successfully");
    }else{
    System.err.println("Image not created");
    try{
    Thread t = new Thread(this);
    t.start();
    }catch(Execption e){}
    protected void paint(Graphics g){
    Graphics saved = g;
    int x = getWidth();
    int y = getHeight();
    g.setColor(255,255,255);
    g.drawImage(currentimage,x,y,g.TOP|g.VCENTER);
    public void run() {
    repaint();
    I know for a fact that the Canvas class 's paint method is called by the system and not the application. This poses a problem for me because I am not sure how to pass the image to the piant method, so that it can be painted.
    When I run the program(using J2ME wtk04), this is the outcome.
    Image created succesfully
    Canvas instiatiated successfully
    null
    Here are my questions
    1) when is the paint method precisely called by the system?after a reference to the canvas class is created?
    2) is it wise to create the image when instiating the canvas class?( initially created the image using a separate thread)-when sould the image be created?
    3)how to let the application know when to use the image when painting the display area?
    I am just trying the logistics here. It is very crucial to me to understand the bolts of this as the core f my project fouses on the man machine interface development.(For the project, the cilent application is quering for the map using HTTP)
    I use a png file of size 161 bytes. Is that too big for testing purposes.
    I would all the help that I can get. thanks in advance

    1) when is the paint method precisely called by the system?after a reference to the canvas class is created?
    After the canvas is set as the current display, and after that, after the repaint() is called.
    2) is it wise to create the image when instiating the canvas class?( initially created the image using a separate thread)-when sould the image be created?
    It's better to create the image in the very begining of the program e.g. in the midlet initialization. You can call the created image as often as you like later on
    3)how to let the application know when to use the image when painting the display area?
    you have to tell it :))
    you can use if-then, switch, or anything else
    and you can use clipping too

  • Using JSR 75 FileConn API + JSR 135 to display an image

    Hi Guys:
    How would one select an image file (let's say JPEG) from a folder that is exposed on a device and then resize and display on screen using a midlet.
    Do you read the file using JSR 75 FileConn API and the transform it using JSR 135 and the display?
    Also can reading a large or high res image file cause an out of memory exception?
    Thanks in advance!

    I don't know if your already found a solution.
    You are correct about the fact that you need JSR75 to load the file. Then to show it on screen you can use the Image class and use a form or a canvas to show it. What I don't know is how to resize it to fit the screen. And also I guess you can't open large files with it.
    To load the image i use this code:
    public Image image;
    DataInputStream is;
    is = new DataInputStream(Connector.openDataInputStream(fileName));
    image=Image.createImage(is);Take into account that every time a file is opened, a security warning will appear asking for permission. As far as I know it can't be avoided unless you sign your application with a certificate.
    Is it useful for you?
    Marc

  • Display image in full screen canvas

    Hi frndz
    I have an Image, which either bigger in size of a canvas or small
    I want to give an option of a full screen view
    So its a kind of zoomIn/ zoomOut function in one method
    how can I convert such small/big images into full screen canvas size
    thanks
    alpesh

    This question has been asked already several times here: http://onesearch.sun.com/search/onesearch/index.jsp?qt=resizing+image&subCat=siteforumid%3Ajava76&site=dev&dftab=siteforumid%3Ajava76&chooseCat=javaall&col=developer-forums
    There is no method in MIDP which rescales a picture for you, so you have to write it on your on (or use existing code). But usually this would be pretty slow. Mostly it is better to offer different versions of your application for different devices (screen resolutions) where the images have already the appropriate size within your jar-file.

  • How can I use the print module to print different size images on one large "canvas"?

    How can I use the print module to print different size images on one large "canvas"? An example would be in Photoshop, go to file>new, and create the size paper I want, and move images of different sizes onto it.
    I was thinking the print module would do this automatically for me.

    You can't, at present. It's been a requested feature, so we'll see if it shows up in a future version, but it's not there at present.

  • Problem with displaying BLOB images on JSP page using a servlet

    hi. I have a big problem with displaying BLOB images using JSP. I have a servlet that connects to the oracle database, gets a BLOB image , reads it, and then displays it using a BinaryStream. The problem is , this works only when i directly call that servlet, that is http://localhost:8080/ImageServlet. It doesn't work when i try to use that servlet to display my image on my JSP page (my JSP page displays only a broken-image icon ) I tried several coding approaches with my servlet (used both Blob and BLOB objects), and they work just fine as long as i display images explicitly using only the servlet.
    Here's what i use : ORACLE 10g XE , Eclipse 3.1.2, Tomcat 5.5.16 , JDK 1.5
    here is one of my image servlet's working versions (the essential part of it) :
                   BLOB blob=null;
              rset=st.executeQuery("SELECT * FROM IMAGES WHERE ID=1");
              while (rset.next())
                   blob=((OracleResultSet)rset).getBLOB(2);
              response.reset();
              response.setContentType("image/jpeg");
              response.addHeader("Content-Disposition","filename=42.jpeg");
                    ServletOutputStream ostr=response.getOutputStream();
                   InputStream istr=blob.getBinaryStream(1L);
                    int size=blob.getBufferSize();
              int len=-1;
                    byte[] buff = new byte[size];
                         while ((len=istr.read( buff ))!=-1 ) {
                   ostr.write(buff,0,len);
             response.flushBuffer();
             ostr.close(); and my JSP page code :
    <img src="/ImageServlet" border="0"  > If you could just tell me what i'm doing wrong here , or if you could show me your own solutions to that problem , i would be very greatful ,cos i'm realy stuck here , and i'm rather pressed for time too. Hope someone can help.

    I turns out that it wasn't that big of a problem after all. All i had to do was to take the above code and place it into another JSP page instead of into a servlet like i did before. Then i just used that page as a source for my IMG tag in my first JSP. It works perfectly well. Why this doesn't work for servlets i still don't know, but it's not a problem form me anymore . Ofcourse if someone knows the answer , go ahead and write. I would still appriceatte it.
    here's the magic tag : <img src="ImageJSP.jsp" border="0"  > enjoy : )

  • Does anyone know how to display (in LabVIEW) the memory use during execution of an image and data acquisition VI to predict when it is time to cease the acquisition to prevent the program crashing?

    Does anyone know how to display (in LabVIEW) the memory use during execution of an image and data acquisition VI to predict when it is time to cease the acquisition to prevent the program crashing?
    I am acquiring images and data to a buffer on the edge of the while loop, and am finding that the crashing of the program is unpredictable, but almost always due to a memory saturation when the buffers gets too big.
    I have attached the VI.
    Thanks for the help
    Attachments:
    new_control_and_acquisition_program.vi ‏946 KB

    Take a look at this document that discusses how to monitor IMAQ memory usage:
    http://digital.ni.com/public.nsf/websearch/8C6E405861C60DE786256DB400755957
    Hope this helps -
    Julie

  • How to display a image in webdynpro view using a bytearry

    Hi Frndz..
    How to display an image in a view using webdynpro java ..i have bytearry object in context ..like
    *byte[] img = wdContext.nodeYywwwdataImport_Input().nodeOutput().nodeOutMime().currentOutMimeElement().getLine();*_
    by using this i need to show image in view..
    Kindly help me ....
    Thankas in Advance
    Regards
    Rajesh

    Hi,
    byte[] img = wdContext.nodeYywwwdata_Import_Input().nodeOutput().nodeOutMime().currentOutMimeElement().getLine();
    use this code to create resource and you need to set this value to the context created to display the image suppose in the image UI and set the source property with this attribute:-
    IWDResource res=WDResourceFactory.createCachedResource(b,"MyImage",WDWebResourceType.JPG_IMAGE);
    IPrivateAppView.IVn_ImageTabElement imageEle=wdContext.createVn_ImageTabElement();
           imageEle .setVa_Name(res.toString());
    wdContext.nodeVn_ImageTab().addElement(imageEle);
    Hope this may help you.
    Deepak

  • I've just bought a Macbook Pro 15" and I'm trying to use Photoshop, but the resolution its displaying the images at for 100% are too small. I have to design for the web, so need to be intricate with detail, but I'm finding it adjusts the resolution of the

    I've just bought a Macbook Pro 15" and I'm trying to use Photoshop, but the resolution its displaying the images at for 100% are too small. I have to design for the web, so need to be intricate with detail, but I'm finding it adjusts the resolution of the image right down. (I mean you can see the image clearly, but it's too small to edit). When I look at Safari and see a web page at 100% it's clear, but the same page displayed in Photoshop CC appears 50% of the size (even though it says it's 100%)   If I move the application window to another screen it adjusts it correctly  – leaving all the pallettes, menus and tools correctly sized as they are on the retina display   Is there some way to adjust the way Photoshop CC displays images so it is more consistent with what you actually see?   There doesn't seem to be any answer on the Adobe forum, so hopefully someone here can shed some light.  MacBook Pro with Retina display, 15", OS X Yosemite (10.10.2), Photoshop CC 2014

    I tested both ways. With "open in low resolution" ckecked the size of the images is cool, but it is low-resolution including Photoshop appearance.
    If "open in low resolution" is unckecked the appearance is good but the very small size.
    See the image below. It has 650 x 732 px, 72 dpi. The font of the text "Neste aniversário ..." is with 18pt.

  • How to display an image on the HTML page by using applet

    Dear friends,
    I am now writing an java applet, I want to display an image on the HTML page, and tried the following commands:
    {color:#ff00ff}{color:#000000}Image map; //put in the class definition
    map=getImage(getCodeBase(),"hhh.gif"); //put in the function of init()
    g.drawImage(map,0,300,this); //put in the function of paint(){color}
    {color}
    However, when I run it, the image wasn't displayed at all.
    I hope who guys ever come across this problem could help me to solve it. Thank you in advance!
    Hawaii

    Hi,
    I am no expert on Images
    but
    from personal exp.
    are you sure that map actually contains the image?
    try using
    ImageIcon ii = ImageIcon(String name);
    map = ii.getImage();I saw a tutorial on images i think on sun
    where they use ImageIcon to load the image

Maybe you are looking for

  • CST or VAT determination automatically in sales order

    Dear all, I want to determine the CST or VAT both in a single sales order for different Items based on plant regions and customer region. for more details let me give you an example. I have,            2 plants - A(Maharashtra), B(Delhi)            C

  • Help with spry tabbed menu bar

    Hi. I need help with the spry tabbed menu panel (horizontal) It works fine in dreamweaver ( pressing f12 ) but when i goto my website www.so-nouveau.com it puts it all over and not in boxes either just the writing. I ahve double checked all uploading

  • Taking Long Time in Posting - PR & PO

    Hi All, Since Last 5-6 days in Posting of Purchase Requisition (T-Code- ME51N, ME54N) & Posting of PO (T-Code- ME21N) taking too much time in production system, almost post a single document it takes 10 minutes else all T-Codes working fine. plz help

  • How can I solve these connection problems in Mail 3.2?

    I have an iBook G4 that is running Leopard (10.5.2). I use it at home via an Airport connection and at work via a direct ethernet connection or router. I have the only Mac in my office. Within Mail I have set up my .Mac account as IMAP, and also impo

  • Group messaging since iOS 5 update

    I strongly dislike the group messaging feature, where all recipients in a group text receive replies from everyone. I had this fixed a long time ago by simply turning this feature off. Since the update (not sure if it started with iOS5 or 5.0.1), it