saryoromulo 6 de mai. de 2015
Ela fica distorcida pq vc tem que reduzir proporcionalmente o tamanho dela…
Por exemplo… se ela tá com 400x600 e vc quer reduzir pela metade, vc tem que colocar 200x300. se vc colocar simplesmente 200x200, ele vai ficar meio distorcido mesmo, entende?
saryoromulo 6 de mai. de 2015
aqui tá um exemplo que eu uso isso num OnActivityResult pegando a foto tirada pela camera:
if (resultCode == RESULT_OK && requestCode == 1){
Bundle bd = data . getExtras ();
Bitmap imagem = ( Bitmap ) bd . get ( "data" );
String [] projection = new String [] { MediaStore . Images . ImageColumns . _ID , MediaStore . Images . ImageColumns . DATA , MediaStore . Images . ImageColumns . BUCKET_DISPLAY_NAME , MediaStore . Images . ImageColumns . DATE_TAKEN , MediaStore . Images . ImageColumns . MIME_TYPE };
final Cursor cursor = managedQuery ( MediaStore . Images . Media . EXTERNAL_CONTENT_URI , projection , null , null , MediaStore . Images . ImageColumns . DATE_TAKEN + " DESC" );
if ( cursor != null ){
cursor . moveToFirst ();
}
BitmapFactory . Options op = new BitmapFactory . Options ();
op . inJustDecodeBounds = true ;
InputStream in = null ;
try {
in = new FileInputStream ( cursor . getString ( 1 ));
} catch ( FileNotFoundException e ) {
e . printStackTrace ();
}
BitmapFactory . decodeStream ( in , null , op );
try {
in . close ();
} catch ( IOException e1 ) {
e1 . printStackTrace ();
}
in = null ;
try {
in = new FileInputStream ( cursor . getString ( 1 ));
} catch ( FileNotFoundException e ) {
e . printStackTrace ();
}
op = new BitmapFactory . Options ();
op . inSampleSize = Math . max ( op . outWidth / 500 , op . outHeight / 375 );
imagem = BitmapFactory . decodeStream ( in , null , op );
imagem = Bitmap . createScaledBitmap ( imagem , 500 , 375 , true );
Log . i ( "Height: " , "" + imagem . getHeight ());
Log . i ( "Width: " , "" + imagem . getWidth ());
ByteArrayOutputStream stream = new ByteArrayOutputStream ();
imagem . compress ( CompressFormat . JPEG , 100 , stream );
byte [] foto = stream . toByteArray ();
…
…
…
…
j.silvestre 6 de mai. de 2015