保存前在Appcelerator Titanium中调整照片大小

问题描述 投票:1回答:2

我在使用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
2个回答
2
投票

@Bruno Almeida您的代码几乎是正确的。根据此查询,您希望使用预定义高度和宽度(像素)保存图像。如果是,那么你可以尝试这个例子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();

-1
投票
MV.utils.ImageUtils.resize(image, 500, 500);
© www.soinside.com 2019 - 2024. All rights reserved.