In meiner Anwendung muss ich Bild von der Kamera erfassen oder aus der Galerie importieren, zeigen Sie es in Bildansicht in Aktivität. Alles ist in Ordnung, ich bekomme Bild von beiden und kann es auf imageview ohne Ausnahme einstellen. Aber manchmal wird das Bild nicht richtig skaliert und wird vertikal gestreckt oder mit Ausrichtung verändert. Bitte hilf mir.Bild von der Kamera oder Galerie bei der Verwendung in Bildansicht seine Ausrichtung wird verändert, und manchmal vertikal gestreckt in Android
Hier ist mein Code Bild von den offiziellen Android-Dokumentation bezeichnet zu dekodieren:
public static Bitmap decodeSampledBitmapFromResource(File photoFile, int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try {
BitmapFactory.decodeStream(new FileInputStream(photoFile), null,
options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth,
reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeStream(new FileInputStream(photoFile),
null, options);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
public static int calculateInSampleSize(BitmapFactory.Options options,
int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
// Calculate ratios of height and width to requested height and
// width
final int heightRatio = Math.round((float) height
/(float) reqHeight);
final int widthRatio = Math.round((float) width/(float) reqWidth);
// Choose the smallest ratio as inSampleSize value, this will
// guarantee
// a final image with both dimensions larger than or equal to the
// requested height and width.
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
}
return inSampleSize;
}
Ich werde es versuchen, und lassen Sie wissen ... @ Abhishek – Prashant
ok es und voteup überprüfen, ob es u hilfreich .. –
Dank abhishek, es funktioniert fine..I've Code getestet meine App. – Prashant