about Using Drop library

edited August 5 in Library Questions

hello gentlemen, I'm new to processing. and can use C little a bit.

Thanks for everyone who developing processing and libraries.

Anyway, I'm trying to make a program for CNC based DIY printer.

I tried to use Drop library for loading images, and am having some troubles.

Image files were successfully loaded. But when I try to get dimensions of image with ".width" and ".height", it fails.

Here are some cases that I've tried.

text(img.width,xx,yy);
==> My program frizzes and "Null pointer Exeption" is showed on consol.

println(img.width); ==> My program runs anyway... and only "4" is displayed on consol, always.

Well...

I'm trying another methods to get sizes of image, but hope to know what's the problem...

Thanks for your attention.

Answers

  • Answer ✓

    What are the dimensions of your image? If you open it with your favorite image editor, you should be able to see its dimensions. If you are in Windows, right click on the image, click properties and go to details. There you can see the image dimensions as well.

    If you get a NPE then it means you are accessing the image before is loaded or the image loading failed (?). What is important first is to get the right dimensions. If you cannot get the right dimensions, then you need to post a minimum amount of code reproducing the problem.

    Kf

  • edited August 5

    I'm really sorry for my fool question ;{ I'll stop drinking....

    I found that I was trying to print the sizes before loading image.

    Sure, the size values were Null.

    But I still don't know why width and height are temporary "4"....

    When load image, "4" shows on screen, but soon right sizes are shown.

  • edited August 6

    This is my code... (sorry I have no idea, how to post right way.:((

    `

    import drop.*;
    SDrop drop;
    PImage img;
    
    void setup() {
      size(800, 600);
      drop = new SDrop(this);
    }
    
    
      void draw() {
        background(1);
    
    
    
        //fill loaded image
        if (img !=null) {
          image(img, 10, 10,width/2,height/2);
        }
    
        //write the size of image
        if (img !=null) {
          textSize(18);
          text(str(img.width),500,30);
          text(str(img.height),500,60);
        }
    
    
    
    
    
    
      }
    
      void dropEvent(DropEvent theDropEvent) {
        println("");
        println("isFile()\t"+theDropEvent.isFile());
        println("isImage()\t"+theDropEvent.isImage());
        println("isURL()\t"+theDropEvent.isURL());
    
        // if the dropped object is an image, then 
        // load the image into our PImage.
        if (theDropEvent.isImage()) {
          println("### loading image ...");
          img = theDropEvent.loadImage();
    
        }
      }
    

    `

  • Answer ✓

    Please edit your post (gear icon in the top right corner of your post), select your code and hit ctrl+o to format it. Make sure there is an empty line above and below your code.

    I ran the example dopLoadImage.pde, provided by the Drop library with your modifications, and I don't get any size while the image is null (as expected). I suggest you start building you code from that example, which is similar to what you have right now.

    Kf

  • Thanks a lot for help =D>

    I've solved the size problem.

    And posting problem too.

  • edited August 7

    Here's my new code that works. I'm trying some tricks, and saving CPU power by reducing frame rate. `

                    import drop.*;
                    SDrop drop;
    
                    PImage img, imgGray, imgThres;
    
    
                    void setup() {
                      size(800, 600);
                      frameRate(4);
                      drop = new SDrop(this);
                      background(1);
                    }
    
    
                      void draw() {
    
    
                        if (img !=null ) {
    
                          imgGray = img.get();// make a copy
                          imgThres = img.get();// make a copy
    
                          imgGray.filter(GRAY);
                          imgThres.filter(THRESHOLD, 0.5);
    
                          background(1);
    
                          //fill loaded image
                          image(img, 10, 10,300,250);
                          image(imgGray, 10, 270, 300, 250);
                          image(imgThres, 320, 10, 300, 250);
    
    
                          //write the size of image 
                          textSize(18);
                          text("Img size :",700,30);
                          text(str(img.width)+"*"+str(img.height),700,60);
    
                        }
    
    
                      }
    
                      void dropEvent(DropEvent theDropEvent) {
                        println("");
                        println("isFile()\t"+theDropEvent.isFile());
                        println("isImage()\t"+theDropEvent.isImage());
                        println("isURL()\t"+theDropEvent.isURL());
    
                        // if the dropped object is an image, then 
                        // load the image into our PImage.
                        if (theDropEvent.isImage()) {
                          println("### loading image ...");
                          img = theDropEvent.loadImage();
    
                        }
                      }
    

    `

  • Great to hear it is working. Thxs for sharing your final solution.

    Kf

Sign In or Register to comment.