×

Discussion Board

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

    Adding text into picture [J2ME]

    Hi, my name is shiro.
    i'm currently using Netbeans j2ME
    and doing a application whereby using mutableimage and combine the text into the picture.

    kind of like the photo editor in the phones today.
    "adding text into photos"

    currently my problem is when i set the text into the image
    it paints the image but not my text.

    this is my code for the paint method under MutableImage class

    Code:
    public void paint(Graphics g) {
            clearScreen(g);
            
            if (originalImage != null && text.equalsIgnoreCase("")){
                //create a mutable Image
                Image modifiedImage = Image.createImage(originalImage.getWidth(), originalImage.getHeight());
                
                Graphics modifiedGraphics = modifiedImage.getGraphics();
                System.out.println(modifiedGraphics.toString()+" modifiedGraphics1");
    //copy the original image into the mutable one
                modifiedGraphics.drawImage(originalImage, 0, 0, Graphics.LEFT | Graphics.TOP);
                
    //set the Font you prefer
                modifiedGraphics.setFont(Font.getDefaultFont());
                modifiedGraphics.setColor(255,255,255);
                System.out.println(originalImage +"asd");
                g.drawImage(originalImage, getWidth() / 2, getHeight() / 2, Graphics.VCENTER | Graphics.HCENTER);} 
            else if(originalImage != null){
               
                System.out.println(" modifiedGraphics2");
                //create a mutable Image
                Image modifiedImage = Image.createImage(originalImage.getWidth(), originalImage.getHeight());
                
                Graphics modifiedGraphics = modifiedImage.getGraphics();
                System.out.println(modifiedGraphics.toString()+" modifiedGraphics");
                Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
          modifiedGraphics.setFont(font);
    //copy the original image into the mutable one
                modifiedGraphics.drawImage(originalImage, 0, 0, Graphics.LEFT | Graphics.TOP);
    //set the Font you prefer
                modifiedGraphics.setFont(Font.getDefaultFont());
                modifiedGraphics.setColor(255,255,255);
                g.drawImage(originalImage, getWidth() / 2, getHeight() / 2, Graphics.VCENTER | Graphics.HCENTER);
                
                //draw the text over the original image content
    
                    g.drawString(text, 0, 0, Graphics.BASELINE | Graphics.LEFT);
                modifiedGraphics.drawString(text, x, y, Graphics.TOP | Graphics.LEFT);
                System.out.println(text +" text");}
    
        }

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Adding text into picture [J2ME]

    Hi,
    What I understand is just you want to write the string over the image...Right

    So simply you can draw that string over the image..like
    @ First draw the image..then
    @ Draw the string on the image.

    refresh the screen..
    Thats all I guess will be enough..what is the point of what you have done..Can u explain..
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

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

    Re: Adding text into picture [J2ME]

    Quote Originally Posted by raj_J2ME View Post
    Hi,
    What I understand is just you want to write the string over the image...Right

    So simply you can draw that string over the image..like
    @ First draw the image..then
    @ Draw the string on the image.

    refresh the screen..
    Thats all I guess will be enough..what is the point of what you have done..Can u explain..
    Thanks,
    yup correct...
    thats what i want to do.
    and under the code that i previously shown, i draw the image first, then, draw the text down.
    but the text doesn't appear still.

    Another thing to note is that the text that i input, will be adjustable in position by the user. Means that after inputting the text, the user can adjust the place of the text.

    Cheers

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Adding text into picture [J2ME]

    Hi,
    Another thing to note is that the text that i input, will be adjustable in position by the user. Means that after inputting the text, the user can adjust the place of the text.
    What do you mean..
    Did you mean that user will enter the text and he will then set the position of the same..like if he wants to draw on x=100 and y=200..then he will do so.next time he can enter some other values for the two params..right..
    Make a quick reply..
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

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

    Re: Adding text into picture [J2ME]

    Quote Originally Posted by raj_J2ME View Post
    Hi,

    What do you mean..
    Did you mean that user will enter the text and he will then set the position of the same..like if he wants to draw on x=100 and y=200..then he will do so.next time he can enter some other values for the two params..right..
    Make a quick reply..
    Thanks,
    the structure is kind of like. user press "add text"
    then type the text that he wants.
    then, the text will appear infront of the image.
    next, the keypress up,down,left,right will allow the user to change the position of the text itself
    after the position is confirmed, user pressed ok command
    and the text will be combined into the image.

    current i'm stuck at the appearing of the text on the image, after user input. While, using mutable image method
    however, previously when i use SVG images and array method, my program is able to run until the positioning of text, means after user input, user CAN choose the position using up,down,left,right keypress.

    Thanks

  6. #6
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Adding text into picture [J2ME]

    Hi,
    Yeah Now it is a clear approach indeed..
    I can give you idea..check whether it is feasible for you or not.

    int origXOffset = someValue,int origYOffset = someValue;
    Graphics.drawImage(ImageToDraw,origXOffset,origYOffset,o);

    In keypressed I am gonna change the x and y params.I am changing the x param on LEFT/RIGHT and y param on UP/DOWN pressed..however you can do it as per your need..right..

    case LEFT:
    origXOffset -= someValueForDec;
    break;
    case RIGHT:
    origXOffset -= someValueForDec;
    break;
    case LEFT:
    origYOffset -= someValueForDec;
    break;
    case LEFT:
    origYOffset -= someValueForDec;
    break;

    case OK_PRESSED:
    origXOffset = origXOffset ;
    origYOffset = origXOffset ;
    break;

    continuously you can keep in painting the canvas..ok
    I hope these lines can help you..
    I am not touching your image creation concept..
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

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

    Re: Adding text into picture [J2ME]

    Quote Originally Posted by raj_J2ME View Post
    Hi,
    Yeah Now it is a clear approach indeed..
    I can give you idea..check whether it is feasible for you or not.

    int origXOffset = someValue,int origYOffset = someValue;
    Graphics.drawImage(ImageToDraw,origXOffset,origYOffset,o);

    In keypressed I am gonna change the x and y params.I am changing the x param on LEFT/RIGHT and y param on UP/DOWN pressed..however you can do it as per your need..right..

    case LEFT:
    origXOffset -= someValueForDec;
    break;
    case RIGHT:
    origXOffset -= someValueForDec;
    break;
    case LEFT:
    origYOffset -= someValueForDec;
    break;
    case LEFT:
    origYOffset -= someValueForDec;
    break;

    case OK_PRESSED:
    origXOffset = origXOffset ;
    origYOffset = origXOffset ;
    break;

    continuously you can keep in painting the canvas..ok
    I hope these lines can help you..
    I am not touching your image creation concept..
    Thanks,
    Thanks alot!! the code will helps greatly in the future!

    but the current problem is before that actually, somehow my text can't even be shown in the picture, after user input.
    if i use g.drawString, i am able to draw the text out.
    but if i use modifiedGraphics.drawString, which is a must for mutable image method, i can't draw it.
    and i HAVE to use mutable image, for the later part of the program.

    and the details of the code is shown in my first post.
    so as to show what i mean.

    Thanks ^^

  8. #8
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Adding text into picture [J2ME]

    Hi,
    You must use this line
    getGraphics() once ..why You are using it twice...any reason please tell me..however let me check it ..
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

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

    Re: Adding text into picture [J2ME]

    Quote Originally Posted by raj_J2ME View Post
    Hi,
    You must use this line
    getGraphics() once ..why You are using it twice...any reason please tell me..however let me check it ..
    Thanks,
    yes i have two getGraphics.
    but it is under the if/else case
    so its different condition

  10. #10
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Adding text into picture [J2ME]

    Hi shiro,
    Can you please tell me in which condition it is coming..since what i have noticed that you have only draw the string in else..if it is coming in else then it is okey but if it is coming in else then your string will not be displayed..

    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

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

    Re: Adding text into picture [J2ME]

    Quote Originally Posted by raj_J2ME View Post
    Hi shiro,
    Can you please tell me in which condition it is coming..since what i have noticed that you have only draw the string in else..if it is coming in else then it is okey but if it is coming in else then your string will not be displayed..

    Thanks,
    yea thats true.
    i put the drawString in else is because
    previously when i run the program, the system.out.println
    shows it went into the else condition.
    thus, the drawString is there only
    XD

  12. #12
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Adding text into picture [J2ME]

    Hi shiro,
    One more thing I wana highlight to you..(However you must be,since you have done that code)...is that you are using two different graphics objects..one is local modifiedgraphics and another is g...I am sure you are miss matching the two graphics objects..since I have also face this problem of two graphics objects. I was using 2 graphics objects and my rendering was not as I was looking for...

    Thats I ask you to tell me the reason of using the graphics reference like this..
    Am I clear to you..??
    Thanks
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

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

    Re: Adding text into picture [J2ME]

    Quote Originally Posted by raj_J2ME View Post
    Hi shiro,
    One more thing I wana highlight to you..(However you must be,since you have done that code)...is that you are using two different graphics objects..one is local modifiedgraphics and another is g...I am sure you are miss matching the two graphics objects..since I have also face this problem of two graphics objects. I was using 2 graphics objects and my rendering was not as I was looking for...

    Thats I ask you to tell me the reason of using the graphics reference like this..
    Am I clear to you..??
    Thanks
    yup
    i used modified and g
    but g is solely for testing whether it paints anot.
    its only a temporary variable.
    while the real graphic object that i wan is modified.

    when i use g.drawString it prints, but modified.drawString it doesn't.

    moreover, i paste the SOP to check whether modified is NULL anot.
    its not null.

  14. #14
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Adding text into picture [J2ME]

    Hi,
    Thats what I am trying to explain to you.Why do not think that control will come in paint every time and it will create a new object of graphics.

    What wrong can be done if you use only g instead of modifiedgraphics.I dont think that there will be anything wrong..even it is good idea...rather then creating so many objects you will be creating it just once..right..

    If you dont mind then can you put the code here..complete source code..I am sure that it is the only problem..sure..due to graphics reference ..
    Am I clear.?
    Thanks
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

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

    Re: Adding text into picture [J2ME]

    Quote Originally Posted by raj_J2ME View Post
    Hi,
    Thats what I am trying to explain to you.Why do not think that control will come in paint every time and it will create a new object of graphics.

    What wrong can be done if you use only g instead of modifiedgraphics.I dont think that there will be anything wrong..even it is good idea...rather then creating so many objects you will be creating it just once..right..

    If you dont mind then can you put the code here..complete source code..I am sure that it is the only problem..sure..due to graphics reference ..
    Am I clear.?
    Thanks
    ok sure, this is our Connect class
    Code:
    package animationMaker;
    import java.io.IOException;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.*;
    
    import java.lang.*;
    import java.io.*;
    import java.util.*;
    
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    import javax.microedition.rms.*;
    import javax.microedition.media.*;
    import javax.microedition.m2g.ScalableGraphics;
    import javax.microedition.m2g.ScalableImage;
    
    //A first MIDlet with simple text and a few commands.
    public class Connect extends Canvas implements CommandListener {
        
        //The exit commands
        private Command exitCommand;
        private Command connectCommand;
        private Command startCommand;
        private mainMenuMidlet midlet;
        //The display for this MIDlet
        private Display display;
        Form displayForm;
        private ScalableImage background;
        private mainCanvas mainCanvas;
        private TextBox textBox;
        
        public Connect(mainMenuMidlet m, Display d, ScalableImage background) {
            //display = Display.getDisplay(this);
            this.background= background;
            midlet=m;
            display= d;
            exitCommand = new Command("Exit", Command.SCREEN, 0);
            connectCommand = new Command("OK", Command.OK, 1);
            startCommand = new Command("Confirm", Command.OK, 1);
        }
        public Connect(mainMenuMidlet m, Display d, ScalableImage background, mainCanvas mainCanvas) {
            mainCanvas = this.mainCanvas;
            //display = Display.getDisplay(this);
            this.background= background;
            midlet=m;
            display= d;
            exitCommand = new Command("Exit", Command.SCREEN, 0);
            connectCommand = new Command("OK", Command.OK, 1);
            startCommand = new Command("Confirm", Command.OK, 1);
        }
        
        public void startApp() {
        }
        
        public void paint(Graphics g) {
            clearScreen(g);
            textBox = new TextBox("Please enter your message", "Text: ", 256, 0);
            textBox.addCommand(connectCommand);
            textBox.setCommandListener(this);
            display.setCurrent(textBox);
            
            displayForm = new Form("Welcome to Text Displayer");
            displayForm.addCommand(exitCommand);
            displayForm.setCommandListener(this);
            displayForm.append(showResults(textBox.getString().substring(textBox.getString().indexOf("Name:") +5).trim()));
        }
        
        
        public void pauseApp() {
        }
        
        // Destroy must cleanup everything not handled
        // by the garbage collector.
        // In this case there is nothing to cleanup.
        public void destroyApp(boolean unconditional) {
        }
        
        public void commandAction(Command c, Displayable s) {
            if (c == exitCommand) {
                destroyApp(true);
                //notifyDestroyed();
            } else if(c == connectCommand) {
                try{
                    
                    Image       originalImage = Image.createImage("/picture/background2.png");
                    //originalImage = Image.createImage(80,20);
                    System.out.println(originalImage.toString()+" originalImage123");
                    String text= textBox.getString().substring(textBox.getString().indexOf("Text:") +5).trim();
                    //   MutableImage mi = new MutableImage(midlet,display,background,text);
                    mainCanvas= new mainCanvas(midlet,display,background,text,originalImage);
                    //  mainCanvas.append("Welcome, " + textBox.getString().substring(textBox.getString().indexOf("Text:") +5).trim());
                    
                    //  mainCanvas.setTitle(textBox.getString().substring(textBox.getString().indexOf("Text:") +5).trim());
                    // mainCanvas.displayForm.append(textBox.getString().substring(textBox.getString().indexOf("Text:") +5).trim());
                    display.setCurrent(mainCanvas);
                }catch(IOException e){
                    e.printStackTrace();
                }
                
            } else if(c == startCommand) {
                displayForm.append(showResults(textBox.getString().substring(textBox.getString().indexOf("Text:") +5).trim()));
                display.setCurrent(displayForm);
            }
        }
        
        
        String showResults(String string) {
            String result = "";
            try {
            } catch (Exception exc) {
                exc.printStackTrace();
            }
            return result;
        }
        private void clearScreen(Graphics g) {
            g.setColor(0xFFFFFF);
            g.fillRect(0,0,getWidth(),getHeight());
        }
    }
    This connect code simply does the text input action.
    user will be brought to this page and input his text.

Similar Threads

  1. Rendering text in multiple languages
    By TheLittleBird in forum Symbian
    Replies: 0
    Last Post: 2007-06-05, 12:52
  2. Adding Chinese Text to an Existing Midlet
    By ktorimaru in forum [Archived] Other Programming Discussion 关于其他编程技术的讨论
    Replies: 2
    Last Post: 2005-04-07, 21:00
  3. text in picture message
    By jdado in forum Smart Messaging
    Replies: 1
    Last Post: 2002-10-29, 07:55
  4. adding a text line to a dialog
    By cl_jp in forum Symbian User Interface
    Replies: 1
    Last Post: 2001-12-05, 15:20

Posting Permissions

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