ImageAsResized icon indicating copy to clipboard operation
ImageAsResized copied to clipboard

RuntimeException: Canvas: trying to use a recycled bitmap

Open Arood opened this issue 11 years ago • 1 comments

I want to resize and crop a picture in Titanium 3.2, but I ran into a out of memory-error on devices where photos are too big. I was recommended to check this module out. I'm however running into some problems:

var resized_image = e.media;
var rate = 16;
var width = e.cropRect.width / rate;
var height = e.cropRect.height / rate;
resized_image = image_module.cameraImageAsResized(resized_image, width, height, 0);
savedImage = resized_image.imageAsThumbnail(400,0,0);
picture.image = savedImage;

I'm using imageAsThumbnail afterwards to make sure that I'm getting a correctly cropped and sizes image, that will later be sent to an API. However, when I'm doing this I get the following message: RuntimeException: Canvas: trying to use a recycled bitmap

Is there a way to fix this?

Arood avatar Dec 20 '13 13:12 Arood

how about this?

  function resizeAndSave(e){
    var image_module = require('org.selfkleptomaniac.ti.imageasresized');
    var resized_image = e.media;
    var rate = 16;
    var width = e.cropRect.width / rate;
    var height = e.cropRect.height / rate;
    resized_image = image_module.cameraImageAsResized(resized_image, width, height, 0);
    var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory + 'tmp.png');
    file.write(resized_image);
    var image_to_be_saved = file.read();
    //savedImage = resized_image.imageAsThumbnail(400,0,0);
    savedImage = image_to_be_saved.imageAsThumbnail(400, 0, 0);
    picture.image = savedImage;
  }

yagitoshiro avatar Dec 21 '13 05:12 yagitoshiro