drawing text on BitmapField

Hi all

I'm having a problem with BitmapField.

I'm tring to draw text on the scope of the Bitmap.

The purpose of this is that if the field has the focus, change image and attract white text and vice versa.

But it seems that the text drawing image behind.

Please help me on this.

Thank you

DK.

Here is the code:

        ttsField = new BitmapField(tab_off, BitmapField.FOCUSABLE|BitmapField.FIELD_RIGHT|
                BitmapField.FIELD_VCENTER)

        {
            protected void layout(int maxWidth, int maxHeight)
            {
                    super.layout(tab_on.getWidth()+2, tab_on.getHeight());
                    setExtent(tab_on.getWidth()+2, tab_on.getHeight());
            }
            public void onFocus(int direction){
                //invalidate();
                setBitmap(tab_on);
                    hasFocus = true;
                    //super.onFocus(direction);
            }
            public void onUnfocus(){
                    hasFocus = false;
                    //invalidate();
                    super.onUnfocus();
                    setBitmap(tab_off);

            }
        protected void paint(Graphics g)
        {
            if (g.getBackgroundColor() != 3098850)
            {
                g.setBackgroundColor(0xfafafa);
                        g.clear();
            }
            super.paint(g);
        }
        protected void drawFocus(Graphics g, boolean on)
        {
//          if (hasFocus)
                g.setColor(0xffffff);

                g.setFont(Utils.BBMillBankTall(12, Font.BOLD));
                g.drawText("Text to Speech", 0, 0);
                super.paint(g);
            }

        };

You have your sequence of events backwards.

Call the super.paint (first), then the text above the image bitmap drawText().

Tags: BlackBerry Developers

