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);
Related
I'm making a sprite editor using JavaFX for use on desktops.
I'm attempting to implement zooming functionality, but I've run into a problem: I can't figure out how to disable image smoothing on a Canvas object.
I'm calling Canvas.setScaleX() and Canvas.setScaleY() as per every tutorial implementing Canvas zooming. But my image appears blurred when zoomed in.
I have some test code here to demonstrate.
As this is a sprite editor, it's important for me to have crisp edges to work with. The alternative to fixing image smoothing on the Canvas is to have a non-smoothing ImageView, and have a hidden Canvas to draw on, which I would rather avoid.
Help is appreciated.
(here's a link to a related question, but doesn't address my particular problem)
I was having the same issue with the blurring.
In my case, my computer has Retina Display. Retina Display causes a pixel to be rendered with sub-pixels. When drawing images to the canvas, the image would be drawn with antialiasing for the sub-pixels. I have not found a way to prevent this antialiasing from occurring (although it is possible with other canvas technologies such as HTML5's Canvas)
In the meantime, I have a work-around (albeit I'm concerned about performance):
public class ImageRenderer {
public void render(GraphicsContext context, Image image, int sx, int sy, int sw, int sh, int tx, int ty) {
PixelReader reader = image.getPixelReader();
PixelWriter writer = context.getPixelWriter();
for (int x = 0; x < sw; x++) {
for (int y = 0; y < sh; y++) {
Color color = reader.getColor(sx + x, sy + y);
if (color.isOpaque()) {
writer.setColor(tx + x, ty + y, color);
}
}
}
}
}
The PixelWriter bypasses the anti-aliasing that occurs when drawing the image.
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;
}
}
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
I am developing a j2me application for the BlackBerry. I download a large GIF and now want to scale the image to fit the screen. I am looking for better performance that scaling the image using by using approaches like this.
I haven't used the microedition Image myself, but I've worked with RIM's Image class recently, and it seems the least-common-denominator representation is an array of RGB values. I see that lcdui.Image has a method
getRGB(int[] rgbData, int offset, int scanlength, int x, int y, int width, int height)
which should give the array you need. You can then get a RIM Bitmap or Image or PNGEncodedImage with
Bitmap.setARGB(int[] data, int offset, int scanLength, int left, int top, int width, int height)
ImageFactory.createImage(Bitmap bitmap)
PNGEncodedImage.encode(Bitmap bitmap)
I have the following Java ME code that I'd like to port to BlackBerry:
Image imgAll = Image.createImage("/fontDigits_200x20.png");
imageDigits = new Image[10];
for(int i = 0; i < imageDigits.length; i++)
imageDigits[i] = Image.createImage(imgAll, i * 20, 0, 20, 20, Sprite.TRANS_NONE);
Basically, it's one image of ten digits that I want to split into 10 individual images and store them into an array. I looked through the docs, but can't find anything similar on EncodedImage or Graphics.
Thank you for any pointers!
UPDATE:
Good news! Apparently there's no way to crop an EncodedImage in such a way as to have a new EncodedImage which is a cropped subset of the original. However, you can do that with a Bitmap, which essentially is the same.
you can use
Bitmap.getARGB(int[] argbData,
int offset,
int scanLength,
int x,
int y,
int width,
int height)
after loading your image
Bitmap imgAll = Bitmap.getBitmapResource("fontDigits_200x20.png");
and off course you can create new Bitmap from this ARGB data.
You can do it directly with the Bitmap.scaleInto function:
Bitmap src;
Bitmap dst = new Bitmap(64,32);
int filterType = Bitmap.FILTER_BILINEAR;
src.scaleInto(srcLeft, srcTop, srcWidth, srcHeight, dst, dstLeft, dstTop, dstWidth, dstHeight, filterType);