06-26-2012 04:31 AM
I have this
private static final Bitmap _bitmap = Bitmap.getBitmapResource("SplashScreen.png");
how can i resize image based on screen size?
public static EncodedImage sizeImage(EncodedImage image, int width, int height) {
EncodedImage result = null;
int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
int currentHeightFixed32 = Fixed32.toFP(image.getHeight());
int requiredWidthFixed32 = Fixed32.toFP(width);
int requiredHeightFixed32 = Fixed32.toFP(height);
int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
int scaleYFixed32 = Fixed32.div(currentHeightFixed32,requiredHeightFix
result = image.scaleImage32(scaleXFixed32, scaleYFixed32);
return result; }
Solved! Go to Solution.
06-26-2012 04:55 AM
06-26-2012 05:04 AM
Full solution
static EncodedImage eih1 = EncodedImage.getEncodedImageResource("SplashScreen .png");
private static final EncodedImage _bitmap2 = sizeImage(eih1,Display.getWidth(), Display.getHeight());
private static final Bitmap _bitmap = cropBitmap(_bitmap2.getBitmap(),Display.getWidth() ,Display.getHeight());
public static EncodedImage sizeImage(EncodedImage image, int width, int height) {
EncodedImage result = null;
int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
int currentHeightFixed32 = Fixed32.toFP(image.getHeight());
int requiredWidthFixed32 = Fixed32.toFP(width);
int requiredHeightFixed32 = Fixed32.toFP(height);
int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
int scaleYFixed32 = Fixed32.div(currentHeightFixed32,requiredHeightFix ed32);
result = image.scaleImage32(scaleXFixed32, scaleYFixed32);
return result; }
public static Bitmap cropBitmap(Bitmap original, int width, int height) {
Bitmap bmp = new Bitmap(width, height);
int x = (original.getWidth() / 2) - (width / 2); // Center the new size by width
int y = (original.getHeight() / 2) - (height / 2); // Center the new size by height
int[] argb = new int[width * height];
original.getARGB(argb, 0, width, x, y, width, height);
bmp.setARGB(argb, 0, width, 0, 0, width, height);
return bmp;
}
06-26-2012 10:50 AM
Hey Babakar Thanks for sharing the code. but insted of passing the file name can i pass the image path. i have tried that i am getting error . how to handel that situation. In my case i am taking image from camera and saving to the internal storage. and i want to rezie that image stored in internal storage . like file:///stor/Test/test.png
Thanks in advances