How to resize the Bitmap when running?

Hello

I created a Bitmap that reads directly from a file. The actual size of the image (test.png) is 360 x 50. I displayed this bitmap image in a BitmapField.  Now, I want to display this image in my application so that it should take the width of the screen and adjust (expand or compress) so based on the TILT of the device (in the case of BB storm). My code is as below:

{
   Bitmap image = Bitmap.getBitmapResource("mainmenu_green.png");
    BitmapField bmpMainMenu = new BitmapField(image);

    MenuScreenVFM verticalManager = new MenuScreenVFM();
    verticalManager.add(bmpMainMenu);
    add(verticalManager );
}

//MenuScreenVFM  Class..
 static class MenuScreenVFM extends VerticalFieldManager
 {
        // Constructor
        private MenuScreenVFM()
        {
            super(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR | VerticalFieldManager.FIELD_HCENTER);
        }

       net.rim.device.api.ui.container.VerticalFieldManager#sublayout(int,int)
         */
        protected void sublayout(int width, int height)
        {
            int nTop = 65;
            Field field = getField(0);
            layoutChild(field, Display.getWidth(), 40);
            setPositionChild(field, 0, nTop);
            setExtent( Display.getWidth(), Display.getHeight());
        }
}

The image must stretch/compress based on the width of the screen. Any info/code would be really appreciated.

Thank you

-DK

I created a CustomBitmapField extends the field and for the scaling of the image, I used the following code:

   public static EncodedImage scaleImageToWidth(EncodedImage encoded, int newWidth) {
             return scaleToFactor(encoded, encoded.getWidth(), newWidth);
   }

    public static EncodedImage scaleImageToHeight(EncodedImage encoded, int newHeight) {
           return scaleToFactor(encoded, encoded.getHeight(), newHeight);
    }

    public static EncodedImage scaleToFactor(EncodedImage encoded, int curSize, int newSize) {
         int numerator = Fixed32.toFP(curSize);
         int denominator = Fixed32.toFP(newSize);
         int scale = Fixed32.div(numerator, denominator);

         return encoded.scaleImage32(scale, scale);
    }

  protected void paint(Graphics graphics) {
        graphics.setColor(backgroundColour);
        graphics.drawImage(0, 0, Display.getWidth(), fieldHeight,   this.scaleImageToWidth(bmpBG, Display.getWidth()), 0, 0, 0);
           }

I would like to know if it works... If works please set Bravo... that will encourage those who post the solution

Kind regards

-DK

Tags: BlackBerry Developers

