Giter VIP home page Giter VIP logo

Comments (14)

yagitoshiro avatar yagitoshiro commented on August 14, 2024

will you please try the latest commit?
83493e2

from imageasresized.

cmdaltent avatar cmdaltent commented on August 14, 2024

Thanks for your help. Unfortunately, the issue still occurs. I get the following debug message from Android monitor:

Bitmap IOException:java.io.FileNotFoundException: /mnt/sdcard/app_identifier/mnt/sdcard/app_identifier/preview__tifile46090tmp.jpg (No such file or directory)

I guess the first path of the file path is wrong. It starts again with '/mnt/sdcard/...'. I used again file.nativePath.

from imageasresized.

yagitoshiro avatar yagitoshiro commented on August 14, 2024

Ah, I understand what was wrong. I have fixed the problem so please try the newest one.
example/app.js has been also updated and works correctly.

var sd_file = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory + 'tmp.jpg');
var sd_card_image = androimage.imageAsResized(width, height, sd_file.nativePath, 0);

from imageasresized.

yagitoshiro avatar yagitoshiro commented on August 14, 2024

now you can both use nativePath and Ti.Filesystem.externalStorageDirectory + path. and also fixed to handle Ti.Filesystem.applicationDataDirectory correctly.

from imageasresized.

p0las avatar p0las commented on August 14, 2024

hi,
first of all thank you for this module!!! I have serious problems resizing large images using titanium built it 'imageAsResized' and I hope yours will use memory and allow me to finish my app. Anyway I have the same problem as cmdaltent even using the latest 0.5 version.

[DEBUG]ImageasresizedModule( 2161) [41,78252] Bitmap IOException:java.io.FileNotFoundException: file:///mnt/sdcard/Download/photo_giant-1.jpg

I use the path provided by media module which returns, in my test case, this:

{
"height" : 3744,
"width" : 5616,
"cropRect" : {
"height" : 3744,
"y" : 0,
"width" : 5616,
"x" : 0
},
"code" : 0,
"media" : {
"bubbleParent" : true,
"nativePath" : "file:///mnt/sdcard/Download/photo_giant-1.jpg",
"type" : 1,
"file" : {
"hidden" : false,
"nativePath" : "content://media/external/images/media/477",
"writable" : false,
"executable" : false,
"parent" : null,
"readonly" : true,
"directoryListing" : null,
"size" : 0,
"name" : "photo_giant-1.jpg",
"symbolicLink" : false,
"bubbleParent" : true
},
"height" : 3744,
"length" : 2518844,
"text" : null,
"width" : 5616,
"mimeType" : "image/jpeg"
},
"success" : true,
"mediaType" : "public.image",
"y" : 0,
"x" : 0
};

does the compiled 0.5 version contain this fix?
cheers

from imageasresized.

p0las avatar p0las commented on August 14, 2024

a sanity check:

//this works OK
var file = Ti.Filesystem.getFile(event.media.nativePath);
Ti.API.debug(JSON.stringify(file));
var blob = file.read();
Ti.API.debug(JSON.stringify(blob));

//this complains that file doesn't exist
var PhotoManip = require('org.selfkleptomaniac.ti.imageasresized');
var cropped_image = PhotoManip.imageAsResized(64, 106, event.media.nativePath, 0);

from imageasresized.

p0las avatar p0las commented on August 14, 2024

I tried to use your cameraImageAsResized on a blob and it almost works. The problem is it also crops the image.The image it creates has correct dimensions but is cropped (before resizing)

var cropped_image=PhotoManip.cameraImageAsResized(event.media, parseInt(event.media.width/20),parseInt(event.media.height/20), 0);

(the right image is stretched by imageView on y)

test

according to "known issues" I shouldn't change image proportions. so I tried:

var PhotoManip = require('org.selfkleptomaniac.ti.imageasresized');
var cropped_image=PhotoManip.cameraImageAsResized(event.media, 900,600, 0);

the original image is: 5616x3744 with aspect ration 1.5
the new test dimensions are 900x600 with exact same aspect ratio.
the final image is small crop of the background only.

if you could fix any of those problem you make me really happy :-)
so far your module is the only one that can deal with large images on android!
thank you

from imageasresized.

yagitoshiro avatar yagitoshiro commented on August 14, 2024

Can I have the image that you are using?

from imageasresized.

p0las avatar p0las commented on August 14, 2024

Sure.

Http://polas.net/Http://polas.net/photo_giant.jpg

from imageasresized.

yagitoshiro avatar yagitoshiro commented on August 14, 2024

This module has 2 separate methods. cameraImageAsResized takes TiBlob. While the other one, imageAsResized,
accepts a file path.

  var camera = Ti.Media.openPhotoGallery({
    success: function(e){
      //var camera_data = image_module.cameraImageAsResized(e.media , w, h, 0); // works, this method accepts only TiBlob
      var camera_data = image_module.imageAsResized(w, h, e.media.nativePath, 0); // this method accepts file path
    }

I'm sorry for the irrelevant order of arguments. I know it's wrong. But it's alright as long as it works. Justice is might.

I tested your image (thanks) and found that it works fine only when reduction rate is integer. Take a look at this sample.

  // select your image saved in Gallery
  var camera = Ti.Media.openPhotoGallery({
    success: function(e){
      Ti.API.info(JSON.stringify(e));
      var media = e.media;
      var image_module = require('org.selfkleptomaniac.ti.imageasresized');
      // var h = e.cropRect.height / 6.24; // not working
      // var w = e.cropRect.height / 6.24; // not working
      var h = e.cropRect.height / 8; // success because it's an integer
      var w = e.cropRect.width / 8; // success because it's an integer
      var camera_data = image_module.cameraImageAsResized(media , w, h, 0);
      // var camera_data = image_module.imageAsResized(w, h, media.nativePath, 0); // this also works
      var camera_image = Ti.UI.createImageView({image:camera_data, canScale:true, height:h/4, width:w/4});
      win.add(camera_image);
    }
  });

iar

from imageasresized.

cmdaltent avatar cmdaltent commented on August 14, 2024

Thanks a lot! It's working!

from imageasresized.

p0las avatar p0las commented on August 14, 2024

thanks mate for looking into it. your test case works because the test image is divisible by 8. It seems that it is almost impossible (for randomly cropped photos) to find integer scale ratio that also preserves proportions. this, for instance, fails:

 var h = parseInt(e.cropRect.height / 10); // integer but failure
 var w = parseInt(e.cropRect.width / 10); 

what I'm after is an ability to get any image from user library and centre crop it and scale to something small like 600x600px.

I tried cropping the image before scaling but there is not enough memory to do that on large images (I get java exception). So I need to resize the image to something manageable before I can process it further.

looking at your code it should be possible to combine resize and crop into one function (as both call the same one under the hood). maybe then there will be less restrictions?

from imageasresized.

yagitoshiro avatar yagitoshiro commented on August 14, 2024

How about this module?
https://github.com/yagitoshiro/CropImage

from imageasresized.

p0las avatar p0las commented on August 14, 2024

i will give it a go. however I still need rotate functionality from this one (to fix orientation base on EXIF data).
Ideally I will create one matrix to handle crop + scale + rotate in one operation.
looking at your code it shouldn't be too hard to do. I may try to write my own module with that one purpose. If I come up with working solution I will send you the code.

I'm still confused why scale factor has to be an integer. It doesn't make any sense and looking at other people solutions they definetely pass floats to scale to matricies. And according to android API scale parameter is float on the matix (actually all matrix values are floats).

http://www.anddev.org/resize_and_rotate_image_-_example-t621.html

from imageasresized.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.