Blackberry Image Resize
This Class have resizeBitmap method as static method just call this method with three parameter as shown in following example
ImageResize.java
/*
* Code for Image Resize
*/
import net.rim.device.api.system.Bitmap;
public class ImageResize
{
public static Bitmap resizeBitmap(Bitmap image, int width, int height)
{
//Need an array (for RGB, with the size of original image)
//
int rgb[] = new int[image.getWidth()*image.getHeight()];
//Get the RGB array of image into "rgb"
//
image.getARGB(rgb, 0, image.getWidth(), 0, 0,image.getWidth(), image.getHeight());
//Call to our function and obtain RGB2
//
int rgb2[] = rescaleArray(rgb, image.getWidth(),
image.getHeight(), width, height);
//Create an image with that RGB array
//
Bitmap temp2 = new Bitmap(width, height);
temp2.setARGB(rgb2, 0, width, 0, 0, width, height);
return temp2;
}
private static int[] rescaleArray(int[] ini, int x, int y, int x2,int y2)
{
int out[] = new int[x2*y2];
for (int yy = 0; yy < y2; yy++)
{
int dy = yy * y / y2;
for (int xx = 0; xx < x2; xx++)
{
int dx = xx * x / x2;
out[(x2 * yy) + xx] = ini[(x * dy) + dx];
}
}
return out;
}
}
Calling this function Example
//this code will resize image temp.png to 100*100 whatever it was original size adn return one Bitmap resizedbitmap
Bitmap resizedbitmap= ImageResize.resizeImage(Bitmap.getBitmapResorces("temp.png"),100,100);
No comments:
Post a Comment