Similar Questions

  • How to resize the Bitmap

    I have a bitmap with lets say the size 200 x 100 and I want to create a bitmap with size 200 x 200 and the first bitmap to be drawn in the news and have offset of 50px from the top and bottom of the new bitmap?

    How can I do this and be compatible with OS > = 4.6. I see in the OS 5.0, we have a method scaleInto in the class Bitmap - http://www.blackberry.com/developers/docs/5.0.0api/

    Yes, in this way, the obstacle is buffer of the Blackberry chart which is available only twice the size of the screen.

    Another option is to obtain Bitmap of RGB and that put the RGB right in the right place int this new Bitmap.

  • How to load the list when running

    hiiiiii I have total 100 events list...

    But first, I have 20 events display when I scroll the list down when I reached 20 events th I load another 20 events to the list please give me suggestions to do this to me...

    If you have all 100 items available then you should put all the entries in the ListField.

    In situations when not all are available and you must get them (from a server), a little at a time, then you might have a 'Next' button and allows to do the treatment.  Without doubt, you also need a 'Back' button  I wouldn't try to drive it when the user scrolls to the end of the list.  Because there is a long delay, get the 'next page', I think that instead of using a user interface there different - people expect a scroll to be instant.

  • How to resize a textFrame, when resizing as its parent (a groupitem)?

    I am trying to find the smallest textframe within a group and then match that textframe font size to the minimum size allowed for printing. Everything works, except that I can't understand how to resize the textframe when resizing as its parent, the group.

    #target illustrator

    app.activeDocument = docRef;

    gpRef = docRef.groupItems [0];

    var gpHeight = gpRef.height;

    It's printing allowed minimum font size

    var minFntSize = 18;

    var garbLay;

    var txtFrmCount = gpRef.textFrames.length;

    var container = {};

    var i;

    put each prop textframe and height in json

    for (i = 0; i < txtFrmCount; i ++) {}

    container ["prop" + i] = {"gpTfHeight':gpRef.textFrames [i] .height / 72, 'gpTarget':gpRef.textFrames [i]"};

    }

    find the value prop textframe height min. I have the max in it too just in case I need it in the future

    var min = infinity;

    var max = - infinity;

    var x;

    for (x in container) {}

    If (container [x] ['gpTfHeight'] < min) {}

    min = container [x] ["gpTfHeight"];

    minTg = container [x] ["gpTarget"];

    }

    If (container [x] ['gpTfHeight'] > max) {}

    Max = container [x] ["gpTfHeight"];

    }

    }

    duplicate textframe, convert in way and get the actual height

    var txtFrmDup = minTg.duplicate ();

    txtFrmDup.position = [(minTg.position[0]-100), (minTg.position [1] - 100)];

    txtFrmDup.name = "garbage."

    var tOutline = txtFrmDup.createOutline ();

    tOutline.name = "garbage."

    var tLogHeight = Math.round (tOutline.height);

    garbLay = gpRef.groupItems.getByName ('garbage');

    This is the part where I need to convert it into percentage? tgSize is the size of the target and I thought I could get the different from the 2 and then use this amount to resize down...

    var tgSize = minFntSize - tLogHeight;

    var PERC = Math.round((tgSize/gpRef.height)*100);

    $.writeln (minFntSize);

    $.writeln (tLogHeight);

    $.writeln (tgSize);

    $.writeln (perc);

    resize gp so that font textframe min size meets minFntSize

    if(tLogHeight < minFntSize) {}

    gpRef.resize (perc, perc);

    $.writeln ('smaller');

    garbLay.remove ();

    } else if(tLogHeight > minFntSize) {}

    gpRef.resize (perc, perc);

    $.writeln ('bigger');

    garbLay.remove ();

    } else if(tLogHeight == minFntSize) {}

    $.writeln ('equal');

    }

    I do not know if I go about it the right way. Hoping a new set of eyes can take a look and see what I'm doing wrong or not done? Thank you!

    check this out, I changed it a bit

    // scale grouped text Frames to a minimum font size
    // http://forums.adobe.com/thread/1323065?tstart=0
    // carlos canto
    
    #target illustrator
    
    var docRef = app.activeDocument;
    var gpRef = docRef.groupItems[0];
    
    //this is the minimum print font size allowed
    var minFntSize = 18;
    
    var txtFrmCount = gpRef.textFrames.length;
    
    // make the first frame the one with the minimum font size
    var idx = 0;
    var minFrameFontSize = gpRef.textFrames[idx].textRange.characterAttributes.size;
    
    // see if the other frames have smaller font size than the first
    for(i = 1; i < txtFrmCount; i++) {
        var itext = gpRef.textFrames[i];
        var fontSize = itext.textRange.characterAttributes.size;
        if (fontSize		   
  • How to load a picture of the XYgraphs when running

    Hello everyone.  I need to load a picture of the XYgraphs when running.  Each element of the array is a collection, an item is an XY Chart.  Each curve on its own XYgragh is generated as part of a search optimization.  The number of curves generated based on input from the user during execution.  Resulting curves can be sorted by the user according to different criteria.  Using the sorted curves, the user selects one or more games associated with operating conditions.  So, only 1 curve by graphic, as each curve has its own functioning conditions who were responsible of his generation (the other members of the collection).

    When I try to connect the data a little test vi, I get the error listed... that seems to be complaining that my data types match actually! ??

    Thanks a bunch

    Terry

    Look more closely at your data types.  Upstairs, you have two tables 1 d of double grouped.  While done in a 1 d table.  It is a pink cluster, transformed into a table 1 d of pink cluster.

    Look at the empty table going into the shift register.  Your XY graph is a table 1 d with a bunch of Brown.  This Brown cluster consists of two double scalars, not the two table 1 d double you up there.

    In your loop For on the top, try to convert the blue Angelfish in doubles, then the two values to group together.  Feed this cluster at the edge of the loop For and auto-index on this tunnel. Now, you will have a table 1 d with a bunch of doubles.  Which feed the element of the XY cluster at the bottom.

  • How to resize the dialog box that runs everything in baGetFolder order.

    Dear friends

    I'm very new Director and in collaboration for the project which is already developed by some other providers. in this project, I have to implement the mentioned below requirment so someone can pls help me on this will be greatfull.

    How to resize the dialog box that appears while baGetfolder command triggers. Actualluy problem that I face is that the title of the dialog box extends its width so the title turns out to be incomplete with «...» ", how can I solve this problem? It's very urgent requirment and eagely waiting for your response.

    Thanks in advance

    So how about:

    gBackPath = baGetFolder("/", "Veuillez sélectionner un répertoire de
    sauvegarde pour les fichiers de votre base de données: ", 1, "", 100, 50)
    

    (Note that the parameter 'options' has been changed to 1)

  • need to know how to block the ophcrack from running, my child uses this to get my password and in the parental controls in vista

    you want to know how to block the ophcrack from running, my child uses this to get my password and in the parental controls in vista. I have 3 accounts going 2 for children and one for the parents/administrator. I found ophcrack in several places on the computer. any help would be greatly appreciated

    The only question the idea of Malkeleah, that is when you put a password on BIOS, all you need to do is pop the battery from the motherboard and the password is gone. Faronics has in some programs such as anti-executable and a few other programs that may block the name or ID of a process and prevent it from running (some antiviruses have that option, such as Avast, but usually is a pain in the ass to configure)

  • How to resize the image to ImageSnapshot?

    Hey guys... so im taking a picture of a movie clip using ImageSnapshot.captureBitmapData (myClip);

    I need to resize the bitmap data that I'll be back, the size must be 720 X 486

    the code I have is...

    var myClip:MovieClip = event.target as MovieClip;
    
    var imageBitmapData:BitmapData = ImageSnapshot.captureBitmapData(myClip);
    var pngEncode:PNGEncoder = new PNGEncoder();
    var ba:ByteArray = pngEncode.encode(imageBitmapData);
    

    any ideas? I tried to use the matrix.scale, but I guess I did not understand how to use wisely...

    any help is greatly appretiated!

    Thank you

    Hello

    so why sleep going

    This function will just take your display object and return to what you want to spend the final width you need and it works the scaling for you, you could do more complex comparing say the width and the final height to calculate the "best fit" but well...

    David.

    private function scale (content: DisplayObject, width: int): BitmapData

    {

    var scale:Number = width/content.width;

    var BD: BitmapData = new BitmapData(content.width*scale,content.height*scale);

    var mt:Matrix new matrix());

    Mt.Scale (Scale, Scale);

    EDI Draw(Content,MT);

    Return to comics;

    }

  • My Dungeon AT100 flashing (gel) / how to enlarge the fonts when browsing

    I tried to disable my Tablet (AT100), but he keep re-reading as 'opening line of light sparkles' and then a 'flash '. He continues by doing this.

    I tried to turn if off, but I can't.

    I tried to recharge the battery, but there is nothing to change.

    I had to wait for these to be repeated until all batteries are brains.

    Why would this happen? What's wrong?

    What can I do, when this happen? Reboot? but I can't find those restart button (as these mini button that allows you to push a pencil point)

    ~*~*~*~*~*~*~*~*~*~*~*~
    How to enlarge the fonts when I'm surfing the internet?

    Thank you.

    Post edited by: ec

    Hello

    I think the sparks of light line is a background image possibly the Android system crashed I think you should start in safe mode.
    How?

    1. press the power button and quickly press and hold the Volume button down.
    2. continue to press the Volume button down until you enter secure Mode

    Now you can perform factory reset data as below:
    Tap applications > settings > privacy > data reset > Reset tablet > clear all.
    Factory data collection will be

  • How to set the title when using InvokeManager (MediaPlayer)

    Hi Im using InvokeManager to play the video file (Media Player)

    How to change the title when media player to play the video (above)-> it by default uses the name of the file being played

    but I want to change this

    How to do this?

    Thank you

    Try this

    InvokeManager * invokeManager = new InvokeManager();
    InvokeRequest cardRequest;
    cardRequest.setTarget ("sys.mediaplayer.previewer");
    cardRequest.setAction ("bb.action.OPEN");
    cardRequest.setUri ("* video url *");
                QVariantMap map;
    Map.Insert ("contentTitle", "My title");
    QByteArray requestData = bb:psObject::encode (map, NULL);
    cardRequest.setData (requestData);
    Response InvokeTargetReply * = invokeManager-> invoke (cardRequest);

    Note: Mark your post as solved, if this solves your problem

  • does anyone know how to number the photos when they are exported so someone can choose the peak of number

    Anyone know how to number the photos when they are exported from LR, so someone can choose the photo they like with a number

    Sorry took with the last answer.

    More simple form used something like-Sequence_Filename number suffix

    If an image as _ABC0987.nef will become 0001_0987.nef and 0002_0988.nef, etc.

    Ask your customer to give you the full file name. The suffix indicates the original file.

    (I hope that you only need to search in a folder and do not have a bunch of images named the same that would cause problems!)

  • How to display the ToolTip when the input text is disable

    How to display the ToolTip when the input text is disable?

    Just checked in FF and IE11, works fine for me (jdev 12.1.3)

    
          
    
    

    Dario

  • How to generate the alert when pageitem move on the page? and what class boss be use to move pageitem

    How to generate the alert when pageitem move on the page? and what class boss be use to move pageitem

    Hi Philippe,.

    You can see the kDocBoss for the ClassID with the PMIID IID_ITRANSFORM_DOCUMENT kLocationChangedMessage.

    Markus

  • Anyone know how to solve the problem, when he says scratch disk is full?

    Anyone know how to solve the problem, when he says scratch disk is full? don't do anything :/

    Go to Edition > purge > all

    This will clear all of your history and Clipboard, thus freeing the scratch disk space.

  • How to resize the print size of an item within my PDF to multiple pages? For example a receipt or another image that can scan in bigger or smaller than my 8.5 x 11 Bill?

    How to resize the print size of an item within my PDF to multiple pages? For example a receipt or another image that can scan in bigger or smaller than my 8.5 x 11 Bill?

    Hello

    In the print dialog box, you would get options to resize your document.

    Try them and see if that helps.

    Once you choose the print option, it would give options to change the size of the page you need.

    Please check and see if it suits you or not.

    Concerning

    Sukrit diallo

Maybe you are looking for

  • Satellite 1900-303 Wont Boot up black screen only - help!

    I have a major problem. My Toshiba Satellite 1900, Windows XP Home edition, P4, 2.0 Ghz, 256 MB of RAM (not SP2 updated) won't boot to the top.I ran Norton Sys works - speed record to defragment the HD. The screen is blank because the level of power

  • Note K5 Lenovo VIBE does not detect device Bluetooth Jabra

    Hello It's disappointing to start with. Less than 24 hours since I got my hands on the new Lenovo VIBE K5 Note. With long journeys to work and given the connectivity bluetooth with the phone is an essential feature to have for me. It worked very well

  • Sansa Connect 4GB

    I recently bought the sansa connect 4GB. Well, it looks good, but I can't find the drivers on the Web site I tried the recovery of connection device, sansa updater installation and update the firmware but nothing works... before that I installed thes

  • Link for storage WRT610N problem

    I have 3 computers connected to my router 610N.  I have version 1.0 of the equipment with the latest firmware.  All 3 computers worked very well, and then we moved into a new House.  New home, only 2 of the 3 can now see the external hard drive conne

  • I have compuuter problems can someone help plz

    I have a compaq computer and a new charger for the computer bbut if I plug with the laptop for 5 minutes the charger gets so hot it starts to melt its been ever tht long ago, so I drink llike to no bad mind what my laptop and how do I solve this prob