آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

چرا عکسهای عمودی گرفته شده با برنامه من افقی نمایش داده می شوند؟

ahmad_r  11 سال پیش  9 سال پیش
+5 0

من از کد زیر برای گرفتن عکس استفاده می کنم

 Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File("MyAddress.jpg")));
startActivityForResult(intent, G.REQUEST_CAMERA);

عکس گرفته می شود ولی مشکل اینجاست که اگر عکس را عمودی بگیرم در برنامه من افقی نمایش ولی در گالری پیش فرض گوشی صحیح نمایش می دهد

البته تابع زیر درستش میکنه ولی میخوام اساسی ذخیره بشه که نیازی به استفاده از تابع در هر بار نمایش عکس نباشه.

آخه عکسهایی که مستقیما با خود دوربین گرفته میشه نه برنامه من رو همیشه درست نمایش میده و کاملا مشخصه که نحوه عکس گرفتن من باید درست بشه.

    private static void setImageCorrectlyOriented(String address, ImageView img)
{
Bitmap myBitmap = BitmapFactory.decodeFile(address);

try {

// if (myBitmap.getWidth() > myBitmap.getHeight())
// matrix.postRotate(90);

File imgFile = new File(address);
Matrix matrix = new Matrix();
ExifInterface exif = new ExifInterface(imgFile.getAbsolutePath());

int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
matrix.postRotate(90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
matrix.postRotate(180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
matrix.postRotate(270);
break;
}
myBitmap = Bitmap.createBitmap(myBitmap, 0, 0, myBitmap.getWidth(), myBitmap.getHeight(), matrix, true);

}
catch (Exception e) {
e.printStackTrace();
}
img.setImageBitmap(myBitmap);
}

 

0 0
@ahmad_r : جوابی برای حل این مشکل پیدا نکردی هنوز ؟ اگه پیدا کردی بی زحمت بگو ما هم مشکل داریم سر این قضیه :) (11 سال پیش)
 برای این سوال 2 پاسخ وجود دارد.
پاسخ به سوال 
مجتبی یگانه  11 سال پیش
+1 0

دقیقا همین کد تو کلیپ بورد ام بود و اومدم براتون درج کنم که دیدم ویرایش کرد و خودتون درج کردید !

حالت پیشفرض دوربین ها حالت LandScape هست . منم چند روز پیش به همین مشکل خوردم و این لینک مشکل رو حل کرد

0 0
دستت درد نکنه ، یه خرده باهاش سر و کله بزنیم ببینیم میشه درست پیاده سازیش کرد :) (11 سال پیش)
0 0
نه متاسفانه راه حل بهتری هنوز به دست نیاوردم. (11 سال پیش)
پاسخ به سوال 
moin007  9 سال پیش
0 0

File f=new File("addres ax");
image.setImageBitmap(decodeFile(f));


 این کد عکس رو همونجری ک ذخیره شده بر می گردونه 

private Bitmap decodeFile(File f) {
try {
// Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(f), null, o);

// The new size we want to scale to
final int REQUIRED_SIZE=70;

// Find the correct scale value. It should be the power of 2.
int scale = 1;
while(o.outWidth / scale / 2 >= REQUIRED_SIZE &&
o.outHeight / scale / 2 >= REQUIRED_SIZE) {
scale *= 2;
}

// Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
} catch (FileNotFoundException e) {}
return null;
}
این کد هم می چرخونه اگر نتیجه همونی ک میخواید نبود
 
private Bitmap decodeFile(File f) {
try {
// Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(f), null, o);

// The new size we want to scale to
final int REQUIRED_SIZE=150;

// Find the correct scale value. It should be the power of 2.
int scale = 1;
while(o.outWidth / scale / 2 >= REQUIRED_SIZE &&
o.outHeight / scale / 2 >= REQUIRED_SIZE) {
scale *= 2;
}

// Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();

o2.inSampleSize = scale;
Matrix matrix = new Matrix();
float angle = 90;
matrix.postRotate(angle);

Bitmap bMap= BitmapFactory.decodeStream(new FileInputStream(f), null , o2);
Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0,bMap.getWidth(),bMap.getHeight(), matrix, true);

return bMapRotate;
} catch (FileNotFoundException e) {}
return null;
}
 مشکل حافظه هم اگر داشته باشید تو عکس های سنگین بر طرف می کنه



پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .