Android Tutorial

Showing posts with label Android on board. Show all posts
Showing posts with label Android on board. Show all posts

8.25.2011

resizeImage trong Android.


 public static Drawable resizeImage(Context ctx, int resId, int w, int h) {

     // load the origial Bitmap
     Bitmap BitmapOrg = BitmapFactory.decodeResource(ctx.getResources(),
                                                     resId);

     int width = BitmapOrg.getWidth();
     int height = BitmapOrg.getHeight();
     int newWidth = w;
     int newHeight = h;

     // calculate the scale
     float scaleWidth = ((float) newWidth) / width;
     float scaleHeight = ((float) newHeight) / height;

     // create a matrix for the manipulation
     Matrix matrix = new Matrix();
     // resize the Bitmap
     matrix.postScale(scaleWidth, scaleHeight);
     // if you want to rotate the Bitmap
     // matrix.postRotate(45);

     // recreate the new Bitmap
     Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0,
                                                width, height, matrix, true);

     // make a Drawable from Bitmap to allow to set the Bitmap
     // to the ImageView, ImageButton or what ever
     return new BitmapDrawable(resizedBitmap);

    }

7.13.2011

Converting Views to Bitmap Images in Android

When working with applications, developers can sometimes run in to a situation where they would like to create a view and then convert it to a Bitmap to work with it as an image. Learn how in this easy to follow guide.

In some applications, we would like to create a View with texts, images, and more view-elements and convert it to a Bitmap. Why? Well, you don't know until you need it, but imagine that you are working with OpenGL, you want to add textures to a OpenGL object, and you want these textures view-like. This is just an example, but I'm positive that more functionality will come to your mind while you are developing in Android.

Short introduction to Bitmap and Canvas

7.12.2011

Poarting Android on TI Zoom2

//COMPILER
//Download cross compiler to Desktop from:

$firefox http://www.codesourcery.com/sgpp/lite/arm/releases/2007q3
$ mkdir /home/user/bin
//(Select ARM GNU/Linux and IA32 GNU/Linux options)
//copy download zip to /home/user/bin and unzip here
$ cp /home/user/Desktop/arm-2007q3-51-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 /home/user/bin
$ cd /home/user/bin
$ tar -xjvf arm-2007q3-51-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
//Edit bashrc shell setup
$ cd /home/user
$ gedit .bashrc
//add following to the end
#PATH
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
export PATH=$PATH:/home/user/bin/arm-2007q3/bin //for tools
//save and exit
//apply the path changes
$ source .bashrc
//verify path is ok for tools
$ which arm-none-linux-gnueabi-gcc
//should see /home/usr/bin/arm-2007q3/bin/arm-none-linux-gnueabi-gcc