简体   繁体   中英

CamanJS image manipulation, strange error

i'm using CamanJS to do some images manipulation with javascript, and I have two similar really simple scripts, the first works well, the second not (and this is the script i need working).

This is the first working:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>CamanJS Testing Playground</title>
    <script type="text/javascript" src="caman.full.min.js"></script>
</head>
<body>
    <button onclick="filtraPhoto();">MODIFICA</button><br />
    <img id="smallImage" />
    <script>
    var immagine;
    var smallImage = document.getElementById('smallImage');
    smallImage.src = "test1_600.jpg";
    immagine = Caman("#smallImage", function () {});
    function filtraPhoto() {
        immagine.brightness(10).contrast(500).render(function () {
            alert("Done!");
        });
    }
    </script>
</body>
</html>

This is the second not working, it return in firebug the error: TypeError: this.c.pixelData is undefined

<!DOCTYPE html>
<html lang="en">
<head>
    <title>CamanJS Testing Playground</title>
    <script type="text/javascript" src="caman.full.min.js"></script>
    <script>
    var immagine;
    function carica()
    {
        var smallImage = document.getElementById('smallImage');
        smallImage.src = "test1_600.jpg";
        immagine = Caman("#smallImage", function () {});
    }
    function filtraPhoto() {
        immagine.brightness(10).contrast(500).render(function () {
            alert("Done!");
        });
    }
    </script>
</head>
<body>
    <button onclick="carica();">carica immagine</button><br />
    <button onclick="filtraPhoto();">MODIFICA</button><br />
    <img id="smallImage" />
</body>
</html>

Any help please?

It runs just fine in both Firefox and Chrome for me. In my limited experience, this.c.pixelData typically comes when your conversion to a CamanInstance was not successfully created.

This can be because of many things, but one that isn't expected is that CamanJS won't let you use the same html identifier (class or id) for more than one object, even if you've swapped them out. So if you're running the two scripts above on the same page, it will cause errors.

Sorry, without being able to reproduce your error, it's hard to help more than that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM