A simple way to scale image

Quickly share your Android Code Snippets here...

A simple way to scale image

Postby spring » Mon Jan 11, 2010 11:09 am

hope it useble for you. :)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. //load the source image for scale
  3.  
  4. Resources rs = ctx.getResources();
  5.  
  6. Bitmap tmpImage = BitmapFactory.decodeResource(rs, R.drawable.aircraft);
  7.  
  8.                
  9.  
  10. Matrix m = new Matrix();   //an object for scale and other operations.
  11.  
  12. m.setScale(50.0F, 50.0F);  //set the size of the image that after scaled
  13.  
  14.                
  15.  
  16. //scale the source image and save the result to target image
  17.  
  18. Bitmap image =     Bitmap.createBitmap(tmpImage,0,0,tmpImage.getWidth(),tmpImage.getHeight(),m,true);
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
spring
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sat Jan 09, 2010 4:37 am
Location: China

Top

Re: A simple way to scale image

Postby nhenze » Mon Jan 11, 2010 6:34 pm

... even simpler :-)

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Resources rs = ctx.getResources();
  2.  
  3. Bitmap tmpImage = BitmapFactory.decodeResource(rs, R.drawable.aircraft);
  4.  
  5. Bitmap image = Bitmap.createScaledBitmap(tmpImage, tmpImage.getWidth()/2, tmpImage.getHeight()/2, false);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
nhenze
Freshman
Freshman
 
Posts: 9
Joined: Thu Dec 10, 2009 10:34 am

Postby Droid123 » Tue Jan 12, 2010 12:48 am

Do you also know how to get a thumbnail of an image that is saved in MediaStore?
Droid123
Experienced Developer
Experienced Developer
 
Posts: 77
Joined: Sat Nov 21, 2009 1:21 pm

Postby Mazinkaiser » Tue Jan 12, 2010 6:52 pm

guys but the

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Resources rs = ctx.getResources();
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


what is provide? in the API it says "provides a higher-level API for getting typed data from the assets. " but... exactly?
Mazinkaiser
Freshman
Freshman
 
Posts: 9
Joined: Fri Oct 16, 2009 12:21 pm

Top

Return to Code Snippets for Android

Who is online

Users browsing this forum: Google [Bot] and 4 guests