0
私のアプリでは、カメラから写真を撮る/ギャラリーから選択する必要があります。 私のコードはデバイス上で正常に動作していますが、Galaxy s4で動作し、カメラで写真を撮ったとき、写真はimageViewに表示されません(gallery-working fineから選択してください)。 画像を拡大してからimageViewに表示しました。ここ は、写真を撮るために私のコードです:写真を撮ると画像に表示されません。ギャラクシーs4でのみ表示
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(intent, 1);
これはテイク写真の後に私のコードです:
if (requestCode == 1)
{
File f = new File(Environment.getExternalStorageDirectory().toString());
File image_file = new File(Environment.getExternalStorageDirectory().toString());
for (File temp : f.listFiles())
{
if (temp.getName().equals("temp.jpg"))
{
f = temp;
break;
}
}
try
{
Bitmap bitmap;
//BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
//bitmap=decodeFile(f.getAbsolutePath());//Collapse image
//setImageOnBitmap(bitmap);//Set the image on the imageview
BitmapHandler b=new BitmapHandler(getApplicationContext());
bitmap=b.decodeFileAsPath(f.getAbsolutePath(),"camera");
setImageOnBitmap(bitmap);
String path = android.os.Environment
.getExternalStorageDirectory()
+ File.separator
+ "Phoenix" + File.separator + "default";
f.delete();
}
catch (Exception e)
{
e.printStackTrace();
}
}
これはイメージのファイルを復号化するために、私の関数である。
public static Bitmap decodeSampledBitmapFromFile(String path, int reqWidth, int reqHeight)
{ // BEST QUALITY MATCH
//First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
// Calculate inSampleSize, Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
options.inPreferredConfig = Bitmap.Config.RGB_565;
int inSampleSize = 1;
if (height > reqHeight)
{
inSampleSize = Math.round((float)height/(float)reqHeight);
}
int expectedWidth = width/inSampleSize;
if (expectedWidth > reqWidth)
{
//if(Math.round((float)width/(float)reqWidth) > inSampleSize) // If bigger SampSize..
inSampleSize = Math.round((float)width/(float)reqWidth);
}
options.inSampleSize = inSampleSize;
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(path, options);
}
エラーがありますか? –
番号。私はそれをチェックする、それはちょうどエラーなしで画像を表示しない – Toda