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
Trusted Contributor
NGeldenhuys
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
Accepted Solution

Cropping/ Stretching to Screen Resollution

Hello Everyone!

 

Can A blackberry Application Be Skinned If yes, Please Can you explain to me how?

 

If I want to Add a "wallpaper" to my application how can i be sure that it will fit all blackberry Screen Resollutions? Is there a Code that crops or stretches the image for this or Do I have to create an App for Every Screen Resollution for Blackberry?

 

I have looked on the forum but havent found the answers to my questions. Please help.

 

 

Developer
BrajeshSanodiya
Posts: 134
Registered: ‎08-03-2011
My Device: torch, Z10

Re: Cropping/ Stretching to Screen Resollution

[ Edited ]

Hi,

 

Bitmap temp,img;
		img=Bitmap.getBitmapResource("give image");
		temp=new Bitmap(Display.getWidth(), Display.getHeight());
		img.scaleInto(temp, Bitmap.FILTER_BILINEAR, Display.getWidth()/Display.getHeight());
		

 

now u can use temp it will give u display width and height.

 

 

-----------------------------------------------------------------------
"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
-----------------------------------------------------------------------
Developer
BrajeshSanodiya
Posts: 134
Registered: ‎08-03-2011
My Device: torch, Z10

Re: Cropping/ Stretching to Screen Resollution

you can use this method

 

public static Bitmap resizeImage(Bitmap originalImage, int newWidth, int newHeight) {
    Bitmap newImage = new Bitmap(newWidth, newHeight);
    originalImage.scaleInto(newImage, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FILL);
    return newImage;
}

 

-----------------------------------------------------------------------
"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
-----------------------------------------------------------------------
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Cropping/ Stretching to Screen Resolution

Matching Bitmap sizes to screens is potentially a complicated area because you need to consider the screen size (i.e. pixel width and height) and its aspect ratio and its actual resolution, i.e. the density of pixels. 

 

Here some examples hopefully explaining why each is important.

 

1) Screen size:  If you have an image that is 200 pixels high, it will fill most of the height of the screen on a device like the 9320, but only 1/4 of the screen of a device like the 9860.

2) Aspect ratio: If you try to scale a circle in an image that is 400 X 400 to fill the screen of any BlackBerry device and you do not consider the aspect ratio, then the circle will end up looking like an ellipse on all devices - on the portrait style screens it will be tall and on others it will be wide.  It will never look like a circle.

3) Resolution - pixel density: If you have an image and you want it to appear the same size on any screen, then on the devices like the 9860 with a high density of pixels, the image will need to be larger.  If you have an image that is 50 x 50 displayed on a 9320, to display it the same size on a 9860 you will need an image about 80 x 80. 

 

There are more of my thoughts on this problem and how to resolve it so that you don't need an application per BlackBerry, in the last tutorial you will find here:

http://supportforums.blackberry.com/t5/Java-Development/Tutorials-for-new-developers-Part-1/m-p/1621...

 

On final thing, the code supplied in a previous post may not work for transparent Bitmaps, I recommend you look at this if you have transparent Bitmaps.

http://supportforums.blackberry.com/t5/Java-Development/Resizing-Transparent-Bitmaps/ta-p/703239

 

Trusted Contributor
NGeldenhuys
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250

Re: Cropping/ Stretching to Screen Resolution

[ Edited ]

All you do Is you create an Image that is as big as the largest bb Resolution, then the image automatically gets clipped.

 

The code I used To Add a background image(that adds the Image behind all Fields) .

 

package com.Images;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;

import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

public final class TestScreen extends MainScreen
{
private VerticalFieldManager mainManager;
private VerticalFieldManager subManager;
private Bitmap _backgroundBitmap = Bitmap.getBitmapResource
("12814463558610.png");
private int deviceWidth = Display.getWidth();
private int deviceHeight = Display.getHeight();

public TestScreen(){
super(NO_VERTICAL_SCROLL);
mainManager = new VerticalFieldManager(
Manager.NO_VERTICAL_SCROLL |
Manager.NO_VERTICAL_SCROLLBAR ){
public void paint(Graphics graphics)
{
graphics.clear();
graphics.drawBitmap(0, 0, deviceWidth,
deviceHeight, _backgroundBitmap, 0, 0);
super.paint(graphics);
}
};

subManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR ){
protected void sublayout(int maxWidth, int maxHeight){
int displayWidth = deviceWidth;
int displayHeight = deviceHeight;

super.sublayout( displayWidth, displayHeight);
setExtent( displayWidth, displayHeight);
}
};

mainManager.add(subManager);

this.add(mainManager);
}
}

 

Worked For Me :smileyhappy: