Пример #1
0
 success: function(event) {
     var image = event.media;
     if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
         var nativePath = event.media.nativePath;
         ImageFactory.rotateResizeImage(nativePath, pWidth, 100);
         Ti.App.Properties.setString("colour_picker_image", image.nativePath);
         Ti.App.fireEvent("web:loadImage", {
             image: image.nativePath
         });
     }
 },
/**
 * Capture event
 * 
 * @param {Object} e
 */
function captureSuccess(e) {
  var nativePath = e.media.nativePath;
  
  // Read exif information before rotating and resizing the image, because 
  // data is not conserved after altering the image due to performance
  var exifInformation = 'Exif information:' + "\n";
  for (tag in exifTags)
  {
    exifInformation += "\n" + tag + ': ' + ImageFactory.getExifTag(nativePath, exifTags[tag]);
  }
  
  var maximumSize = 800;
  var jpegQuality = 70;
  
  ImageFactory.rotateResizeImage(nativePath, maximumSize, jpegQuality);
  
  previewImage.image = nativePath;
  
  alert(exifInformation);
};
exports.rotate = function (photoBlob, nativePath) {
  Ti.API.debug('Original Image :', photoBlob.width, ' * ', photoBlob.height, 'photoBlob.nativePath :', photoBlob.nativePath, "nativePath :", nativePath);

  var rotateImage;

  if (OS_ANDROID) {
    // only android
    var fhImageFactory = require("fh.imagefactory");
    var maximumSize = (photoBlob.width > photoBlob.height) ? photoBlob.width : photoBlob.height;
    var nativePath = nativePath || photoBlob.nativePath;
    fhImageFactory.rotateResizeImage(nativePath, maximumSize, 100);
    rotateImage = Titanium.Filesystem.getFile(nativePath).read();
  }else {
    // return original
    rotateImage = photoBlob;
  }

  return rotateImage;
};
exports.resize = function (photoBlob, targetView, nativePath) {
  var ImageFactory = require('ti.imagefactory');

  Ti.API.debug('Original Image :', photoBlob.width, ' * ', photoBlob.height, 'photoBlob.nativePath :', photoBlob.nativePath, "nativePath :", nativePath);

  var resizedImage, croppedImage;
  var isCompressed = false;

  if (OS_ANDROID) {
    var fhImageFactory = require("fh.imagefactory");
    var maximumSize = null;

    //이미지를 리사이즈 하면서 돌리자
    if (photoBlob.width > photoBlob.height) {
      // 가로가 길때
      var rateWH = photoBlob.width / photoBlob.height;
      var targetHeight = APP.Settings.image.width;
      var targetWidth = targetHeight * rateWH;
      maximumSize = targetWidth;
    } else {
      // 세로가 길때
      var rateHW = photoBlob.height / photoBlob.width;
      var targetWidth = APP.Settings.image.width;
      var targetHeight = targetWidth * rateHW;
      maximumSize = targetHeight;
    }
    var nativePath = nativePath || photoBlob.nativePath;
    fhImageFactory.rotateResizeImage(nativePath, maximumSize, 100 * APP.Settings.image.quality);
    isCompressed = true;
    resizedImage = Titanium.Filesystem.getFile(nativePath).read();
    Ti.API.debug('Resize Image : ', resizedImage.width, ' * ', resizedImage.height);
  }else {
    //촬영한 이미지 비율.
    var rateHW = photoBlob.height / photoBlob.width;

    var targetWidth = APP.Settings.image.width;
    var targetHeight = targetWidth * rateHW
    resizedImage = ImageFactory.imageAsResized(photoBlob, {
      width : targetWidth,
      height : targetHeight
    });
    Titanium.API.info('Resize Image : ', targetWidth, ' * ', targetHeight);
  }

  // 화면에 표시된 영역 만큼만 크롭
  if(targetView){
    var cropHWRate = targetView.size.height / targetView.size.width;
    var cropWidth = targetWidth;
    var cropHeight = cropWidth * cropHWRate;
    //가짜 이미지에서는 crop범위가 클경우 자르지 않는다.
    //  Error: x + width must be <= bitmap.width()
    if(cropWidth > resizedImage.width){
      Titanium.API.info('not crop : cropWidth : ', cropWidth, '> bitmapWidth ', resizedImage.width);
      croppedImage = resizedImage;
    }else{
      croppedImage = ImageFactory.imageAsCropped(resizedImage,{
        x: 0,
        y: 0, //상단에 nav영역이 있다면 그 높이 만큼
        width: cropWidth,
        height: cropHeight
      });
      Titanium.API.info('Crop Image : ', cropWidth, ' * ', cropHeight);
    }

  }

  var imageToCompress = croppedImage || resizedImage;
  // 이미지 압축을 하자
  return  isCompressed ? imageToCompress : ImageFactory.compress(imageToCompress, APP.Settings.image.quality);
};