Skip to content

Can't render PGraphics object using image() within a PDF #4473

Description

@scotthmurray

@almoce logged this issue here: processing/processing-docs#431

If you run this example, an error is triggered:

ClassCastException sun.java2d.SunGraphics2D cannot be cast to java.awt.Image

Is this a bug? Shouldn't you be able to use image() to display/output a PGraphics object, even within the PDF renderer? (Or perhaps this isn't supported for PDFs.)

import processing.pdf.*;

PGraphics pg;

void setup() {
  size(100, 100, PDF, "output.pdf");
  pg = createGraphics(100, 100);
  noLoop();
}

void draw() {
  pg.beginDraw();
  pg.background(100);
  pg.stroke(255);
  pg.line(0, 0, 100, 100);
  pg.endDraw();

  image(pg, 0, 0);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions