1

现在已经5天了,没有人帮忙!!请问谁能帮帮我

我有一个问题,并且仅适用于 Samsumg S3 手机。我正在尝试从 android 的相机服务中拍摄 4 张图像。

问题是当我尝试为其他手机执行此操作时,相同的代码可以正常工作,但显示三星 S3 手机存在问题。

我想做的是有4个Imageview,在每个imageview的onclick上,我可以根据用户的选择打开相机服务或图库服务。单击或选择图像后,该图像将设置在单击的特定图像视图上。

所以我可以一张一张地设置所有 4 张图像。这适用于其他手机和其他三星手机,但三星 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);
    }

}

}
4

0 回答 0