inavnacorp inavnacorp - 2 years ago 89
Java Question

create image Hype Processing,

I am trying to create image using and I want to create the image and store in a folder then display it on the web using java spark. The following are the steps that I started with.

  1. Create maven project using NetBeans

  2. Added, spark libraries in maven

  3. Downloaded hype processing jar added to my libraries

My question is how do I create image with then save it to the webapp folder? I am relatively new to hype and processing drawing shapes stuff. The following are my code that I put together:

Right now this cimg.setup() in the main spark controller throws java.lang.NumberFormatException: For input string: "#BC7A38,#996A37,#968063,#AB977C,#997949,#AE9162,#DFC597,#CAB790" error.

I searched google, but can't find any lead. Any help on how I should accomplish my task is greatly appreciated. Thanks!

//-- spark controller -
public class Main {
public static void main(String[] args) {
get("/", new TemplateViewRoute() {
public ModelAndView handle(Request req, Response res) throws Exception {
HashMap model = new HashMap();
HypeProcessing cimg = new HypeProcessing();
model.put("template", "templates/form.vtl");
return new ModelAndView(model, "templates/layout.vtl");
}, new VelocityTemplateEngine());

//--- HypeProcessing class ----
public class HypeProcessing extends PApplet
HDrawablePool pool;
HColorPool colors;

public void setup()
int h = 300;
int w = 300;
//size(w, h);

colors = new HColorPool(Integer.parseInt("#BC7A38,#996A37,#968063,#AB977C,#997949,#AE9162,#DFC597,#CAB790"));

pool = new HDrawablePool(121);
.add(new HShape("svg1.svg"))
.add(new HShape("svg2.svg"))
.add(new HShape("svg3.svg"))
.add(new HShape("svg4.svg"))
.add(new HShape("svg5.svg"))
.add(new HShape("svg6.svg"))

new HGridLayout()

new HCallback() {

public void run(Object obj) {
HShape d = (HShape) obj;
// .anchorAt(H.CENTER)
.rotate( (int)random(4) * 90 )
.size( 50 + ( (int)random(4) * 50 ) ) // 50, 100, 150, 200
// ...

public void draw()
//rect(10, 10, 80, 80);
// ...

public void saveImage(int width, int height)
//Helper c = new Helper();
String p = "webapp/images/";
String fn = p+"image_"+Helper.generateRandomNumber();
PGraphics img = createGraphics(width, height);
boolean use3D = false;
float alpha = 1;
H.stage().paintAll(img, use3D, alpha);


Answer Source

Processing uses a custom color type. You can use web notation like #ff00ff, and under the hood Processing stores that as an integer, so you can even do things like:

int c = #ff00ff;

However, Java functions like Integer.parseInt() have no idea how to handle web notation. Java has no way of mapping a String like "#ff00ff" to an int value. This is why you're getting your error.

Even if Java did know how to map web notation to an int value, you're passing in multiple values within a single String, which doesn't make a ton of sense.

But the point is, you can only use web notation if you're using the Processing editor. If you're writing this in something other than the Processing editor, you'll have to use the color() function.

HColorPool(color(0, 255, 0), color(255, 0, 255), ...);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download