Similar Questions

  • How to draw text above a picture

    Hello

    How do I draw text above an image. It will work - substitution of the paint the field and using drawText (0, -10) method.

    -10 means that the text will be drawn 10 pixels above the image.

    It depends on the method you are using:

    If you decide to drawText in the charts (the hard), you would be better to check the length of the text before drawing it (getFont () .getAdvance (text), is what you will use for this), in the positioning of your custom field. This can become quite complicated, especially if you are concerned about the return to the line and other things.

    If you go to VerticalFieldManager approach and want the text field to wrap text properly, use, say, RichTextField for this BitmapField for your image and ensure that they have the style flags you can (for example, say, FIELD_HCENTER for centering them vertically; there are a of others, but you do not have to worry with them now) IMHO). In this way, that everything will be done automatically for you. And, as I said before, VerticalFieldManager respect the margins of fields.

  • Draw text on the graphic waveform Plot

    I need to understand how to draw text on a waveform graph during execution. This could be a text box, a picture of the text, a label and an additional plot with text... etc.

    Yes, I know a graph would be better than this, but need to use a graphic for my application.

    The graph is updated every second, and new data are added to the history of the ranking. (Which means that the chart bigger every second) So if I draw the text above or behind the table, I'll have to update their location every second. I'll have to use card to XY Coords in an event, (mousedown or mouseup) to place the text (or image of the text) in the field where the user clicked.

    Step 1 to resolve this problem is to find first class, learn how to draw or text on the plot of the graph area.

    Does anyone have ideas of how this could be accomplished, or some ideas of a sneaky work around to make this work?

    Example:

    Unfortunately, graphics (graphic and graphic waveform XY) have support Annotation and slider, exposed programmatically through properties, but the array of waveform is not.

    What you could do is to place an indicator of 2D image that corresponds to the size of the chart above.  Make the value of the image that you draw be transparent and just print the text with transparent backgrounds.  However, I do not know the considerations on the performance of it - many times user interface elements, overlap (portions of even transparent) can cause problems of performance due to forcing redesigns... then again maybe a graph is always be redrawn in any case.

  • How to draw text bordered on Bitmap usgin class Graphics?

    Hi guys.

    I'm drawing text on a line graph.

    Here is the example.

    The text color is black. Border is white (edge of letters).

    How to draw like this?

    Thanks in advance.

    If you are interested in a vaguely similar effect, but without all the subtle shadows, I have a suggestion. Draw the white text, several times, gap between the nominal position of a pixel or two in different directions and then draw the text in black at the nominal position. The idea is that white copies create an enlargement of each letter which becomes an overview when you draw the black letter on it. You may need to do this a letter at a time, allowing more space between the letters, rather than draw the entire chain at the same time.

  • Draw text within the rectangle in OpenGL

    I want to draw text in a rectangle and I also need to make sure that the text does not go beyond the limit. Can someone give me some idea/advice for this problem in OpenGL?

    Yes on the link below.

    https://github.com/BlackBerry/NDK-samples/tree/next/HelloWorldDisplay

  • Draw text on the XY graph

    Hello

    There is a technique to draw a text note on graph XY.

    For example the text "AAAAAA" put near the upper left of the XY graph.

    Thank you.

    Previous version is wrong: this only works if an annotation already exists on the chart.

    If no annotation it does not work.

    Here is the solution for the empty graph:

  • Draw texts or Images as background in camera

    Hi all, I want to create a BB10 application that uses the camera feature.

    Can I draw a text or pictures in the background in the camera?

    I thank you all.,.

    I think you wanted to say overlay and not background? connection with the camera will cover probably the majority of the content displayed on the screen...

    If you meant overlay, check out ForeignControl:

    https://developer.BlackBerry.com/Cascades/reference/bb__cascades__foreignwindowcontrol.html

    and the following sample app:

    HelloVideoCamera

    Just add content on top of the foreignwindowcontrol

  • How to draw text on a single line?

    Hello

    Is there a way to draw a string so that it fits on the screen?

    I'm working on a MIDlet application that has a class that extends the canvas. I want to paint a line of text, but the text is a bit too long so that it cannot be seen entirely on some devices.

    I put the police to be "Font.getFont (Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_SMALL);"

    As a more general question, how do the even smaller than SIZE_SMALL police?

    Many thanks for any help!

    Does the work with image. Thank you very much!

  • Draw text with different fronts in a RichTextField

    Hello

    Is it possible to use a rich text field to draw different text in different fonts. I can change the color of the fonts by the function

    graphics.setColor ();

    in the painting method but I can't change the font.

    Another thing... I want to create a line which contains several elements... like 2 bitmaps, 3 different texts, etc... I have manged to make horizontal use and vertical field managers... the problem is that it takes too long to make... and jerks... scrolling so I m using the paint function draw all these things in one control... but I can't seem to divide the text into two lines if the text exceeds the width of the screen... is it possible to do and does not affect performance.

    Sorry for the long post...

    Thank you

    Found! Field of ActiveRichText!

    Code following (not mine)

    compensates for the int [] = new int [] {0, 5, 12};
    Police fonts1 [] = new make [] {Font.getDefault (), Font.getDefault ()};
    int bg [] = new int [] {Color.BROWN, Color.WHITE};
    int fg [] = new int [] {Color.BLACK, Color.GREEN};
    Byte [] attributes = new byte [] {0, 1};

    mainScreen.add (new ActiveRichTextField ("Hello \nworld", offsets, attributes, fonts1, fg, bg, 0));

  • The paint on BitmapField text

    Hello again"

    I have a little experience of the development of BB. I need to paint text on BitmapField for my application.

    Do you have a code example? Please help me guys. Good day.

    TNX'

            String logoBitmap = "mobiyana.png";
            String logoString = "mobiyana.com";
    
            logo = Bitmap.getBitmapResource(logoBitmap);
    
            Graphics graphics = new Graphics(logo);      int xOffset = (logo.getWidth() - Font.getDefault().getAdvance(logoString)) / 2;
            int yOffset = (logo.getHeight() - Font.getDefault().getHeight()) / 2;
    
            graphics.setColor(Color.WHITE);
            graphics.drawText(logoString, xOffset, yOffset);
    
            add(new BitmapField(logo));
    
  • Text Diagnal of drawing on the screen

    I'm new to Blackberry. Could you please help me Center of Diagnal drawing text to the screen

    Hi @ramachandra9345

    Welcome to the forum.

    I think that you would have to create a bitmap image and write the text on it and then rotate the bitmap image.

    You can create a new Bitmap using the Bitmap class, and then create an instance of graphics with your bitmap:

    Image bitmap bitmap = new Bitmap (...);

    Graphics g = Graphics.create (bitmap);

    g.drawText (...);

    To rotate the bitmap image, take a look here:

    http://supportforums.BlackBerry.com/T5/Java-development/rotate-and-scale-bitmaps/Ta-p/492524

    Hope that helps,

    E.

  • In any case to draw the width of the text?

    Hi all

    I use the graphics graphics card to draw text. Anyway, it is short of the width of the string to be drawn. Because I want to draw another string after that string in the same horizontal line. Thank you

    Download the police, then:

    defaultFont.getAdvance ("my text");

    This property returns an integer.

  • Bitmap text point

    Hello guys '

    I have little problem. It is: I created BitmapField and then added scree.

    ------------------------------------------

    _bitmapScreen = new BitmapField();
               
    verMngr.add (_bitmapScreen);
    horMngr.add (verMngr);

    ------------------------------------------

    Then load image JPG to BitmapField. It works.

    Image bitmap bitmap = createImage (data);

    data are massive byte: byte data [];

    Graphics graphics = new Graphics (bitmap);

    int xOffset = (logo.getWidth () - Font.getDefault () .getAdvance (logoString)) / 2;

    int decalage_y = (logo.getHeight () - Font.getDefault () .getHeight ()) / 2;

    graphics.setColor (Color.WHITE);

    graphics.drawText ("TEXT" x_offset, decalage_y);

    Finally:

    _mapScreen._bitmapScreen.setBitmap (bitmap); This line doesn't work well?

    I think that printing text 'TEXT' on bitmapField. But he does not draw the text.

    Is there a solution? Guy

    TNX

    TNX a lot ' guys, I found my mistake.

  • ToolTip under the bitmapField

    Hello world

    I want to create the ToolTip under the bitmapfield when it has the focus...

    I don't want to use pop-up screen for this.

    When focus on the field of the bitmap to draw the rectangle with the drawrect method and

    Subsequently he draws text using the method drawtext graphics.

    It is the display text and rect in the graphics area, but it is not the rect in the region of graphics to display outside.

    It is possible to display text in draw and draw the rectangle graphics elsewhere?

    and how to add a graphics area in the field of the bitmap image?

    all comments will be appropriate.

    Thank you

    You can use the screen paint method to do that (we solved it like this)

  • How to clear the text on the image

    Hello

    I have a screen with the background image (bitmap). I draw the text and other images on this background to aid graphics object and all looks ok when I show the screen - but only the first time because the next time background image is one containing all these designs on it.

    I would like to know if it is possible to erase these drawings, so next time I can use background image to draw top again?

    I use something like this:

    String fText = "Text";
    
    fBackground = Bitmap.getBitmapResource("background.png")
    
    fGraphics = new Graphics (fBackground );
    
    fvm1 = new VerticalFieldManager()
    {     
    
    public void paint(Graphics graphics)
    {
       fGraphics.drawText(fText, 0, 0);
    
       graphics.drawBitmap(0, 0, fBackground.getWidth(),  fBackground.getHeight(), fBackground, 0, 0);
    
       super.paint(graphics);
    }
    }
    

    Next time I want to draw text 'Text2' so I change variable fText to "Text2". How can I remove the 'Text' text before doing this?

    Thanks in advance.

    You really want to paint on the bitmap background to show change data.

    One of the most obvious solutions is to have fields for that--both the LabelField and RichTextField are good for displaying text, BitmapField is good to display bitmaps (use setBitmap to change the image), GaugeField is ideal for the indication of the percentage, etc..  Add the fields to your VerticalFieldManager, use the margins and the bits of style such as FIELD_HCENTER to space and position them the way you want and enjoy. When comes a new value to display, change the field matching and nullity. This is the right way to do these things.

    Of course-, since you seem to be attached to the use of the graphics directly - the quick and dirty approach is just to paint directly on the screen using the Graphics object passed in object.  Something like this:

    fBackground = Bitmap.getBitmapResource("background.png")
    
    // fGraphics = new Graphics (fBackground );
    
    fvm1 = new VerticalFieldManager()
    {     
    
    public void paint(Graphics graphics)
    {
       // fGraphics.drawText(fText, 0, 0);
    
       graphics.drawBitmap(0, 0, fBackground.getWidth(),  fBackground.getHeight(), fBackground, 0, 0);
       graphics.drawText(fText, 0, 0); // plus any other draws...
       super.paint(graphics);
    }
    }
    

    Of course, you must also override sublayout() to this VerticalFieldManager to properly define its dimensions.

    However, doing it this way is really strange. You must be something much simpler than a VerticalFieldManager to paint in it (expand, replace its layout() setExtent() correctly and his object to do any painting you need - do not call the super.paint (), it is abstract) or you add fields to it as usual and let the super.paint () do its job.

Maybe you are looking for

  • The mail app leaves unexpectadly

    The mail application that closes unexpectedly

  • google search gives results in Chinese

    When I get a few things to look for in the upper right corner, using the Google search engine. The result are shown in characters of Chinas. Then I go to the website of google and enter the same search elements on their homepage, the results appear i

  • How to order recovery of product for my Satellite M60 - 104?

    Hello I have a portable Satellite M60-104. I want to recovery of product, however, I seem to have lost my product recovery dvd. Is there anyway where I can re - order one for this laptop, or download from internet (if so, where!) Thank you Sunny

  • Prolems of hard drive

    I have one machine that when I insert the disc of windows to install gos in the blue screen of death once windows starts to load. I can't use any disk to start I get the same screen. For this reason, I can't format the hard drive to a new copy of win

  • Need driver of Bus SM for HP Pavilion G6-1b60us controller

    I had to replace the hard drive on my HP Pavilion G6 1b60us, reinstalled an operating system of Windows 7, but finds it difficult to get a driver for the SM Bus controller.  I tried other solutions suggested in the forums for those having a similar p