上传到s3的图像具有相同的图像名称,但是当我打开图像时看到的图像不同

时间:2017-08-18 09:23:07

标签: android amazon-s3

我从我的Android手机拍照并上传到s3,图片上传成功,我也可以在s3中看到相同的图片名称但是图片里面的图片与我上传的图片不同显示带有新图像名称的旧图片。

代码:

protected void takePicture() {
        if (null == cameraDevice) {
            Log.e(TAG, "cameraDevice is null");
            return;
        }
        CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
        try {
            CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraDevice.getId());
            Size[] jpegSizes = null;
            if (characteristics != null) {
                jpegSizes = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP).getOutputSizes(ImageFormat.JPEG);
            }
            if (jpegSizes != null && 0 < jpegSizes.length) {
                width = jpegSizes[0].getWidth();
                height = jpegSizes[0].getHeight();
            }
            ImageReader reader = ImageReader.newInstance(width, height, ImageFormat.JPEG, 1);
            List<Surface> outputSurfaces = new ArrayList<Surface>(2);
            outputSurfaces.add(reader.getSurface());
            outputSurfaces.add(new Surface(textureView.getSurfaceTexture()));
            final CaptureRequest.Builder captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
            captureBuilder.addTarget(reader.getSurface());
            captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
            // Orientation
            int rotation = getWindowManager().getDefaultDisplay().getRotation();
            captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));
            final File file = new File(Environment.getExternalStorageDirectory() + "/"+name+"_"+dl+".jpg");
            final ImageReader.OnImageAvailableListener readerListener = new ImageReader.OnImageAvailableListener() {
                @Override
                public void onImageAvailable(ImageReader reader) {
                    Image image = null;
                    try {
                        image = reader.acquireLatestImage();
                        ByteBuffer buffer = image.getPlanes()[0].getBuffer();
                        byte[] bytes = new byte[buffer.capacity()];
                        buffer.get(bytes);
                        save(bytes);
                        mBitmapToSave1 = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                        mBitmapToSave = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                        Bitmap scaled = Bitmap.createScaledBitmap(mBitmapToSave, width, height, true);
                        int w = scaled.getWidth();
                        int h = scaled.getHeight();
                        // Setting post rotate to 90
                        Matrix mtx = new Matrix();
                        mtx.postRotate(-180);
                        // Rotating Bitmap
                        mBitmapToSave = Bitmap.createBitmap(scaled, 0, 0, w, h, mtx, true);
                        // mBitmapToSave = Bitmap.createBitmap(width+rowPadding/pixelStride,height, Bitmap.Config.RGB_565);
                        // mBitmapToSave.copyPixelsToBuffer(buffer);

                        if (detector.isOperational() && mBitmapToSave != null) {
                            Frame frame = new Frame.Builder().setBitmap(mBitmapToSave).build();
                            SparseArray<Face> faces = detector.detect(frame);

                            for (index = 0; index < faces.size(); ++index) {
                                Face face = faces.valueAt(index);
                            }
                            if (faces.size() == 0) {
                                MediaPlayer mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.not);
                                mediaPlayer.start();
                                //Toast.makeText(AndroidCamera2API.this, "Face Not detected Adjust Camera Properly", Toast.LENGTH_SHORT).show();
                            } else {
                                    c++;
                                    Toast.makeText(AndroidCamera2API.this, "Face Found " + "\n", Toast.LENGTH_SHORT).show();
                                    //Toast.makeText(AndroidCamera2API.this, "Saved:" + file, Toast.LENGTH_SHORT).show();
                                    setFileToUpload();
                                    Toast.makeText(AndroidCamera2API.this, "" +c, Toast.LENGTH_SHORT).show();


                               // Toast.makeText(AndroidCamera2API.this, "completed" , Toast.LENGTH_SHORT).show();


                            }

setFileToUpload方法:

public void setFileToUpload(){


 TransferObserver transferObserver = transferUtility.upload(

                "train-faces/TrainingData"+"/"+name,     /* The bucket to upload to */
                name+"_"+dl+".jpg",    /* The key for the uploaded object */
                fileToUpload       /* The file where the data to upload exists */
        );

        transferObserverListener(transferObserver);
    }

0 个答案:

没有答案