Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
RAMON_SOLER
Posts: 67
Registered: ‎11-14-2010
My Device: 9900 7.0 PAQUETE 2395 (V7.0.0.579,PLATAFORMA 5.0.0.735)
Accepted Solution

Label field barcode font to bitmap

i create a barcode usin font ttf 128 and others i would like to create a bitmap image to save he image how van be done

_logField.setText(_barcodeTextField.getText());

                        try {
                                upcFont128 = UtilIDAutomationHC128.get1dFont();
                                _logField.setFont(upcFont128);
                             // here the routine 
// Bitmap a
                        } catch (Exception e) {
                                Dialog.alert(e.toString());

                        }

 

Please use plain text.
Developer
peter_strange
Posts: 19,607
Registered: ‎07-14-2008
My Device: Not Specified

Re: Label field barcode font to bitmap

Following are general instructions if you want to create a Bitmap Image using that Font.

1) Use getAdvance(<text> and getheight() to determine how big the Bitmap needs to be

2) create a Bitmap that size (new Bitmap(....);

3) Create a graphics Object for the bitmap - use static create(<bitmap>) method

4) drawText(...) onto the graphics object created

 

Now you have a Bitmap with your Text painted on to it. 

 

Hope this is clear. 

Please use plain text.
Regular Contributor
RAMON_SOLER
Posts: 67
Registered: ‎11-14-2010
My Device: 9900 7.0 PAQUETE 2395 (V7.0.0.579,PLATAFORMA 5.0.0.735)

Re: Label field barcode font to bitmap

Here i arrive but it dont know clearly how to set values some help pls

int tamañoCB=_logField.getHeight();
                                String textoCB=_logField.getText();
                                int width = Display.getWidth();
                               // int X = _logField.getAdvance(); 
                              //  int height = Display.getHeight();

                                
                                 Bitmap bm = new Bitmap(width, tamañoCB);
                                 Graphics graphics = new Graphics(bm);
                                 graphics.drawText(textoCB, 0 ,tamañoCB , 0 , width);
                                 BitmapField CampoBC = new BitmapField(bm,BitmapField.FOCUSABLE );
                                 UiApplication.getUiApplication().getActiveScreen().add(CampoBC);
                                 UiApplication.getUiApplication().getActiveScreen().invalidate();

 

Please use plain text.
Developer
peter_strange
Posts: 19,607
Registered: ‎07-14-2008
My Device: Not Specified

Re: Label field barcode font to bitmap

I may have misunderstood what you want to do.  Can you please explain again what you are trying to do and why?

Please use plain text.
Regular Contributor
RAMON_SOLER
Posts: 67
Registered: ‎11-14-2010
My Device: 9900 7.0 PAQUETE 2395 (V7.0.0.579,PLATAFORMA 5.0.0.735)

Re: Label field barcode font to bitmap

What i want is to save an image with the barcode generated 

tks 

r.soler

Please use plain text.
Developer
peter_strange
Posts: 19,607
Registered: ‎07-14-2008
My Device: Not Specified

Re: Label field barcode font to bitmap

Save it where?

Please use plain text.
Regular Contributor
RAMON_SOLER
Posts: 67
Registered: ‎11-14-2010
My Device: 9900 7.0 PAQUETE 2395 (V7.0.0.579,PLATAFORMA 5.0.0.735)

Re: Label field barcode font to bitmap

Location does not matter what I want is to get the bitmap of the label field
Thks
Please use plain text.
New Contributor
abuwarez
Posts: 3
Registered: ‎09-24-2012
My Device: latest bold 9???

Re: Label field barcode font to bitmap

[ Edited ]

You need to call graphics.setFont(Barcode font) before calling graphics.drawText().

 

Smth like this:

 

PSEUDOCODE:

Font upcFont128 = UtilIDAutomationHC128.get1dFont();
int width = upcFont128.getAdvance(-your-bracode-text-here-);

Bitmap b = new Bitmap(width, upcFon128.getHeight(Ui.UNITS_px));

Graphics g = new Graphics(b);
g.setFont(upcFont128);
g.drawText(-your-bracode-text-here-, 0, 0);

diplay bitmap ...
Please use plain text.
Developer
peter_strange
Posts: 19,607
Registered: ‎07-14-2008
My Device: Not Specified

Re: Label field barcode font to bitmap

Hopefully the previous post answers your question.

 

"Location does not matter"

I think you might find it does.  If you want to save an Object, then you might be able to save a Bitmap in persistable store.  If you want to convert the image to a file that that you can send to the host, or save on SD Card, then you will need to encode the Bitmap into a format like png to save it.  There are various Threads on the forum that talk about doing this. 

 

I wonder if you really only need to save the text rather than the image?

Please use plain text.
New Contributor
abbyyy
Posts: 4
Registered: ‎04-12-2013
My Device: none

Re: Label field barcode font to bitmap

If you want create barcodes in Bitmap format (Bitmap barcodeInBitmap = barcode.drawBarcode():smileywink:, you may refer to this tutorial.

Please use plain text.