In Processing if you want that a function is executed in a diferent thread, you have just to use the following command:
thread("myFunc"); // this command creates a new thread and executes myFunc in that thread
void myFunc(){ ... }
The restriction is that 'myFunc' must be void, with no parameters and it could not be declared in a subclass in the sketch (it must be a public function in the pApplet class).
If you nedd that 'myFunc' has parameters,
See this Post
PImage codificaBarCcode(String codi, BarcodeFormat format, int ample, int alt){ color negre = color(0), blanc = color(255); PImage img = new PImage(ample, alt); Hashtable hints = new Hashtable(1); hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
int width = QRBitMatrix.getWidth(); int height = QRBitMatrix.getHeight();
for (int y = 0; y < height; y++) { int offset = y * width; for (int x = 0; x < width; x++) { if(QRBitMatrix.get(x, y)) img.set(x, y, negre); else img.set(x, y, blanc); } } return(img); }
String decodificaBarCode(PImage img){ String retorn = ""; Result result = null;
try { LuminanceSource source = new BufferedImageLuminanceSource((BufferedImage)img.getImage()); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); result = reader.decode(bitmap); retorn = result.getText(); if (retorn != null) { //println(result.getText()); ResultPoint[] points = result.getResultPoints();
for (int i = 0; i < points.length; i++) { fill(#ff8c00); ellipse(points[i].getX(), points[i].getY(), 20,20); } } } catch (Exception e) {println(e.toString());}