我想以圆形显示图像,我能够以圆形显示用户图像,但无法管理图像质量。图像正在缩小/拉伸。我正在尝试在Android设备中测试它。< / p>
Titanium studio信息
Titanium Studio,build:3.4.1.201410281727 Build:jenkins-titanium-rcp-master-202
拉伸图像的设备截图。 http://i60.tinypic.com/23hq9lv.png
我的代码如下。
查看
<View id="userpiceView">
<ImageView id="userImage" onClick="chooesPic"></ImageView>
</View>
TSS
"#userpiceView":{
left : "10%",
width: 84,
height: 84,
borderRadius: 42,
borderColor: '#f05323',
borderWidth: 3,
}
"#userImage":{
autorotate: true,
image: "/images/defaultuser.png",
defaultImage: "/images/defaultuser.png",
}
控制器
function chooesPic() {
Titanium.Media.openPhotoGallery(
{
mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO],
success : function(event) {
var imageG = event.media;
Ti.API.info("before" + imageG.height + " x " + imageG.width);
Ti.API.info("before" + imageG.length);
try{
var imgBlob = imageG.imageAsResized(300,300);
imageG=null;
Ti.API.info("after imgBlob " + imgBlob.height + " x " + imgBlob.width);
$.userImage.image=imgBlob;
imgBlob=null;
}catch(e){
Ti.API.info("Image conversion error"+e );
}
if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
var filename = Titanium.Filesystem.applicationDataDirectory + "/" + 'camera_photo' + new Date().getTime() + ".png";
var f = Titanium.Filesystem.getFile(filename);
if (f.exists()) {
f = Titanium.Filesystem.getFile(filename);
}
f.write(imageG);
pathfromgallery = f.nativePath;
}
}
});}