Blackberry - set field background image stetched to fit - blackberry

How can you scale an image - whether it be using Bitmap or EncodedImage to fill the entire width and height of a field?
Tried this:
protected void paintBackground(Graphics g) {
super.paintBackground(g);
//try bitmap
//g.drawBitmap(0, 0, this.getWidth(), this.getHeight(), image 0, 0);
//try encoded image
g.drawImage(0, 0, this.getContentWidth(), this.getContentHeight(), image, 0, 0, 0);
}

This questn is asked before here is link Blackberry - how to resize image?
In OS 5.0 the api scaleInto method is provided in Bitmap class i.e
http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/system/Bitmap.html#scaleInto%28net.rim.device.api.system.Bitmap,%20int%29
For Below OS 5.0 this bb kb article will be helpful for image manipulations
http://supportforums.blackberry.com/t5/Java-Development/Rotate-and-scale-bitmaps/ta-p/492524

Related

Get layer image data

Is there any way to get a layer image data, like the one that custom filters receive as a param? Yes, I know I can use getImageData and get it, but I was having a problems with it. In draggable canvases, it only captures visible part of the layer. Maybe I can create new canvas, then place a layer there and get image data? But I was wondering if there is any way to do it that is already built into konva?
If you want to get image data of layer's canvas you can do this:
const ctx = layer.getContext();
const imageData = ctx.getImageData(0, 0, width, height);
If your stage is too small and you need bigger image data, you have to export the layer into a bigger canvas and then get its image data:
const canvas = layer.toCanvas({ x: 0, y: 0, width, height});
const imageData = canvas.getContext('2d').getImageData(0, 0, width, height);

Unable to display image from web on blackberry device

I developed simple code to display an image and title on blackberry screen, but I am not able to display anything (but if I tested for title only it is working).
My requirement is to display image with title in a list.
I have followed this link for fetching image from image url
and here my code in drawlistrow method:
public void drawListRow(ListField list, Graphics g, int index, int y, int w)
{
String text = (String)listElements.elementAt(index);
Bitmap image =GetImage.connectServerForImage("http://toucheradio.com/toneradio/iphone/toriLite/toriLive.png");
g.drawLine(0, y, w, y);
g.drawText(text, 150, y, 60, w);
g.drawBitmap(0,y,image.getWidth(),image.getHeight(),image,0,0);
}
What could be the problem?
And please check the image height and width if its big than your screen resolution, then you have to crop or enlarge the image you are getting. Give some x axis to the drawBitmapMethod i have just giving you the idea like below you can implement.
g.drawBitmap(340, y, image.getWidth(), image.getHeight(), image, 0, 0);

Set width and height on BlackBerry BitmapField

How do I set width and height of a BitmapField in BlackBerry? The following code works, but I can't show the entire image. The display shows only some portion of my image.
BitmapField bmp = new BitmapField(connectServerForImage(ImageUrl)) {
protected void layout(int width, int height)
{
setExtent(80, 70);
}
};
I assume you're saying that your BitmapField is showing the image you retrieve cropped?
And you would like it to scale, perhaps scaled to fit the size of your BitmapField? There's many ways to do that, but one is to resize the image after downloading, before giving it to the BitmapField:
From this answer on resizing a Bitmap
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;
}
(Note that the link I provided has an alternate method for resizing images, if you have to support BlackBerry OS < 5.0).
Then, use
Bitmap img = resizeImage(connectServerForImage(ImageUrl), 80, 70);
BitmapField bmp = new BitmapField(img) {
protected void layout(int width, int height)
{
setExtent(80, 70);
}
};
However, I believe that if you actually set the size of the Bitmap img to 80x70, then there's no need to also set the extent of the BitmapField to 80x70. It should default to the size of the image you give it. So, you could simplify the code to:
BitmapField bmp = new BitmapField(img);
int prefWidth=(30*bitmap.getWidth())/bitmap.getHeight();
Bitmap temp=resizeBitmap(bitmap,prefWidth,30);
where
private Bitmap resizeBitmap(Bitmap image, int width, int height)
{
int rgb[] = new int[image.getWidth()*image.getHeight()];
image.getARGB(rgb, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
int rgb2[] = rescaleArray(rgb, image.getWidth(), image.getHeight(), width, height);
Bitmap temp2 = new Bitmap(width, height);
temp2.setARGB(rgb2, 0, width, 0, 0, width, height);
return temp2;
}
This support bb os 4.5

Blackberry app is very slow on startup, how can i fix this?

I recently updated my app to work on nearly all of the phones. I did this by having the first screen detect the screen size and then change all the images (there are a lot of images). As such, the startup on the non-base model phones is like 15 seconds, it looks like the phone is freezing but its just changing the images. It does this every time I open the app. What can I do to fix this?
Make sure that you are resizing images on a separate thread (no UI Blocking operation).
It would be better if you store all the resized images on persistent
storage so that you don't need to resize same image twice on a
handset.
[edited]
Some links about how to use persistence storage:
BlackBerry persistent store
Create a persistent data store
BlackBerry Java Application Development Guide
Sample Code Snippet for making a Bitmap object persistable:
class PersistableBitmap implements Persistable {
int width;
int height;
int[] argbData;
public PersistableBitmap(Bitmap image) {
width = image.getWidth();
height = image.getHeight();
argbData = new int[width * height];
image.getARGB(argbData, 0, width, 0, 0, width, height);
}
public Bitmap getBitmapImage() {
Bitmap image = new Bitmap(width, height);
image.setARGB(argbData, 0, width, 0, 0, width, height);
return image;
}
}

What is the easiest way to set background image of the application on Blackberry

I know, this question was asked before. However I can't beleive that this operation is so difficult. I think i miss some important points on developing Blackberry applications.
Try to use the following code:
Bitmap backgroundBitmap = Bitmap.getBitmapResource("background.png");
HorizontalFieldManager horizontalFieldManager = new
HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH |
HorizontalFieldManager.USE_ALL_HEIGHT){
//Override the paint method to draw the background image.
public void paint(Graphics graphics)
{
//Draw the background image and then call super.paint
//to paint the rest of the screen.
graphics.drawBitmap(0, 0, Display.getWidth(), Display.getHeight(),
backgroundBitmap, 0, 0);
super.paint(graphics);
}
};

Resources