2016-11-07 3 views
0

Ich versuche Bitmap aus gallery.I, um die Größe schrieb einige Code, und ich kann Bitmap nur statische Breite und height.this ist Quelleandroid Resize Bitmap Auto Höhe

 public Bitmap getResizedBitmap(Bitmap bm, int newWidth) { 

    float aspectRatio = (float)bm.getWidth()/(float) bm.getHeight(); 
    int height = Math.round(newWidth/aspectRatio); //based on width it gives height 
    Matrix matrix = new Matrix(); 

    matrix.postScale(newWidth, height); 

    Bitmap resizedBitmap = Bitmap.createBitmap(
      bm, 0, 0, newWidth, height, matrix, false); 
    return resizedBitmap; 
} 

, aber ich möchte, um die Größe Bitmap zum Beispiel Breite die Größe 800px und auto höhe. Ist es möglich, dieses problem in android zu lösen? dank

+0

[diesen Link verweisen] (http://stackoverflow.com/questions/3331527/android-resize-a-large-bitmap-file-to-scaled-output-file) i auch bekam Lösung für gleiche Problem von diesem Link –

Antwort

1
public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) { 
int width = bm.getWidth(); 
int height = bm.getHeight(); 
Bitmap resizedBitmap; 


try { 
     resizedBitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight()); 
      }catch (Exception e){ 
       e.printStackTrace(); 
       boolean_image = true; 
       return ""; 

      } 

return resizedBitmap; 
} 
+0

dank für die Aufmerksamkeit aber ich möchte automatische Höhe btmap – BekaKK

3
float aspectRatio = (float)Image.getWidth()/(float) Image.getHeight(); 
int width = 200; //your width 
int height = Math.round(width/aspectRatio); //based on width it gives height 
+0

ich es tryed aber ich habe nullpointException.setHasAlpha null ist – BekaKK

+0

ich es tryed aber ich habe nullpointException.setHasAlpha – BekaKK

+0

Post ypur bearbeitet Code null ist – sasikumar