Skip to content

PImage resize() problem #251

Closed
Closed
@PandaBalls

Description

@PandaBalls
PGraphics pg;
int brushSize = 6;
PImage img, img2;
import ketai.ui.*;

void setup() {
  //size(600, 600);
  fullScreen();
  noStroke();
  pg = createGraphics(width, height);
  pg.beginDraw();
  pg.background(255);
  pg.endDraw();
}

void draw() {
  background(0);
  brushSize = constrain(brushSize, 3, 66);
  image(pg, 0, 0);
  if (img !=null) {
    image(img, 0, 0);
    fill(255, 0, 0);
    text(pg.get(mouseX, mouseY), mouseX, mouseY);
  }
  pushStyle();
  noFill();
  stroke(255, 0, 0);
  ellipse(mouseX, mouseY, brushSize, brushSize);
  popStyle();
}

void mouseDragged() {
  pg.beginDraw();
  pg.strokeWeight(brushSize);
  pg.stroke(0);
  pg.line(pmouseX, pmouseY, mouseX, mouseY);
  pg.endDraw();
}

void mousePressed() {
  KetaiKeyboard.toggle(this);
}

void keyPressed() {
  if (key == '+') {
    brushSize +=2;
  } else if (key == '-') {
    brushSize -=2;
  } else if (key =='r') {
    img = pg.get();
    try {
      img.resize(100, 100);
    } 
    catch (Exception e) {
      e.printStackTrace();
    }
  } else if (key =='p') {
    printArray(img.pixels);
  }
}

while in android mode, if PImage load from file. resize() function is fine to work.
But i tried to create a PImage for grabber image from PGraphics , resize() function doesn't work.
It works in Java Mode..
console through out the exceptions :
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:622)
at processing.core.PImage.resize(Unknown Source)
at processing.test.pgraphicsdraw.PGraphicsDraw.keyPressed(PGraphicsDraw.java:72)
at processing.core.PApplet.keyPressed(Unknown Source)
at processing.core.PApplet.handleKeyEvent(Unknown Source)
at processing.core.PApplet.dequeueEvents(Unknown Source)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:833)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions