我正在将image
上传到amazon server
。一切运作良好,但只有少数设备orientation
更改为landscape
。在上传几个三星设备和平板电脑上的方向更改时。我试图解决它,但似乎没有任何工作。下面提到的是我的代码。
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
value = true;
viewPager.setVisibility(View.VISIBLE);
Uri takenPhotoUri = getPhotoFileUri(photoFileName); //get the uri of the photo in order to get the path.
System.out.println("URI==" + takenPhotoUri);
al.add(takenPhotoUri);
Bitmap takenImage = BitmapFactory.decodeFile(takenPhotoUri.getPath());
final int maxSize = 1560;
int outWidth, outHeight;
int inWidth = takenImage.getWidth();
int inHeight = takenImage.getHeight();
if (inWidth > inHeight) {
outHeight = maxSize;
outWidth = (inHeight * maxSize) / inWidth;
} else {
outHeight = maxSize;
outWidth = (inWidth * maxSize) / inHeight;
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
takenImage = Bitmap.createScaledBitmap(takenImage, outWidth, outHeight, false);
String newDate = sdf.format(new Date());
Canvas canvas = new Canvas(takenImage); //bmp is the bitmap to dwaw into
Paint paint = new Paint();
paint.setColor(Color.RED);
paint.setTextSize(30);
paint.setTextAlign(Paint.Align.RIGHT);
canvas.drawText(newDate, 200, 100, paint);
//Creating a byte array output stream which is used to store the image once it has been compressed.
ByteArrayOutputStream bos = new ByteArrayOutputStream();
//Compress the image and store it in our ByteArrayOutPutStream
takenImage.compress(Bitmap.CompressFormat.JPEG, 90, bos);
int rotate = 0;
try {
getContentResolver().notifyChange(takenPhotoUri, null);
File imageFile = new File(String.valueOf(al.get(0)));
ExifInterface exif = new ExifInterface(
imageFile.getAbsolutePath());
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
}
Matrix matrix = new Matrix();
matrix.postRotate(rotate);
} catch (Exception e) {
e.printStackTrace();
}
try {
s3Client = new AmazonS3Client(
new BasicAWSCredentials(MY_ACCESS_KEY_ID, MY_SECRET_KEY));
byte[] contentBytes = bos.toByteArray(); //Create a byte array to store the size of the stream.
is = new ByteArrayInputStream(contentBytes);
Long contentLength = Long.valueOf(contentBytes.length);
objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(contentLength);
myAsyncTask = new MyAsyncTask();
myAsyncTask.execute();
responseUrl += s3Client.getResourceUrl(BUCKET_NAME, photoFileName) + " ";
System.out.println("URL IS +==========" + responseUrl);
} catch (Exception e) {
e.printStackTrace();
}
//Add the path of the image to the array list and pass it to our custom adapter.
bitmapArrayList.add(takenImage);
imageSwipeAdapter = new ImageSwipeAdapter(this, iv, bitmapArrayList, viewPager, this, al,
viewPagerLayout, cameraBtn);
viewPager.setAdapter(imageSwipeAdapter);
} else {
Toast.makeText(this, "Picture Wasn't taken!", Toast.LENGTH_SHORT).show();
}
我的AsyncTask
正在后台上传图片。