【问题标题】:Resize photo in Appcelerator Titanium before save保存前在 Appcelerator Titanium 中调整照片大小
【发布时间】:2012-09-13 05:06:42
【问题描述】:

我在使用 Appcelerator 保存照片时遇到了一点麻烦。

我正在拍照并保存它,好吧,那就是工作,这是代码:

var cameraOverlay = Ti.UI.createView({
    width:'100%',
    height:'100%'
});

var porcoOverlay = Ti.UI.createView({
    width: '90%',
    height: '100%',
    left: 0,
    top: 0
});
var porco = Ti.UI.createImageView({
    width: 200,
    height: 238,
    top: 10,
    left: 10,
    image:'images/pig.png',
    touchEnabled: false
});
porcoOverlay.add(porco);
cameraOverlay.add(porcoOverlay);

var menuOverlay = Ti.UI.createView({
    width: '10%',
    height: '100%',
    right: 0,
    top: 0
});
var takeFoto = Ti.UI.createButton({
    title: 'PH',
    bottom: 10,
    right: 10
});
menuOverlay.add(takeFoto);
cameraOverlay.add(menuOverlay);



Ti.Media.showCamera({
    showControls:true,
    overlay: cameraOverlay,
    saveToPhotoGallery: true,
    success:function(event) {

        var cropRect = event.cropRect;
        var image = event.media;

        var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'camera_photo.png');
        f.write(image);

    }
});

takeFoto.addEventListener('click',function(){
    Ti.Media.takePicture();
});

这是我的问题:

1 - 自动对焦不起作用;

2 - 图像分辨率始终为:320*240;

3 - 我想用照片加入叠加层并保存;

谁能帮帮我?

【问题讨论】:

    标签: android iphone camera titanium appcelerator


    【解决方案1】:

    @布鲁诺·阿尔梅达 您的代码几乎是正确的。 根据此查询,您希望使用预定义的高度和宽度(像素)保存图像。 如果是,那么您可以试试这个示例This 我认为这对我很有用。 求助 !看懂这段代码

    var ImageFactory = require('ti.imagefactory');
    // Save your Image 
    
    savedFile.write(event.media);
    // Read you Image in Blob Format                    
    var blob = savedFile.read();
    
    //  Resize this image through use ImageFactory Module.
    
    newBlob = ImageFactory.imageAsResized(blob, { width:300, height:300, quality:ImageFactory.QUALITY_LOW });
      savedFile.write(newBlob);
      blob = savedFile.read();
    

    【讨论】:

    • 谢谢!但是我尝试将这段代码放在成功回调中,将模块插入到正确的文件夹中,但没有生效。图像仍然是 320*240,但我想用我的 5mp 相机拍一张高质量的照片。我以前从未处理过图像,所以我真的迷路了!
    • 这是银河系,有 5MP 摄像头!但是使用叠加层,照片始终是 320*240,如果我取下叠加层,相机会以 5mp 和自动对焦拍摄普通照片。
    【解决方案2】:
    MV.utils.ImageUtils.resize(image, 500, 500);
    

    【讨论】:

    • 接受简洁,但稍加解释总是更有帮助:)
    猜你喜欢
    • 2017-06-14
    • 2013-04-10
    • 2015-07-24
    • 1970-01-01
    • 2017-01-27
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    相关资源
    最近更新 更多