5日経ちましたが、誰も助けてくれません!! 誰か助けてください
私は問題を抱えており、特にSamsumg S3電話でのみ持続します. Androidのカメラサービスから4枚の画像を取得しようとしています。
問題は、他の電話で同じコードを実行しようとすると、問題なく動作しますが、Samsung S3 電話で問題が発生することです。
私がやろうとしているのは、4 つの Imageview を用意することです。すべての imageview の onclick で、ユーザーの選択に応じてカメラ サービスまたはギャラリー サービスを開くことができます。画像をクリックまたは選択すると、その画像はクリックされた特定の画像ビューに設定されます。
したがって、4つの画像すべてを1つずつ設定できます。これは、他の電話や他のサムスンの電話でも問題なく動作しますが、Samsung S3 では問題があるようです。
誰でも私を助けてください。
これは、imageViewで画像を取得している私のコードです。
私のOncreateメソッド
public class Add_image extends Activity {
ImageView imgview1, imgview2, imgview3, imgview4;
private static int RESULT_LOAD_IMAGE = 1;
private static final int CAMERA_IMAGE_CAPTURE = 0;
private static final int PICK_FROM_GALLERY = 2;
int CAMERA_PIC_REQUEST = 1337;
String SD_CARD_IMAGE_PATH = null;
byte b[];
String largeImagePath = "";
Uri uriLargeImage;
Uri uriThumbnailImage;
private static final int OG = 4;
int flag = 0, orientation;
String bal, picturePath, bal1, bal2, bal3, bal4;
int flagg = 0;
Cursor myCursor, cursor1;
Bitmap thumbnail = null;
TextView t5, t6, t7, t8;
// SharedPreferences pic1, pic2, pic3, pic4;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.image);
imgview1 = (ImageView) this.findViewById(R.id.imageView1);
imgview1.setOnClickListener(click_img1);
imgview2 = (ImageView) this.findViewById(R.id.imageView2);
imgview2.setOnClickListener(click_img2);
imgview3 = (ImageView) this.findViewById(R.id.imageView3);
imgview3.setOnClickListener(click_img3);
imgview4 = (ImageView) this.findViewById(R.id.imageView4);
imgview4.setOnClickListener(click_img4);
t5 = (TextView) findViewById(R.id.textView5);
t5.setVisibility(View.VISIBLE);
t6 = (TextView) findViewById(R.id.textView6);
t6.setVisibility(View.VISIBLE);
t7 = (TextView) findViewById(R.id.textView7);
t7.setVisibility(View.VISIBLE);
t8 = (TextView) findViewById(R.id.textView8);
t8.setVisibility(View.VISIBLE);
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(btn_click);
if (savedInstanceState != null) {
Bitmap carpic;
String B1 = savedInstanceState.getString("message");
// Toast.makeText(this, "SavedYeah"+B1, Toast.LENGTH_LONG).show();
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = OG;
carpic = BitmapFactory.decodeFile((B1), opts);
System.gc();
if (carpic != null) {
imageCam(carpic);
}
}
}
異なるボタンクリック
public View.OnClickListener btn_click = new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Add_image.this, Add.class);
startActivity(intent);
}
};
private View.OnClickListener click_img1 = new View.OnClickListener() {
@Override
public void onClick(View v) {
flag = 1;
openNewGameDialog();
}
};
private View.OnClickListener click_img2 = new View.OnClickListener() {
@Override
public void onClick(View v) {
flag = 2;
openNewGameDialog();
}
};
private View.OnClickListener click_img3 = new View.OnClickListener() {
@Override
public void onClick(View v) {
flag = 3;
openNewGameDialog();
}
};
private View.OnClickListener click_img4 = new View.OnClickListener() {
@Override
public void onClick(View v) {
flag = 4;
openNewGameDialog();
}
};
メーカーとカメラ サービスを確認するための私の openNewGameDialog() メソッド
String[] B = { "Camera", "Gallery", "Delete Image" };
private void openNewGameDialog() {
new AlertDialog.Builder(this).setItems(B,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialoginterface, int i) {
if (i == 0) {
String BX1 = android.os.Build.MANUFACTURER;
if (BX1.equalsIgnoreCase("samsung")) {
// Toast.makeText(getApplicationContext(),
// "Device man"+BX1, Toast.LENGTH_LONG).show();
Intent intent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,
CAMERA_IMAGE_CAPTURE);
} else {
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent,
CAMERA_PIC_REQUEST);
}
}
else if (i == 1) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, RESULT_LOAD_IMAGE);
} else if (i == 2) {
if (flag == 1) {
imgview1.setImageDrawable(null);
t5.setVisibility(View.VISIBLE);
}
if (flag == 2) {
imgview2.setImageDrawable(null);
t7.setVisibility(View.VISIBLE);
}
if (flag == 3) {
imgview3.setImageDrawable(null);
t6.setVisibility(View.VISIBLE);
}
if (flag == 4) {
imgview4.setImageDrawable(null);
t8.setVisibility(View.VISIBLE);
}
}
}
}).show();
}
imageCam() 画像を ImageView に設定するメソッド
public void imageCam(Bitmap thumbnail) {
Bitmap photo = thumbnail;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.JPEG, 70, bos);
b = bos.toByteArray();
bal = Base64.encodeBytes(b);
// ImageView imageview = (ImageView) findViewById(R.id.imageView1);
String BX1 = android.os.Build.MANUFACTURER;
if (BX1.equalsIgnoreCase("samsung") && flagg == 0) {
}
if (flag == 1) {
bal1 = bal;
t5.setVisibility(View.GONE);
imgview1.setImageBitmap(photo);
// Toast.makeText(getApplicationContext(), "Image1=" + bal1,
// Toast.LENGTH_LONG).show();
} else if (flag == 2) {
bal2 = bal;
t7.setVisibility(View.GONE);
imgview2.setImageBitmap(photo);
// Toast.makeText(getApplicationContext(), "Image2=" + bal2,
// Toast.LENGTH_LONG).show();
} else if (flag == 3) {
bal3 = bal;
t6.setVisibility(View.GONE);
imgview3.setImageBitmap(photo);
// Toast.makeText(getApplicationContext(), "Image3=" + bal3,
// Toast.LENGTH_LONG).show();
} else if (flag == 4) {
bal4 = bal;
t8.setVisibility(View.GONE);
imgview4.setImageBitmap(photo);
// Toast.makeText(getApplicationContext(), "Image4=" + bal4,
// Toast.LENGTH_LONG).show();
}
Add ad = new Add();
ad.image_save(bal1, bal2, bal3, bal4);
// flag=0;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString("message", largeImagePath);
outState.putString("Gallerymessage", picturePath);
}
onActivityResult() メソッド
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_IMAGE_CAPTURE
&& resultCode == Activity.RESULT_OK) {
flagg = 0;
// Describe the columns you'd like to have returned. Selecting from
// the Thumbnails location gives you both the Thumbnail Image ID, as
// well as the original image ID
String[] projection = {
MediaStore.Images.Thumbnails._ID, // The columns we want
MediaStore.Images.Thumbnails.IMAGE_ID,
MediaStore.Images.Thumbnails.KIND,
MediaStore.Images.Thumbnails.DATA };
String selection = MediaStore.Images.Thumbnails.KIND + "=" + // Select
// only
// mini's
MediaStore.Images.Thumbnails.MINI_KIND;
String sort = MediaStore.Images.Thumbnails._ID + " DESC";
// At the moment, this is a bit of a hack, as I'm returning ALL
// images, and just taking the latest one. There is a better way to
// narrow this down I think with a WHERE clause which is currently
// the selection variable
myCursor = this.managedQuery(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
projection, selection, null, sort);
long imageId = 0l;
long thumbnailImageId = 0l;
String thumbnailPath = "";
try {
myCursor.moveToFirst();
imageId = myCursor
.getLong(myCursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.IMAGE_ID));
thumbnailImageId = myCursor
.getLong(myCursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID));
thumbnailPath = myCursor
.getString(myCursor
.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.DATA));
} finally {
// myCursor.close();
}
// Create new Cursor to obtain the file Path for the large image
String[] largeFileProjection = {
MediaStore.Images.ImageColumns._ID,
MediaStore.Images.ImageColumns.DATA };
String largeFileSort = MediaStore.Images.ImageColumns._ID + " DESC";
myCursor = this.managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
largeFileProjection, null, null, largeFileSort);
largeImagePath = "";
try {
myCursor.moveToFirst();
// This will actually give yo uthe file path location of the
// image.
largeImagePath = myCursor
.getString(myCursor
.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.DATA));
} finally {
// myCursor.close();
}
// These are the two URI's you'll be interested in. They give you a
// handle to the actual images
uriLargeImage = Uri.withAppendedPath(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
String.valueOf(imageId));
uriThumbnailImage = Uri.withAppendedPath(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
String.valueOf(thumbnailImageId));
// I've left out the remaining code, as all I do is assign the URI's
// to my own objects anyways...
// Toast.makeText(this, ""+largeImagePath,
// Toast.LENGTH_LONG).show();
// Toast.makeText(this, ""+uriLargeImage, Toast.LENGTH_LONG).show();
// Toast.makeText(this, ""+uriThumbnailImage,
// Toast.LENGTH_LONG).show();
if (largeImagePath != null) {
Toast.makeText(this, "LARGE YES" + largeImagePath,
Toast.LENGTH_LONG).show();
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = OG;
// thumbnail = (BitmapFactory.decodeFile(picturePath));
thumbnail = BitmapFactory.decodeFile((largeImagePath), opts);
Bitmap bitmap = thumbnail;
System.gc();
try {
ExifInterface exif = new ExifInterface(largeImagePath);
orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION, 1);
Log.e("ExifInteface .........", "rotation =" + orientation);
// exif.setAttribute(ExifInterface.ORIENTATION_ROTATE_90,
// 90);
Log.e("orientation", "" + orientation);
Matrix m = new Matrix();
if ((orientation == ExifInterface.ORIENTATION_ROTATE_180)) {
m.postRotate(180);
// m.postScale((float) bm.getWidth(), (float)
// bm.getHeight());
// if(m.preRotate(90)){
Log.e("in orientation", "" + orientation);
bitmap = Bitmap.createBitmap(thumbnail, 0, 0,
thumbnail.getWidth(), thumbnail.getHeight(), m,
true);
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
m.postRotate(90);
Log.e("in orientation", "" + orientation);
bitmap = Bitmap.createBitmap(thumbnail, 0, 0,
thumbnail.getWidth(), thumbnail.getHeight(), m,
true);
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
m.postRotate(270);
Log.e("in orientation", "" + orientation);
bitmap = Bitmap.createBitmap(thumbnail, 0, 0,
thumbnail.getWidth(), thumbnail.getHeight(), m,
true);
}
} catch (Exception e) {
}
if (thumbnail != null) {
// Toast.makeText(this, "Try Without Saved Instance",
// Toast.LENGTH_LONG).show();
imageCam(bitmap);
}
}
if (uriLargeImage != null) {
// Toast.makeText(this, ""+uriLargeImage,
// Toast.LENGTH_LONG).show();
}
if (uriThumbnailImage != null) {
// Toast.makeText(this, ""+uriThumbnailImage,
// Toast.LENGTH_LONG).show();
}
}
if (requestCode == 1337 && resultCode == RESULT_OK) {
flagg = 0;
Bundle extras = data.getExtras();
// if (extras!=null){
if (extras.keySet().contains("data")) {
BitmapFactory.Options options = new BitmapFactory.Options();
// options.inSampleSize = 1;
// options.inPurgeable = true;
// options.inInputShareable = true;
thumbnail = (Bitmap) extras.get("data");
// image(thumbnail);
if (thumbnail != null) {
// Toast.makeText(this, "YES Thumbnail",
// Toast.LENGTH_LONG).show();
BitmapFactory.Options opt = new BitmapFactory.Options();
// options.inSampleSize = 1;
// options.inPurgeable = true;
// options.inInputShareable = true;
thumbnail = (Bitmap) extras.get("data");
imageCam(thumbnail);
}
} else {
Uri imageURI = getIntent().getData();
ImageView imageview = (ImageView) findViewById(R.id.imageView1);
imageview.setImageURI(imageURI);
if (imageURI != null) {
// Toast.makeText(this, "YES Image Uri",
// Toast.LENGTH_LONG).show();
}
// Toast.makeText(CreateProfile.this, "Picture NOt taken",
// Toast.LENGTH_LONG).show();
}
}
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK
&& null != data) {
Uri selectedImage = data.getData();
flagg = 1;
String[] filePathColumn = { MediaStore.Images.Media.DATA };
cursor1 = getContentResolver().query(selectedImage, filePathColumn,
null, null, null);
cursor1.moveToFirst();
int columnIndex = cursor1.getColumnIndex(filePathColumn[0]);
String picturePath = cursor1.getString(columnIndex);
// cursor.close();
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = OG;
// thumbnail = (BitmapFactory.decodeFile(picturePath));
thumbnail = BitmapFactory.decodeFile((picturePath), opts);
System.gc();
Bitmap bitmap = thumbnail;
try {
ExifInterface exif = new ExifInterface(picturePath);
orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION, 1);
Log.e("ExifInteface .........", "rotation =" + orientation);
// exif.setAttribute(ExifInterface.ORIENTATION_ROTATE_90, 90);
Log.e("orientation", "" + orientation);
Matrix m = new Matrix();
if ((orientation == ExifInterface.ORIENTATION_ROTATE_180)) {
m.postRotate(180);
// m.postScale((float) bm.getWidth(), (float)
// bm.getHeight());
// if(m.preRotate(90)){
Log.e("in orientation", "" + orientation);
bitmap = Bitmap.createBitmap(thumbnail, 0, 0,
thumbnail.getWidth(), thumbnail.getHeight(), m,
true);
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
m.postRotate(90);
Log.e("in orientation", "" + orientation);
bitmap = Bitmap.createBitmap(thumbnail, 0, 0,
thumbnail.getWidth(), thumbnail.getHeight(), m,
true);
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
m.postRotate(270);
Log.e("in orientation", "" + orientation);
bitmap = Bitmap.createBitmap(thumbnail, 0, 0,
thumbnail.getWidth(), thumbnail.getHeight(), m,
true);
}
} catch (Exception e) {
}
if (thumbnail != null) {
imageCam(bitmap);
} else {
Toast.makeText(this, "Please select a different picture",
Toast.LENGTH_LONG).show();
}
}
else {
// imgview.setBackgroundResource(R.drawable.bbtb);
}
}
}