Scaling background Bitmap, 9900 vs 9700
App looks on the 9900, but of course, the 9700 has a different screen and my bitmaps were created to adapt to the 9900. I checked the other threads, but all they advise to make is to use the method. scaleInto(), who does not work for me, as shown:
Bitmap bgfirstscreen = Bitmap.getBitmapResource("peerreview2.jpg"); Bitmap bgfirstscreenScaled = new Bitmap(Display.getWidth(),Display.getHeight()); bgfirstscreen.scaleInto(bgfirstscreenScaled, Bitmap.FILTER_LANCZOS); Background background = BackgroundFactory .createBitmapBackground(bgfirstscreen);
Is this all that generally must be done for the bitmap on the scale? It is used as a background image for my application screen.
Hi vingilot
Try this.
public static Bitmap getScaledBitmapImage(String imagename,int wd,int ht) { EncodedImage image = EncodedImage.getEncodedImageResource(imagename); if(image.getWidth()==wd && image.getHeight()==ht) return image.getBitmap(); int currentWidthFixed32 = Fixed32.toFP(image.getWidth()); int currentHeightFixed32 = Fixed32.toFP(image.getHeight()); int width = wd; if(width == -1) width=image.getWidth(); int height = ht; if(height == -1) height=image.getHeight(); int requiredWidthFixed32 = Fixed32.toFP(width); int requiredHeightFixed32 = Fixed32.toFP(height); int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32); int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32); image = image.scaleImage32(scaleXFixed32, scaleYFixed32); return image.getBitmap(); }
Thank you
Pawan
Tags: BlackBerry Developers
Similar Questions
-
Problem with Listfield and expandable background bitmap
Hello
I struggled for a while to make this work, and after searching the forums and knowledge base, I can't seem to do right. What I try to do is:
1 header is a bitmap expandable width of 1px to the bottom, more a company logo bitmap, with position fixed (only the items below it is scrolling)
2. use a listfield, which contains 4 elements:
-1 px wide image bitmap background for each line, repeat horizontally
-1 px width bitmap image of background for the highlighted line, repeat horizontally
-an icon bitmap for each line on the left side, and
-a title text for each line
Here is the screenshot and code what I've done so far, so the problem is:
1. when I scroll, scrolls the header (what I want is to position of the header is fixed, only the listfield below is scrolling).
2. the background image is only painted on the first line of the listfield, how can I do this with all the lines?
3. How is - that replace you the default blue color on a bitmap background highlighted line?
public class AjsScreen extends MainScreen{ // constructor public AjsScreen() { super(); // --- 1. Main Header --- \\ //prepare images upfront final Bitmap bgHeader = Bitmap.getBitmapResource("bg-header.jpg"); // repeating background image for main header final Bitmap logoAjs = Bitmap.getBitmapResource("logo-ajs.png"); // company logo in main header final Bitmap bgMenu = Bitmap.getBitmapResource("bg-menu.jpg"); // repeating background image for main menu final Bitmap bgMenuRo = Bitmap.getBitmapResource("bg-menu-ro.jpg"); // repeating background image for main menu (highlighted) //images used as repeating background final Background backgroundHeader = BackgroundFactory.createBitmapBackground(bgHeader, 0, 0, Background.REPEAT_VERTICAL); //REPEAT HORIZONTAL ??? Background backgroundMenu = BackgroundFactory.createBitmapBackground(bgMenu, 0, 0, Background.REPEAT_VERTICAL); Background backgroundMenuRo = BackgroundFactory.createBitmapBackground(bgMenuRo, 0, 0, Background.REPEAT_VERTICAL); //main header background, with stretched width, and fixed height HorizontalFieldManager hfm = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH){ public int getPreferredHeight() { return 55; } }; hfm.setBackground(backgroundHeader); //main header logo BitmapField bf = new BitmapField(logoAjs); bf.setPadding(2, 0, 0, 5);//clockwise from top, right, bottom, left hfm.add(bf); add(hfm); // --- 2. Main Menu --- \\ ListField lf = new ListField(){ //4, USE_ALL_HEIGHT | USE_ALL_WIDTH protected void paint(Graphics graphics) { // TODO Auto-generated method stub super.paint(graphics); } }; lf.setBackground(backgroundMenu); lf.setRowHeight(40); final Vector le = new Vector(); le.addElement("Menu 1"); le.addElement("Menu 2"); le.addElement("Menu 3"); le.addElement("Menu 4"); le.addElement("Menu 5"); le.addElement("Menu 6"); le.addElement("Menu 7"); le.addElement("Menu 8"); le.addElement("Menu 9"); lf.setCallback(new ListFieldCallback() { public int indexOfList(ListField listField, String prefix, int string) { return le.indexOf(prefix, string); } public int getPreferredWidth(ListField listField) { return Display.getWidth(); } public Object get(ListField listField, int index) { return le.elementAt(index); } public void drawListRow(ListField listField, Graphics g, int index, int y, int w) { g.drawBitmap(0, y, bgMenu.getWidth(), bgMenu.getHeight(), bgMenu, 0, 0); String text = (String) le.elementAt(index); g.drawText(text, 0, y, 0, w); } }); lf.setSize(le.size()); add(lf); } }
Thank you very much
Yusuf
«1. when I scroll, scrolls the header (what I want is in the position of the header is fixed, only the listfield below scrolls).»
ListField will do this for you. I suggest that you look at setTitle in the screen and put your part not scrolling in there
'2. the background image is only painted on the first line of the listfield, how can I do this with all the lines?'
Don't know (haven't looked hard) how your background is painted on the first line, but this line:
g.drawBitmap (0, bgMenu.getWidth (), bgMenu.getHeight (), bgMenu, 0, 0);
doesn't seem to work for your lines. You need to paint the entire width like this.
". How do replace you line default highlighted in blue on a background bitmap? »
There are a number of ways to do I think. Is to determine if you paint the selected line and act accordingly
(if (listField.getSelectedInde () == index) {...})
} else {}
}
Some people I think drawFocus override for the ListField - if you're looking for tour you will find examples.
I think there are other ways, I'm looking round I think that this question has been asked before.
-
Hi, I'm doing my compatible application on all phones, and I came to a roadblock.
-the sNormButton parameters are just an experiment to see if it works
-the normal parameters of the image are 40 x 20 cm I think
-everything works perfectly before putting in the code of scaling
-at the moment is to find a null pointer exception when I trigger the image
Here is my code on the screen:
Bitmap SNormButton = new Bitmap (10.5);
.......
public mainUIScreen()
{
Super();
......If ((Display.GetWidth () == 320) & (Display.getHeight () == 240))
{
A.newGame.scaleInto (sNormButton, Bitmap.FILTER_BILINEAR);
}.....
newGameBut = new BitmapButtonField (A.newGame, A.newGameUp);
newGameBut.setChangeListener (this);I'm new to the thing scaled so all words of advice are greatly appreciated, thank you!
Is this for 5.0 and above?
If so, use this class for scaling: http://supportforums.blackberry.com/t5/Java-Development/Resizing-Transparent-Bitmaps/ta-p/703239 it is clean and works with images that have transparent backgrounds (which the BB SDK does not work).
-
Dotted lines are possible without background bitmap?
Hello
I'm trying to get the grid on my graph dotted lines. After searching around, I think I can only achieve this by setting the background as a bitmap that has the dotted lines on. Is this correct?
I think that this was addressed in the .NET version, which now has this feature, but not in the version of VC ++ (inherited). I just wanted to confirm that this was the case.
Hi Richard,
After installing the legacy support version of one of our machines, I can confirm that the function you're looking for seems to be unavailable for VC ++. Unfortunately, as it comes to legacy support, it is unlikely that the feature will be added in the future.
I hope that answers your question
Kind regards
-
LabelField with background bitmap file
I would like to show a LabelField with a background as (01.gif, the yellow circle is the bmp and the labelField is '1'). My code is as follows:
final Bitmap bmp = Bitmap.getBitmapResource("img/circulo_numero.png"); LabelField lblPaso = new LabelField("1", Field.FIELD_RIGHT) { protected void paintBackground(Graphics g) { g.drawBitmap(0, 0, bmp.getWidth(), bmp.getHeight(), bmp, 0, 0); super.paint(g); } public int getPreferredWidth() { return bmp.getWidth(); } public int getPreferredHeight() { return bmp.getHeight(); } protected void layout(int width, int height) { super.layout(width, height); setExtent(Math.min(width, bmp.getWidth()), Math.min(height, bmp.getHeight())); } };
However, I got results as indicated in 02.gif...
How can I solve this problem?
TIA,
Yamil
Sorry, I'm not your post earlier. In any case, here is an explanation:
Your number 1 is painted where LabelField wants to paint. Unfortunately, you don't try to control where he went to paint it or where it will be placed, by the way. Fortunately, there is an old creation of mine tailor-made for you. Here it is:
Re: ButtonField with background
Simply create a CenteringManager with the bitmap you want to use as a background, add your LabelField and enjoy.
-
HII all I want to change my image of transparent background 100 * 100 in 80 * 80 with transparent background. When the
bitmap. Scale (new bitmap (), Bitmap.lancoz);
How to make transparent background as a black background...
but I want not transparent as original image...
using the search help.
http://supportforums.BlackBerry.com/T5/Java-development/resizing-transparent-bitmaps/Ta-p/703239 -
Scaling of Bitmaps embedded in Illustrator files.
Hello
At the moment, if I'm files provided with built-in Bitmaps (or related) I find the source file, rebuild the image and the parent to the rest of the work, if I want it intensify.
I can't just step up in Illustrator which makes things too big for AE work with.
Then
I was wondering if there was a way to gain access to Illustrator, scaling in EI.
For example, within a 1024 x 576 image, there is a small bitmap picture.
In Illustrator, the original bitmap has been reduced to 12%
I want to zoom in on that part of the image
If I resized the picture upwards in artificial intelligence, he referred to the original bitmap, so I can resize it back up to 100%
But if it's at 1024 x 576 AE can't do.
Continuous dither treats the whole things as vector of original size.
I can't do just one big file AS I would now have a px AI 10240 x 5760 file that would give me errors of memory.
(because always the AE will not only rendered what is in the window, but must do the whole layer. Did someone nothing real now at Adobe?)
Maybe some PDF files would work?
Is focused on working on a workflow better
designers still use bitmap (and bitmap effects!) images in artificial intelligence and think that I can zoom in on them.
Even at 100% weird flickering errors occur with bitmaps in files so I have used to reuse and parents anyway.
Nope. Would be nice, but can't be doen ATM. And a simple PDF file is useless, either because this can actually worse by flattening of the things that could be the vector into bitmap data or cut out pictures in separate tiles...
Mylenium
-
Background Bitmap value W3D file problem
OK, I posted about a while, but it has never been resolved. I have a program that allows the user to select from a list of objects. The list consists of several different models of W3D imported into my a 3D cast member after a mouseUp event. There is another list which consists of various images (JPEG format) that are important in a cast member called boss. After importation, they are applied as a texture to the current W3D model. I have the background transparent value, and DTS is disabled. The program works fine you cross and click on the different textures, they are applied to the model that is superimposed on a background that I created. My problem comes when I try to print at the scene. To print, I put the image of the 3D cast member to a bitmap, called "Imageholder." Once this happens, for all but one of the W3D models I work with, a background color is filled in the bitmap of the Imageholder and is no longer transparent. The sprite of the Member "Imageholder" I put transparent background as well. There must be a problem with exporting W3D model but I don't know what to change. Please help and thanks in advance.Answered my own question... Finally! I thought to print you need to set an image to the image of the 3D member. Turn on you can simply print the scene with the 3D cast member.
-
Change the image background bitmap on a click
I have the label with a text on the label... and I add a bitmap image right below the label.i put navigation click on the click event of image.for. now what I want,
First, when I click on this image, the image will be replaced by a different bitmap (second)
and
second - my text will be saved in my database, I did the second.Problem solved then?
If so, please mark this issue as resolved - see instructions in the Lnk help upwards if you are not sure about this.
-
Scaling of Bitmaps on BB 4.6?
Hi all
Take a look at the following knowledge base article:
Works on BB4.2 and later versions.
-
I have a simple yet unusual problem... I can't scale a bitmap despite the use of scaleinto class. BTW, I use the BB Torch Simulator.
My code is as follows:
Create background bitmap
Image bitmap bmpBkg = Bitmap.getBitmapResource ("sunlight2.png");
Bitmap scaling
Scaledbitmap bitmap =new Bitmap (Display.getWidth (),Display.getHeight ());
bmpBkg.scaleInto (scaledbitmap, Bitmap.FILTER_BILINEAR);
The problem is that even after the operation of scaleinto the height and width of the bmpBkg remain the same...?
Can someone help me with this please?
Thank you.
According to me, Miss me something here:
After:
bmpBkg.scaleInto (scaledbitmap, Bitmap.FILTER_BILINEAR);
isn't the Bitmap scaling in scaledbitmap rather than bmpBkg?
-
Hello...
Yes, I looked in other posts. And trying to disect the sample APP CustomButton. But, the image does not change the focus for this, and really, I had a hard time to work with it.
So, after several hours, I write...
I would like to make my button below clickable so that it plays a sound image and changes on focus. However, I have not yet found a strategy that I could implement.
Can someone provide some guidance? The error that I get with the implementation ŒUVRE FieldChangeListener when I try to extend the UiApplication is that...
....... The SmartCord type must implement the inherited abstract method FieldChangeListener.fieldChanged (field, int)
So clearly something is wrong and I have a bad strategy, but I have no idea what.
I use absolute available to resize the image according to the size of the screen
Thanks for the tips...
package com.package; import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; import net.rim.device.api.system.*; /** * This class extends the UiApplication class, providing a * graphical user interface. */ public class MyApp extends UiApplication implements FieldChangeListener { public static void main(String[] args) { MyApp theApp = new MyApp(); theApp.enterEventDispatcher(); } public MyApp() { MainScreen mainScreen = new MainScreen(); AbsoluteFieldManager MainFieldManager = new AbsoluteFieldManager(){ //Size the Field to the Screen Size protected void sublayout( int maxWidth, int maxHeight) { int width = Display.getWidth(); int height = Display.getHeight(); super.sublayout( width, height); setExtent( width, height); } //Override the paint method to draw the background image. public void paint(Graphics graphics) { Bitmap background = Bitmap.getBitmapResource("background.png"); Bitmap backgroundscaled = new Bitmap(Display.getWidth(),Display.getHeight()); backgroundscaled = new Bitmap(Display.getWidth(),Display.getHeight()); background.scaleInto(backgroundscaled, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FILL); //Draw the background image and then call paint. graphics.drawBitmap(0, 0, Display.getWidth(), Display.getHeight(), backgroundscaled, 0, 0); super.paint(graphics); } }; //Power Button Bitmap powerbutton = Bitmap.getBitmapResource("blackbutton.png"); Bitmap whitepowerbutton = Bitmap.getBitmapResource("whitebutton.png"); Bitmap powerscaled = new Bitmap(Display.getWidth()/2,Display.getWidth()/2); powerscaled = new Bitmap(Display.getWidth()/2,Display.getWidth()/2); Bitmap powerpressedscaled = new Bitmap(Display.getWidth()/2,Display.getWidth()/2); powerpressedscaled = new Bitmap(Display.getWidth()/2,Display.getWidth()/2); powerbutton.scaleInto(powerscaled, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FILL); whitepowerbutton.scaleInto(powerpressedscaled, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FILL); BitmapField bitmapField2 = new BitmapField(powerscaled, Field.FOCUSABLE) ; //Location int field2x=Display.getWidth()/4; int field2y=(Display.getHeight()/2)-(Display.getWidth()/4); //Add the manager to the screen. mainScreen.add(MainFieldManager); //Add the fields to the manager. MainFieldManager.add(bitmapField2,field2x,field2y); //Push the screen. pushScreen(mainScreen); } }
Thanks for the reply.
Yes, I am just now simply show the domains I've created for the package which is currently running and which displays some things I'd like to that.
So my queestion is, what do you suggest to be the next? I feel that I need to have separate classes for each button, which extends to a BitmapField? I left it because I didn't know how to add.
Thank you
-
Definition solid background Transparent for VerticalFieldManager
I use BB JDE 6.0
Simulator is also the same thing (Blackberry Torch)
My phone is Blackberry Torch
I created a verticalfieldmanager two in my screen. (iVFM1, iVFM2)
I put the bottom of iVFM1 as a background bitmap
I put the bottom of iVFM2 as a background of solidtransparent (with an alpha 180, color - 0 x 111111 value value), which is placed in the center of iVFM1.
I added two fields button in iVFM2
Background MainBG = BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("DriveLinkBG.png")); Background ActBG = BackgroundFactory.createSolidTransparentBackground(0x111111,180); iVFM2 = new VerticalFieldManager(VerticalFieldManager.FIELD_HCENTER | VerticalFieldManager.USE_ALL_WIDTH); iVFM2.setBackground(ActBG); iVFM1.setBackground(MainBG); iVFM1.add(iVFM2);
Note: Please find the spare part for images
(1) when I open my application. the iVFM2 has solid experience (no transparency) with the two buttons (attachment: BeforeFocus.png).
(2) when I select the first button of the part around the button becomes transparent (attachment: AfterFirstFocus.png) and
(3) when I choose the other key the part around this button becomes transparent too(attachment: AfterSecondFocus.png) [add with the portion who previously became transparent]
How to do the whole iVFM2 transparent when the screen is pressed
I found the error.
I was working with transparent background and a solid border. If the whole bottom was solid.
Now, I've changed the border to border transparent by setting the alpha value, and his works now.
-
Faced with centered Background Image
I have the code that I found always give me a background focused on a screen image. It is based on the ideas presented here:
http://supportforums.BlackBerry.com/T5/Java-development/MainScreen-explained/Ta-p/606644
However, the code does not, at least not for me.
I tried other variations as well, as the addition of another not VFM of scrolling, then adding data scrolling to the optimization of resources, but even this indirection suffers from the same problem. Have two screenshots to show, the 'exclamation' should be at the centre according to me!
Code follows.
To illustrate the problem, just space out the field change with "entry" for more complete screen. Then the same thing to one below the Bitmap and then scroll and down using the trackpad. I suspect that you will see the problem.
I saw this on OS 6.0 and 7.0 OS simulators. Not tested on OS 5.0 and tested only on touchscreen devices. I'll do some more tests later.
Someone at - it suggestions on the subject of how we get the "centered" background Bitmap actually stay in the Center will still let me add lines to my editfields and scroll using the trackpad?
Net.rim.device.api.system import. *;
Net.rim.device.api.ui import. *;
Net.rim.device.api.ui.component import. *;
Net.rim.device.api.ui.container import. *;/**
* A screen class to test background bitmap images.
*/
SerializableAttribute public class BackgroundImageScreen extends screen
{
private int backgroundColor = 0x00FF0000;
private bitmap _backgroundBitmap = Bitmap.getPredefinedBitmap (Bitmap.EXCLAMATION);
Constructor
public BackgroundImageScreen()
{
Super(Manager.USE_ALL_WIDTH |) Manager.USE_ALL_HEIGHT | Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR);
setTitle (new LabelField ("Background Image Demo"));
VerticalFieldManager backgoundManager = VerticalFieldManager(Manager.USE_ALL_WIDTH | nouveau Manager.USE_ALL_HEIGHT |) Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR) {}
{} public void paintBackground (Graphics g)
int currentVackgroundColor = g.getBackgroundColor ();
try {}
g.setBackgroundColor (backgroundColor);
g.Clear ();
} {Finally
g.setBackgroundColor (currentVackgroundColor);
}
int managerWidth = this.getWidth ();
int managerHeight = this.getHeight ();
centerX = int (this.getWidth () - _backgroundBitmap.getWidth (()) 2.
centerY = int (managerHeight - _backgroundBitmap.getHeight ()) 2.
System.out.println ("current position:" + Integer.toString (centerX) + ":" + Integer.toString (centerY) +)
", Far manager:" + Integer.toString (managerWidth) + ":" + Integer.toString (managerHeight) + "."
", Manager virtual:" + Integer.toString (this.getVirtualWidth () + ":" + Integer.toString (this.getVirtualHeight () + "."
", ManagerScroll:" + Integer.toString (this.getHorizontalScroll () + ":" + Integer.toString (this.getVerticalScroll ())); "."
g.drawBitmap (this.getHorizontalScroll () + centerX, this.getVerticalScroll () + centerY, _backgroundBitmap.getWidth (), _backgroundBitmap.getHeight (), _backgroundBitmap, 0, 0);
}
};
backgoundManager.add (new EditField ("scrolling test:", "Enter the text here to scroll"));
backgoundManager.add (new SeparatorField());
backgoundManager.add (new BitmapField (Bitmap.getPredefinedBitmap (Bitmap.QUESTION)));
backgoundManager.add (new SeparatorField());
backgoundManager.add (new EditField ("test an another parchment:", "Enter the text here to scroll"));
This.Add (backgoundManager);}
}Ahh, touch screens...
I remember I had to invalidate the Manager paint extra stuff (vertical scroll bar in my case) in scrollChanged() specifically for touchscreen devices. So one thing to try is to implement ScrollChangeListener in your main screen or your added VFM and invalidate the VFM in scrollChanged. This should fix the problem, even if it will be a drop in performance.
I suspect that the touchscreen devices have certain graphic hardware acceleration, which makes them more effective when scrolling but it lacks what BlackBerry stuff framework is not aware (for example your paintBackground according to the positions of scrolling).
I'm curious to know what happens if you use setBackground on a scroll, no Manager and add the scroll with no bottom paint on top of it. setBackground, being a built-in could make better use of their hardware acceleration.
-
Question about image scaling height
Hi all
I know that there are a ton of posts on this topic, but I have not really found one that is clear on the problem I encounter.
Basically I have a PNG image that I want to change so that the width of the image corresponds to the width of the screen. So, I want the height of the image to be adjusted automatically in order to preserve the proportions of the image. Currently, I am doing this:
Bitmap b = Bitmap.getBitmapResource(image); Bitmap scaled = new Bitmap(Display.getWidth(), ???); b.scaleInto(scaled, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FIT); BitmapField bf = new BitmapField(scaled);
But with this method, I have to set the height of the sized image. This is not good, as I don't know what should be the height after the image has been resized (and kept proportions).
Anyone know how I can determine the correct height of the image?
Thank you.
If you can get the height and width of the image, then use the ratios.
UX = initial width, OH is original height, NW is the new width, NH = new height.
(NW * OH) / OW = NH
Maybe you are looking for
-
Beachball constantly present in Safari
Whenever I use Safari, I get the spinning beachball. I ran Etrecheck and this is the result of this. Any help is appreciated. EtreCheck version: 2.9.12 (265) Report generated 2016-05-23 13:53:59 Download EtreCheck from https://etrecheck.com Time 03
-
I'm using Firefox for the past five years. I've updated regularly and have had no problems, but today all of a sudden I get a message saying "sorry, you try to use Google calendar with a browser that is currently not supported. Press OK display a rea
-
I was able to get the driver and the ut6ilize my HP Laser Jet 4 L printer. Since my hard drive had to be replaced, I was not able to get the LaserJe6t from HP again 4L printer driver. Help!
-
play a game of cd rom for xp on vista
I have a monopoly game that works fine on the xp desktop. I was able to load on vista. When you click on play now it goes in a black full screen as it is supposed to.However, the game does not go past the black screen. or in other words, the game wil
-
The appearance screen Aero feature disappeared as an option. I know not why he disappeared because I ran a Registar mechanic function that caused the AERO feature to disappear. Is it possible that I can get the rear AERO screen appearance without h