简体   繁体   中英

Processing 3 as a library for image processing

I'm currently working on image dynamic overlaying in java. My server will render images based on runtime parameters so I need a library to work with Images in a simple manner.

I've heard about Processing and curious about how to use it with my Spring boot server. Can I just use Processing as a Library without setup() draw() functions? Just run processing to load images, make operations on them and upload result in AWS S3 so end client will reach it?

I've tried to just use

import processing.core.PApplet;
import processing.core.PImage;

public class Application {
    public static void main(String[] args) {
        PApplet pApplet = new PApplet();
        PImage pImage = pApplet.loadImage("/home/vadim/Pictures/lena.png");
        PImage pImage2 = pApplet.loadImage("/home/vadim/Pictures/lena.png");

        pImage.blend(pImage2, 0, 0, 50, 50, 0, 0, pImage2.width, pImage2.height, PImage.OVERLAY);
        pImage.save("/home/vadim/Pictures/result.png");
    }
}

Is it possible at all? or maybe I need to consider some another library for it?

As far as I know, you can't use Processing's functions as standalone without at least a setup() function. This is because Processing needs to do its own initialization before most of its functions work.

But note that you don't need to include a draw() function. You can do everything from setup() , something like this:

public class TestSketch extends PApplet {
  public void setup() {
    background(32);
    ellipse(50, 50, 25, 25);
    noLoop();
  }

  static public void main(String[] passedArgs) {
    String[] appletArgs = new String[] { "TestSketch" };
    PApplet.main(appletArgs);
  }
}

That being said, you might be able to hack at Processing's source to isolate the functionality you want. This is probably more work than it's worth though.

Shameless self-promotion: here is a guide on using Processing as a Java library. Here is a guide on running Processing without a display.

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