我目前正在开发一款Android应用程序,允许用户旋转图像然后保存。我可以保存图像但是当我检查它时,它不会旋转。如果有人能指出我正确的方向,我将不胜感激。
这是我的代码:
_rotateLeft.addEventListener('click', function(e){
_rotationDegree = _rotationDegree - 90;
var t = Ti.UI.create2DMatrix();
//t.rotate(90);
//imageContainer.transform = t;
imageContainer.animate({
transform: t.rotate(_rotationDegree)
});
});
_saveButton.addEventListener('click', function(){
var imgSave = imageView.toImage();
var moment = require('alloy/moment');
var directory = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, 'images/test');
!directory.exists() && directory.createDirectory();
var fileName = String.format('rotate_%s.jpg', moment().format('YYYY-MM-DD-HH-mm'));
var file = Ti.Filesystem.getFile(directory.resolve(), fileName);
var fileNativePath = file.nativePath;
// Write media to file
//file.write(newBlob);
file.write(imgSave);
Ti.API.info('New Save File : ' + JSON.stringify(file));
imageView.setImage(file);
});
以下是我的观点:
<View id="imageContainer">
<!--<View id="imageUploadedView"></View>-->
<ImageView id="imageView"></ImageView>
</View>
答案 0 :(得分:1)
我的代码中有两件事我发现很奇怪:
1 - 您正在旋转 imageContainer ,然后您正在捕获 imageView.toImage(); ,我认为这是问题的原因,因为:
2 - 在 _saveButton 点击事件中,请使用以下行:
A new entity was found through the relationship '***' that was not configured to cascade persist operations for entity:
***. To solve this issue: Either explicitly call EntityManager#persist() on
this unknown entity or configure cascade persist this association in the
mapping for example @OneToOne(..,cascade={"persist"}). If you cannot find
out which entity causes the problem implement '***#__toString()' to get a clue.
,因为您没有在代码中读取文件的blob数据。
答案 1 :(得分:0)
您需要先声明变换,然后在保存之前将变换应用于视图。
_rotateLeft.addEventListener('click', function(e){
var rotateTransform = Ti.UI.create2DMatrix({
rotate: 45
});
imageContainer.transform = rotateTransform;
}
参考:http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.2DMatrix