[TIMOB-7848] Android: Cannot save rotated camera images
GitHub Issue | n/a |
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2013-10-29T21:08:02.000+0000 |
Affected Version/s | Release 2.0.0, Release 3.1.0 |
Fix Version/s | 2013 Sprint 23, 2013 Sprint 23 API |
Components | Android |
Labels | n/a |
Reporter | Varun Joshi |
Assignee | Ping Wang |
Created | 2012-02-29T10:36:13.000+0000 |
Updated | 2017-03-23T21:38:23.000+0000 |
Description
The attached app.js file reproduces the issue. Here are the steps:
1. Start the app and take a picture and save it.
2. It is saved to an imageview. Click on the imageview to rotate the image.
3. Now, you will get an alert showing the location of the rotated image. I have it saved on the sdcard.
4. View the sdcard to see the image (you will need a file manager to view it).
5. The image is saved as the originally taken and not the rotated.
Here is the sample file:
{noformat}
var win = Titanium.UI.createWindow({
backgroundColor:'white'
});
Titanium.Media.showCamera({
success:function(event)
{
var cropRect = event.cropRect;
var image = event.media;
Ti.API.debug('Our type was: '+event.mediaType);
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
{
/******** capture image in a imageView ********/
var imageView = Ti.UI.createImageView({
width:win.width,
height:win.height,
image:event.media
});
win.add(imageView);
/******** rotate the imageView ************/
var transformCurrentPicture = Titanium.UI.create2DMatrix();
imageView.addEventListener('click',function(e){
transformCurrentPicture = transformCurrentPicture.rotate(90);
imageView.animate({transform:transformCurrentPicture});
savePhoto('Hello.png',imageView.toBlob());
});
// savePhoto('Hello',imageView.toBlob());
}
else
{
alert("got the wrong type back ="+event.mediaType);
}
},
cancel:function()
{
},
error:function(error)
{
// create alert
var a = Titanium.UI.createAlertDialog({title:'Camera'});
// set message
if (error.code == Titanium.Media.NO_CAMERA)
{
a.setMessage('Please run this test on device');
}
else
{
a.setMessage('Unexpected error: ' + error.code);
}
// show alert
a.show();
},
saveToPhotoGallery:true,
allowEditing:true,
mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO]
});
win.open();
/******* function to save the image **********/
function savePhoto(photoName,photoToSave){
var photoPath = '';
var photoDir = '';
//Check for photo dir and create if not there
if (Titanium.Filesystem.isExternalStoragePresent()){
photoDir = Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory, 'PlayGroundPhotos');
if ( ! photoDir.exists()){
photoDir.createDirectory();
}
}
//check for photo dir and create if not there locally since no external storage
else{
photoDir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'PlayGroundPhotos');
if ( ! photoDir.exists()) {
photoDir.createDirectory();
}
else{
alert('photoDir exists');
}
}
//At this point we know if SD card exists and have created photo directory if needed
photoPath = photoDir.nativePath;
alert('The photopath is: '+photoPath);
var f = Titanium.Filesystem.getFile(photoPath,photoName);
f.write(photoToSave);
}
{noformat}
Attachments
File | Date | Size |
1.png | 2013-03-20T09:47:44.000+0000 | 509265 |
2.png | 2013-03-20T09:47:44.000+0000 | 285136 |
3.png | 2013-03-20T09:47:44.000+0000 | 146186 |
4.jpg | 2013-03-20T09:47:44.000+0000 | 2817928 |
It seems to be a bug, Here i attached my observation . 1.After taking photo 2.After click save, it shows 90 degree rotated imageview 3.when clicking on imageview it rotate to original state 4.photo in sdcard
This is not a valid test case. The method
only applies a rotation matrix to the canvas to render the imageview but not changes/rotates the image itself. Therefore the saved file is always the original image. Resolved the ticket as Invalid.
Closing ticket as invalid with reference to the previous comments.