<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with save() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=save%28%29</link>
      <pubDate>Sun, 08 Aug 2021 19:53:13 +0000</pubDate>
         <description>Tagged with save() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedsave%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>PGraphics Background Color</title>
      <link>https://forum.processing.org/two/discussion/27754/pgraphics-background-color</link>
      <pubDate>Fri, 13 Apr 2018 06:23:15 +0000</pubDate>
      <dc:creator>james0411</dc:creator>
      <guid isPermaLink="false">27754@/two/discussions</guid>
      <description><![CDATA[<p>Hi there, when I save PGraphics to jpg file, the background color is always Black. I've tried  ####.background(255)  like this to change the background color. But I'm using my canvas with live Video. So the outcome was not what I want. How can I change the background Color when I save PGraphics?  Is there any way to change it?</p>

<p>Here is my Code.</p>

<pre><code>import processing.video.*;

Capture video;

color trackColor = color(145,43,54);
color trackColor2 = color(142,156,42);
color trackColor3 = color(18,35,40);

float threshold = 25;
PGraphics topLayer;

float r2;
float g2;
float b2;

float r3;
float g3;
float b3;

float r4;
float g4;
float b4;

float distSq(float x1, float y1, float z1, float x2, float y2, float z2) {
  float d = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) +(z2-z1)*(z2-z1);
  return d;

}
float distSq2(float x1, float y1, float z1, float x2, float y2, float z2) {
  float d2 = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) +(z2-z1)*(z2-z1);
  return d2;

}
float distSq3(float x1, float y1, float z1, float x2, float y2, float z2) {
  float d3 = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) +(z2-z1)*(z2-z1);
  return d3;

}

void setup() {
  size(640, 360);
  String[] cameras = Capture.list();
  printArray(cameras);
  video = new Capture(this, cameras[3]);
  video.start();
  trackColor = color(145,43,54);
  trackColor2 = color(142,156,42);
  trackColor3 = color(18,35,40);

  topLayer = createGraphics(width, height, g.getClass().getName());
}

void captureEvent(Capture video) {
  video.read();
}

void draw() {

  video.loadPixels();
  image(video, 0, 0);

  //threshold = map(mouseX, 0, width, 0, 100);
  threshold = 25;
  float thresholdSquare = threshold * threshold;

  // Begin loop to walk through every pixel

  topLayer.beginDraw();
  topLayer.clear();
  for (int x = 0; x &lt; video.width; x++ ) {
    for (int y = 0; y &lt; video.height; y++ ) {
      int loc = x + y * video.width;
      // What is current color
      color currentColor = video.pixels[loc];

      float r1 = (currentColor&gt;&gt;16)&amp;0xFF;
      float g1 = (currentColor&gt;&gt;7) &amp; 0xFF ;
      float b1 = (currentColor) &amp; 0xFF;

      r2 = (trackColor&gt;&gt;16)&amp;0xFF;
      g2 = (trackColor&gt;&gt;7) &amp; 0xFF;
      b2 = (trackColor) &amp; 0xFF;

      r3 = (trackColor2&gt;&gt;16)&amp;0xFF;
      g3 = (trackColor2&gt;&gt;7) &amp; 0xFF;
      b3 = (trackColor2) &amp; 0xFF;

      r4 = (trackColor3&gt;&gt;16)&amp;0xFF;
      g4 = (trackColor3&gt;&gt;7) &amp; 0xFF;
      b4 = (trackColor3) &amp; 0xFF;
      //
      float d = distSq(r1, g1, b1, r2, g2, b2);
      float d2 = distSq2(r1, g1, b1, r3, g3, b3);
      float d3 = distSq3(r1, g1, b1, r4, g4, b4);

      if (d &lt; thresholdSquare) {
        topLayer.stroke(trackColor);
        topLayer.fill(trackColor);
        topLayer.ellipse(x, y,2,2);
      }
      else if( d2 &lt; thresholdSquare){  
        topLayer.stroke(trackColor2);
        topLayer.fill(trackColor2);
        topLayer.ellipse(x,y,2,2);
      }
      else if(d3 &lt; thresholdSquare){
        topLayer.stroke(trackColor3);
        topLayer.fill(trackColor3);
        topLayer.ellipse(x,y,2,2);
      }
      }
     ////////////////////////////////////////
      }
        topLayer.endDraw(); 
        image(topLayer, 0, 0);

    if(mousePressed){
      topLayer.save("example.jpg");
    }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to permanently type words onto a PImage and save it as jpg?</title>
      <link>https://forum.processing.org/two/discussion/25965/how-to-permanently-type-words-onto-a-pimage-and-save-it-as-jpg</link>
      <pubDate>Mon, 15 Jan 2018 03:44:44 +0000</pubDate>
      <dc:creator>Fangry</dc:creator>
      <guid isPermaLink="false">25965@/two/discussions</guid>
      <description><![CDATA[<p>Hello guys,</p>

<p>I am working on an image processing program. I notice that when I type some words onto a PImage, and try to save the PImage, the text is saved in jpg? Any ideas?</p>

<pre><code>class Text {
  PVector textLocation;
  String string;
  float textSize;
  color colour;

  Text (PVector textLocation) {
    this.textLocation = textLocation;
    textSize = 18;
    colour = color(0);
  }

  void display() {
    if (textOn &amp;&amp; !(string == null)) {
      fill(colour);
      textSize(textSize);
      text(string, textLocation.x, textLocation.y);
    }
  }
}
</code></pre>

<p>my project link <a href="https://github.com/Finaros/Pixcell" target="_blank" rel="nofollow">https://github.com/Finaros/Pixcell</a>
Thanks!</p>
]]></description>
   </item>
   <item>
      <title>How to save image after edits</title>
      <link>https://forum.processing.org/two/discussion/25909/how-to-save-image-after-edits</link>
      <pubDate>Thu, 11 Jan 2018 04:28:50 +0000</pubDate>
      <dc:creator>Fangry</dc:creator>
      <guid isPermaLink="false">25909@/two/discussions</guid>
      <description><![CDATA[<p>Hello, forum
So I am doing this image processing application, but I haven't found a way to 'undo' changes or to save changes. 
I get how changing the brightness or the RBG values changes the image.</p>

<pre><code>loadPixels();
      for (int y = 0; y &lt;pic.height; y++) {
        for (int x = 0; x &lt;pic.width; x ++) {
          int index = x + height*y;
          float r = red(pic.pixels[index]);
          float g = green(pic.pixels[index]);
          float b = blue(pic.pixels[index]);
          pixels[index] = color(r, g, b);
        }
      }
      updatePixels();
</code></pre>

<p>saveFrame() saves the entire screen, including my user interface. And that's not what I want. I only want the image portion to be saved.</p>

<p>I think PImage.save is the way to go. But I don't know how to save changes to an image object and then it can save.</p>

<p>How do you save store changes so you can go back if you make a mistake?</p>

<p>My code can be found on my Github <a href="https://github.com/Finaros/Pixcell" target="_blank" rel="nofollow">https://github.com/Finaros/Pixcell</a>
Thank you very much!</p>
]]></description>
   </item>
   <item>
      <title>Using a code from Processing 10 doesn't work on Processing 13</title>
      <link>https://forum.processing.org/two/discussion/25435/using-a-code-from-processing-10-doesn-t-work-on-processing-13</link>
      <pubDate>Thu, 07 Dec 2017 14:42:42 +0000</pubDate>
      <dc:creator>alenalo</dc:creator>
      <guid isPermaLink="false">25435@/two/discussions</guid>
      <description><![CDATA[<p>Hello all</p>

<p>I'm running a code from a couple of years ago which worked fine on the old version of processing 
but doesn't work on Processing 13.</p>

<p>line 16 is causing troubles 
please please help?</p>

<p>thank you!</p>

<pre><code>import java.io.*;

int outputWidth = 819;
int outputHeight = 819;
int smallWidth = 9;
int smallHeight = 9;

String imagePath;
String[] images;
int imageCount;
PGraphics pg;

void setup() {
  size(819, 819);
  pg = createGraphics(outputWidth, outputHeight, P2D);
  imagePath = selectFolder();
  if (imagePath != null) { images = loadImageFilenames(imagePath); } else { exit(); }
}

void draw() {
  PImage currentImage = loadImage(imagePath + "/" + images[imageCount % images.length]);
  currentImage.resize(smallWidth, smallHeight);
  int x = (smallWidth * imageCount) % outputWidth;
  int y = ((smallWidth * imageCount) / outputWidth) * smallHeight;
  if (y &lt; outputHeight) {
    pg.beginDraw();
    pg.image(currentImage, x, y);
    pg.endDraw();
    background(0);
    image(pg, 0, 0, width, height);
    imageCount++;
  } else {
    pg.save("output.png");
    exit();
  }
}

String[] loadImageFilenames(String path) {
  File folder = new File(path);
  FilenameFilter imgFilter = new FilenameFilter() {
    public boolean accept(File dir, String name) {
      String lowCase = name.toLowerCase();
      return lowCase.endsWith(".jpg")
      || lowCase.endsWith(".png")
      || lowCase.endsWith(".tga");
    }
  };
  return folder.list(imgFilter);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to use random to get at my color array</title>
      <link>https://forum.processing.org/two/discussion/23896/how-to-use-random-to-get-at-my-color-array</link>
      <pubDate>Wed, 23 Aug 2017 03:18:50 +0000</pubDate>
      <dc:creator>Petros</dc:creator>
      <guid isPermaLink="false">23896@/two/discussions</guid>
      <description><![CDATA[<p>What I'm trying to do: create a bunch of ellipses (in a grid) that each have one of an array of colors and that each mask one or more rectangles that also have a variable color from the same array. I've succeeded at (1) creating a masked shape, (2) duplicating it in a grid, and (3) creating an array of colors. Right now I'm trying to get that array to affect the colors but I'm failing. What am I doing wrong? I'm getting an error "expecting EOF, found 'colorset'." Pretty sure I have my file set up incorrectly. Any tips?</p>

<pre><code>/**
 * Draw rectangles inside of circles
 * 2017-08-22
 **/
PGraphics sourceImage;
PGraphics maskImage;

  int colorset;
  color [] colorsetarray = { 
    color(#3AC459), 
    color(#3D8CFF), 
    color(#8CD6ED), 
    color(#F7CC68), 
    color(#F77068), 
    color(#576984), 
    color(#7A9BB0), 
    color(#D8E8ED), 
    color(#EAF4F7) };
  colorset = colorsetarray[(int)random(0, 8)];

void setup() {
  size(800, 800); //size of canvas
  noLoop();
  smooth();
}

void draw() {

  for (int y = 20; y &lt; height-8; y += 120) {
    for (int x = 20; x &lt; width-80; x += 120) {
      // create source
      sourceImage = createGraphics(100, 100); //size of drawing
      sourceImage.beginDraw();
      sourceImage.background(colorsetarray[(int)random(colorsetarray.length)]); //color the background
      sourceImage.fill(colorsetarray[(int)random(colorsetarray.length)]); //color the rectangle
      sourceImage.translate(width/2, height/2);
      sourceImage.rotate(radians(45));
      sourceImage.noStroke(); //take the stroke off of the rectangle
      sourceImage.rect(-600, -200, 80, 500); //locate the rectangle and draw it
      sourceImage.endDraw();

      // create mask
      maskImage = createGraphics(100, 100); //size of mask
      maskImage.beginDraw();
      maskImage.ellipse(50, 50, 100, 100);
      maskImage.endDraw();

      // apply mask
      sourceImage.mask(maskImage);

      // show masked source
      image(sourceImage, x, y); //move the chip here
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>I have a current code but I need to make the outer squares move, please help</title>
      <link>https://forum.processing.org/two/discussion/22759/i-have-a-current-code-but-i-need-to-make-the-outer-squares-move-please-help</link>
      <pubDate>Thu, 25 May 2017 15:10:53 +0000</pubDate>
      <dc:creator>KingSpagooter</dc:creator>
      <guid isPermaLink="false">22759@/two/discussions</guid>
      <description><![CDATA[<pre><code>// =================================================================
//Variables
StopWatchTimer sw;
float x = 0;
float y = 100;
float speed = 1;
// =================================================================
// Main
void setup() {
  size(700, 560);
  println (millis());
  sw = new StopWatchTimer();
  sw.start();
  rectMode(CENTER);
}
// Draw
void draw () {
  time();
  println(mouseX);
  println(mouseY);
  stroke (153);
  fill (204, 102, 0);
  rect (555, 275, 50, 50);
  rect (345, 475, 50, 50);
  rect (115, 275, 50, 50);
  rect (345, 75, 50, 50);
  frame.setTitle(int(frameRate) + " fps");
  fill (235, 235, 0);
  noStroke();
  rect (mouseX, mouseY, 30, 30);
}
// =================================================================
// Other
void time() {
  background(#C9C9C9);
  fill(#000000);
  textAlign(CENTER);
  text(nf(sw.minute(), 2)+":"+nf(sw.second(), 2), 656, 14);
}
// =================================================
// classes
class StopWatchTimer {
  int startTime = 0, stopTime = 0;
  boolean running = false; 
  void start() {
    startTime = millis();
    running = true;
  }
  void stop() {
    stopTime = millis();
    running = false;
  }
  int getElapsedTime() {
    int elapsed;
    if (running) {
      elapsed = (millis() - startTime);
    } else {
      elapsed = (stopTime - startTime);
    }
    return elapsed;
  }
  int second() {
    return (getElapsedTime() / 1000) % 60;
  }
  int minute() {
    return (getElapsedTime() / (1000*60)) % 60;
  }
}
// ====================================================
//High Rez
void saveHiRes(int scaleFactor) {
  PGraphics hires = createGraphics(width*scaleFactor, height*scaleFactor, JAVA2D);
  beginRecord(hires);
  hires.scale(scaleFactor);
  draw();
  endRecord();
  hires.save("hires.png");
}
//=======================================================
//collision 
boolean mouseOverRect(int x, int y, int w, int h) {
  return (mouseX &gt;= x &amp;&amp; mouseX &lt;= x+w &amp;&amp; mouseY &gt;= y &amp;&amp; mouseY &lt;= y+h);
}
// =====================================================
void move() {
  x = x + speed;
  if (x &gt; width) {
    x = 0;
  }
}
void display() {
  rect(x,y,30,10);
}``
</code></pre>
]]></description>
   </item>
   <item>
      <title>Saving canvas to img with all p5 elements</title>
      <link>https://forum.processing.org/two/discussion/22975/saving-canvas-to-img-with-all-p5-elements</link>
      <pubDate>Wed, 07 Jun 2017 12:42:56 +0000</pubDate>
      <dc:creator>archas</dc:creator>
      <guid isPermaLink="false">22975@/two/discussions</guid>
      <description><![CDATA[<p>Is it possible to save canvas with all custom elements like divs, p, a, etc. created (by p5.dom) and positioned on the canvas?
The simple text() function was quite buggy for me, I decided to use createElement to simulate text on a canvas with possibility to edit it and change its position.</p>

<p>This question is similar to the unaswered question:
<a href="https://forum.processing.org/two/discussion/19707/can-the-save-function-include-p5-elements-within-the-saved-image" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/19707/can-the-save-function-include-p5-elements-within-the-saved-image</a></p>
]]></description>
   </item>
   <item>
      <title>save() function keeps overwriting file names - how can I make file names increase numerically?</title>
      <link>https://forum.processing.org/two/discussion/22686/save-function-keeps-overwriting-file-names-how-can-i-make-file-names-increase-numerically</link>
      <pubDate>Sat, 20 May 2017 20:08:27 +0000</pubDate>
      <dc:creator>phoeknowles</dc:creator>
      <guid isPermaLink="false">22686@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I'm super new to processing.</p>

<p>I've done a key press function where it saves an image that I've made various modifications to, but every time I press 's' to save, a new image saves and overwrites the previous image. I don't know how I can rename the files so that they can change automatically (e.g. every time I save it goes output_1.jpg, output_2.jpg and so on...).</p>

<p>I have two images side by side so I use saveFrame(); to save both of them and this is fine, but when I try to save just the image on the right (titled imgCopy), this is when the overwrite problem happens.
Any solutions?</p>

<p>Thanks in advance! x</p>
]]></description>
   </item>
   <item>
      <title>Why is this image not displaying?</title>
      <link>https://forum.processing.org/two/discussion/22461/why-is-this-image-not-displaying</link>
      <pubDate>Mon, 08 May 2017 14:56:20 +0000</pubDate>
      <dc:creator>lifeofmusic13</dc:creator>
      <guid isPermaLink="false">22461@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone, I have this code setup that on the first program you select a folder and then it displays the folder of images. Then when you click on an image it opens a code that you have to run that allows you to edit and save the images. However on my second code, it isn't displaying the image. It will allow you to save it if you know the right key to press but it also doesn't apply any of the filters if anyone has any help.</p>

<p>here is the first code to display the images and launch the second code.</p>

<pre><code>PImage images;
String[] filenames;
PImage[] imgs;
int len;
String pathName;

void setup() {
  size(1000, 881);
  loadFrames();
}  

void draw() {
  background(0);
  displayImages();
   if (mousePressed &amp;&amp; (mouseButton == LEFT)) {
     enlargeAll();
   }

textSize(32);
fill(255);
text("word", 450, 45);
    }

    void loadFrames() {
  selectFolder("Select a folder to process:", "folderSelected");
}

void folderSelected(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
  } else {
    println("User selected " + selection.getAbsolutePath());
    java.io.File folder = new java.io.File(selection.getAbsolutePath()); 
    filenames = folder.list();   // list the files in the data folder
    len = filenames.length;
    imgs = new PImage[len];
    pathName= selection.getAbsolutePath() +"\\";
  }
}


void displayImages(){
  int imageY;
  float imageX;
  //where the photos are placed
  imageX = 8.33;
  imageY = 200;
  int count = 0;
  for(int x = 1; x&lt;=len; x++){
  count = x;
  String toDisplay = pathName + filenames[x - 1];
  //size and display of photos
  images = loadImage(toDisplay);
  images.resize(190, 0);
  image(images, imageX, imageY);
  //spacing of photos
  imageX=imageX+198.33;
  if ((count%5 == 0)) {
    imageX = 8.33;
    imageY = imageY + 150;
  }
  }
}

void enlarge(int imageNumber) {
  //Sets toDisplay as the photo name
  String imageNumbs;
  if (imageNumber &lt;10) {
    imageNumbs = "0" + imageNumber;
  }
  else
  {
    imageNumbs = str(imageNumber);
  }
  String toDisplay = pathName + imageNumbs + ".jpg";
  float lowX, highX;
  float lowY, highY;
  int imageNum = imageNumber;
  //Starting point of photo 1
  lowY = 200;
  highY = 325;
  lowX = 8.33;
  highX = 198.33;
  //Placement of photos 1-5
  if (imageNum &lt;=5) {
  lowX = 8.33 + ((imageNum - 1) * 198.33);
  highX = 198.33 + ((imageNum - 1) * 198.33);
  lowY = 200;
  highY = 325;
  }
  else {
    //Placement of photos 6-10
    if (imageNum &gt;= 6 &amp;&amp; imageNum &lt;= 10) {
  imageNum = imageNum - 5;
  lowX = 8.33 + ((imageNum - 1) * 198.33);
  highX = 198.33 + ((imageNum - 1) * 198.33);
  lowY = 350;
  highY = 475;
  }
  else {
    //Placement of photos 11-15
    if (imageNum &gt;= 11 &amp;&amp; imageNum &lt;= 15) {
      imageNum = imageNum - 10;
      lowX = 8.33 + ((imageNum - 1) * 198.33);
      highX = 198.33 + ((imageNum - 1) * 198.33);
      lowY = 400;
      highY = 625;
    }
    else {
      //Placement of photos 16-20
      if (imageNum &gt;= 16 &amp;&amp; imageNum &lt;= 20) {
          imageNum = imageNum - 15;
          lowX = 8.33 + ((imageNum - 1) * 198.33);
          highX = 198.33 + ((imageNum - 1) * 198.33);
          lowY = 550;
          highY = 775;
      }
    }
  }
  }

//if mouse is on a photo
  if((mouseX &gt;= lowX) &amp;&amp; (mouseX &lt;= highX) &amp;&amp; (mouseY &gt;= lowY) &amp;&amp; (mouseY &lt;= highY)) {
    //Enlarges photo to full screen
    launch(sketchPath() +"\\" +"pic" + imageNumbs + "\\" + "pic" + imageNumbs + ".pde");
  }


}
//Enlarges when mouse is clicked
void enlargeAll() {
  enlarge(1);
  enlarge(2);
  enlarge(3);
  enlarge(4);
  enlarge(5);
  enlarge(6);
  enlarge(7);
  enlarge(8);
  enlarge(9);
  enlarge(10);
  enlarge(11);
  enlarge(12);
  enlarge(13);
  enlarge(14);
  enlarge(15);
  enlarge(16);
  enlarge(17);
  enlarge(18);
  enlarge(19);
  enlarge(20);
}
</code></pre>

<p>and here is the second code which is the one that I am having troubles with</p>

<pre><code>PImage images;
String[] filenames;
int len;
String pathName;
String imageToDisplay;
PImage newImage;

void setup() {
  size(1000, 881);
  loadFrames();


}  

void draw() {
  noLoop();
  redraw();
  background(0);
  loadImages();
  filters();
  saveFilter();


  textSize(32);
  fill(255);
  text("word", 450, 45);
}

void loadFrames() {
  selectFolder("Select a folder to process:", "folderSelected");
}

void folderSelected(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
  } else {
    println("User selected " + selection.getAbsolutePath());
    java.io.File folder = new java.io.File(selection.getAbsolutePath()); 
    filenames = folder.list();   // list the files in the data folder
    len = filenames.length;
    pathName= selection.getAbsolutePath() +"\\";
    imageToDisplay = pathName + "04.jpg";
    //size and display of photos


  }
}

void loadImages() {
  if (imageToDisplay != null) {
  images = loadImage(imageToDisplay);
  images.resize(0, 656);
  newImage = images.get();
  image(images, 8.33, 200);


  }
  }



void filters() {
  bFilter();
  tFilter();
  tFilter();
  pFilter();
  dFilter();
  noFilter();
}


void bFilter() {
  if (keyPressed == true) {
    if (key == 'b' || key == 'B') {
      if (pathName != null) {

        image(newImage, 8.33, 200);
        newImage.filter(GRAY);

      }
    }
  }
}

void tFilter() {
  if (keyPressed == true) {
    if (key == 't' || key == 'T') {
      if (pathName != null) {

        image(newImage, 8.33, 200);
        newImage.filter(THRESHOLD);

      }
    }
  }
}

void iFilter() {
  if (keyPressed == true) {
    if (key == 'i' || key == 'I') {
      if (pathName != null) {
        imageToDisplay = pathName + "04.jpg";
        //size and display of photos
        newImage = images.get();

        image(newImage, 8.33, 200);
            newImage.filter(INVERT);

      }
    }
  }
}

void pFilter() {
  if (keyPressed == true) {
    if (key == 'p' || key == 'P') {
      if (pathName != null) {

        image(newImage, 8.33, 200);
        newImage.filter(POSTERIZE, 66);

      }
    }
  }
}

void dFilter() {
  if (keyPressed == true) {
    if (key == 'd' || key == 'D') {
      if (pathName != null) {

        image(newImage, 8.33, 200);
                newImage.filter(DILATE);

      }
    }
  }
}

void noFilter() {
  if (keyPressed) {
    if (key == CODED) {
      if (keyCode == DELETE) {
        image(images, 8.33, 200);
      }
    }
  }
}


void saveFilter() {
  if (keyPressed == true) {
    if (key == CODED) {
      if (keyCode == '=') {
        int fileName = len+1;
        newImage.save(pathName + fileName +".jpg");
      }

      //save
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Why is it doing that ??? Saving live capture instead of the content of a capture object</title>
      <link>https://forum.processing.org/two/discussion/22237/why-is-it-doing-that-saving-live-capture-instead-of-the-content-of-a-capture-object</link>
      <pubDate>Thu, 27 Apr 2017 08:31:51 +0000</pubDate>
      <dc:creator>Mat007</dc:creator>
      <guid isPermaLink="false">22237@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,
I am trying to record incoming data from a serial port as well as capturing video. Because of the speed (data is coming every millisecond) I had to trigger the video capture inside the serialEvent (built-in camera works at 30 fps max). I decided to capture a snapshot every 50ms. It takes too long to save the snapshot so I had to buffer it in an arrayList. I did the same with the serial data.
Acquisition is triggered and stopped using keyPressed. Once it is finished, I come back to my arrayLists and save the pictures one by one (including the serial data in the name, it is just a short string).
Here is the trouble: instead of reading the content of the Capture arrayList it reads whatever is coming from the camera.</p>

<p>I tried without success:
-myPort.stop()
-myVideo.stop()
-noLoop()
-using a PImage arrayList instead of Capture object arrayList
-use different ways to trigger/stop acquisition.</p>

<p>It doesn't make any sense to me... why when I write mySnapshotAL.get(i) do I get the current camera view and not the content of the arrayList which is populated properly (I checked the size) ???</p>

<p>Many thanks!!!</p>

<pre><code>import processing.video.*;
import processing.serial.*;

Capture myVideo;                     // declaring a Capture object
Serial myPort;                       // declaring a  serial port
ArrayList&lt;String&gt; myDataAL;          // declaring an ArrayList of String (serial data)
ArrayList&lt;Capture&gt; mySnapshotAL;     // declaring an ArrayList of Capture objects
String myFileName;
String myDataString;
String myDate;
int startTime;
String myTime;
int i=0;
boolean saving=false;

void setup() {  
  frameRate(1000);
  size(1000, 700);
  background(0);
  mySnapshotAL= new ArrayList&lt;Capture&gt;();            // initialising the ArrayList of Capture objets
  myDataAL= new ArrayList&lt;String&gt;();                 // initialising the ArrayList of String
  myVideo = new Capture(this, 320, 240,30);          // initialising the Capture object
  myVideo.start();
  myPort = new Serial(this, Serial.list()[1], 9600); // initialising the port dev/cu.usbmodem1411
  myPort.bufferUntil(10); // char(10) = line feed
}

void serialEvent(Serial myPort) {   // myPort receives data every ms
  i++; 
    if (i==50){
      myVideo.read(); // only acquire every 50 ms
      i=0;
    } 
  myDataString = trim(myPort.readString());
  myTime=nf(millis()-startTime,6,1).substring(0,5);
  myDataString=myTime + "," + myDataString;
  if (saving){
  mySnapshotAL.add(myVideo);
  myDataAL.add(myDataString);
  }
}

void draw() {  
image(myVideo, 600, 40);
}

void keyPressed(){
        if (!saving) {
          saving=true;
          startTime=millis();
          }
        else {
          saving=false;
          myDate= nf(hour(),2,1).substring(0,2) + "h" + nf(minute(),2,1).substring(0,2);
          for (int i =0; i&lt;mySnapshotAL.size(); i++){
              myFileName="VideoFiles/Capture" + i + "@" +myDate+ "-" +myDataAL.get(i)+".png";
              mySnapshotAL.get(i).save(myFileName); 
              if (i==300) break;  // safety, until code is failproof
          }
        }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>how to save high quality images from processing PGraphics</title>
      <link>https://forum.processing.org/two/discussion/13359/how-to-save-high-quality-images-from-processing-pgraphics</link>
      <pubDate>Mon, 02 Nov 2015 13:30:48 +0000</pubDate>
      <dc:creator>jairo_asecas</dc:creator>
      <guid isPermaLink="false">13359@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I'm trying to get high quality images from processing but I've got a problem.</p>

<p>this is the code I'm using:</p>

<pre><code>PGraphics big;  
void setup() {  
  big = createGraphics(5000, 5000, JAVA2D); // Create a new PGraphics object 5000x5000px  
  big.beginDraw(); // Start drawing to the PGraphics object  
  size(500, 500, P2D); //size of the on-screen display  
}  

int counter; // counter  
void draw() {  
  counter++; // add 1 to counter  
  if(counter%10 == 0) { // every 10th frame we snap a preview and draws it  
    PImage img = big.get(0, 0, big.width, big.height); //snap an image from the off-screen graphics  
    img.resize(width,height); // resize to fit the on-screen display  
    image(img,0,0); // display the resized image on screen  
  }  

  big.fill(255,0,0);//we fill following with red  
  big.ellipse(random(big.width),random(big.height),10,10);//randomly placed circle  
}  

/** 
* We save on any key 
* this could be done in void close() but safer to have it here. 
*/  
void keyPressed() {  
  big.endDraw(); // finish drawing  
  big.save("highRes.tif"); //save to file - use .tif as format for high-res  
  println("saved"); // nice with some feedback  
}  
</code></pre>

<p>it is from: Alexander Salveson Nossum, link: <a href="http://alexanno.net/2010/06/high-resolution-output-from-processing-processing-in-hd/comment-page-1/#comment-818" target="_blank" rel="nofollow">http://alexanno.net/2010/06/high-resolution-output-from-processing-processing-in-hd/comment-page-1/#comment-818</a></p>

<p>It works with easy sketches but when I try to use a function it fails.</p>

<p>example: <code>big.ellipse(random(width),random(height),40,40);</code></p>

<p>works</p>

<p>but: <code>void example(){ ellipse(random(width),random(height),40,40); }</code></p>

<p>big.example();</p>

<p>doesn’t works. (says: ****the function example() does not exist.****)</p>

<p>why is it? there is another way to get better quality captures?</p>
]]></description>
   </item>
   <item>
      <title>Remove processing-java window</title>
      <link>https://forum.processing.org/two/discussion/20798/remove-processing-java-window</link>
      <pubDate>Tue, 14 Feb 2017 17:42:49 +0000</pubDate>
      <dc:creator>usernamevalid</dc:creator>
      <guid isPermaLink="false">20798@/two/discussions</guid>
      <description><![CDATA[<p>Im running processing-java from cmd line in another app. The app creates an image in an offscreen buffer, saves it and exits. 
However when ever the app is called there is still a window that pops up on screen, it takes focus away anything on screen. Is there a way to run processing-java with no window?</p>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>Resizing/Saving an Image</title>
      <link>https://forum.processing.org/two/discussion/20280/resizing-saving-an-image</link>
      <pubDate>Sun, 15 Jan 2017 15:56:17 +0000</pubDate>
      <dc:creator>mobodcubism</dc:creator>
      <guid isPermaLink="false">20280@/two/discussions</guid>
      <description><![CDATA[<p>Hey all,</p>

<p>I'm trying to write a program that reduces the size of an image by a predetermined factor.
My program has to load an image file into a PImage, construct a new PImage, eight times smaller in every dimension, with the scaled content, and save that new PImage to disk.</p>

<p>Saving an image with save() works but i'm struggling to simultaneously rescale as well. 
Is it possible to use resize() with save() to achieve this? Or is there perhaps a more efficient way of going about doing this?</p>

<p>Any help would be greatly appreciated!
Thanks</p>
]]></description>
   </item>
   <item>
      <title>using copy() to copy part of canvas to another graphic</title>
      <link>https://forum.processing.org/two/discussion/20234/using-copy-to-copy-part-of-canvas-to-another-graphic</link>
      <pubDate>Fri, 13 Jan 2017 11:24:17 +0000</pubDate>
      <dc:creator>Geoffree3</dc:creator>
      <guid isPermaLink="false">20234@/two/discussions</guid>
      <description><![CDATA[<p>I want to copy parts of the canvas to another image, which is then output as a single file.  However, it appears that copy() doesn't take any notice of the pixel density as I get a low res. output.  If I save the canvas directly to a file using save() I get high res. from my MacBook retina screen. 
Any ideas?</p>

<p>What I do:<br />
use output = createImage() to define the image which is eventually output
use output.copy(,</p>,, "png")
]]></description>
   </item>
   <item>
      <title>How to saveFrame high quality when using .pngs</title>
      <link>https://forum.processing.org/two/discussion/19819/how-to-saveframe-high-quality-when-using-pngs</link>
      <pubDate>Mon, 19 Dec 2016 00:26:30 +0000</pubDate>
      <dc:creator>vincep</dc:creator>
      <guid isPermaLink="false">19819@/two/discussions</guid>
      <description><![CDATA[<p>Ive made a sketch</p>

<p>I want to output on key press at High Quality.
How do you do it when using imported images rather than Co Ordinates?</p>

<p>Ive got a text screen at the beginning and the images are called 'letter' .png.
The code makes a collage. I'd like to be able to save individual frames at high res.</p>

<pre><code>PImage [] picArray = new PImage [42];
float r = random (.1, 1);




void setup() {

    size (480,777,JAVA2D);

{  textSize(32);
fill(180,75,90);
text("UP ARROW TO GENERATE", 20, 360); 
fill(180,75,90);
text("ENTER TO SAVE FRAME ", 20, 400);
 }

for (int p = 0; p &lt; picArray.length; p++) {
    picArray[p] = loadImage("letter" + nf(p,1) + ".png");
}

}

void draw() {


   background(255);
   for(int b=0; b&lt;2000; b++){
    tint(random(255),random(255));
    rotate(random(360));
 image(picArray[int(random(picArray.length))], random (width), random (height),r*(1080),r*(720));
   }
}

void keyPressed() {




  if (keyCode == ENTER){
    saveFrame("fragment-####.jpg");
  }
}


void mousePressed() {
  keyPressed();

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Can the save() function include p5 elements within the saved image?</title>
      <link>https://forum.processing.org/two/discussion/19707/can-the-save-function-include-p5-elements-within-the-saved-image</link>
      <pubDate>Mon, 12 Dec 2016 20:28:39 +0000</pubDate>
      <dc:creator>jacorre</dc:creator>
      <guid isPermaLink="false">19707@/two/discussions</guid>
      <description><![CDATA[<p>I've been playing around with the <a rel="nofollow" href="https://p5js.org/reference/#/p5/save">save()</a> function. I can get it to successfully save the drawing on my canvas as an image. However, when using the <a rel="nofollow" href="https://p5js.org/reference/#/libraries/p5.dom">DOM</a> library and creating p5.Elements that float on top of the canvas, these are not included when saving the canvas.</p>

<p>Is there a way to include p5.Elements when saving the canvas as an image?</p>

<p>Thank you!</p>
]]></description>
   </item>
   <item>
      <title>Does anybody have a clue about this very weird color behavior</title>
      <link>https://forum.processing.org/two/discussion/18852/does-anybody-have-a-clue-about-this-very-weird-color-behavior</link>
      <pubDate>Wed, 02 Nov 2016 20:37:29 +0000</pubDate>
      <dc:creator>Matei</dc:creator>
      <guid isPermaLink="false">18852@/two/discussions</guid>
      <description><![CDATA[<p>Hello, so I have noticed a very weird behavior of colors, which will be better explained visually. First a small introduction to what I want to do : first, open a file, which is a 9x9 pixels JPEG image. Then I want to apply the color of each pixel in the first line to all following vertical pixels. Very simple indeed, there's how I did by code :</p>

<pre><code>PImage loadedImgage;
String selectedPath = "";

void fileSelected(File selection) {
  selectedPath = selection.getAbsolutePath();
  loadedImgage = loadImage(selectedPath);
}

String getFileName(String completeFileName) {
  String[] fileNameParts = split(completeFileName, ".");
  fileNameParts = shorten(fileNameParts);
  return join(fileNameParts, ".");
}

void keyPressed() {
  if(key == 's') {
    save(getFileName(selectedPath) + "__.jpg");
    exit();
  }
}

void settings() {
  selectInput("Select a file to process:", "fileSelected");
  while (loadedImgage == null)  delay(100);
  size(loadedImgage.width, loadedImgage.height); 
}

void draw() {
  background(loadedImgage);

  for(int i = 0; i &lt; loadedImgage.width; i++) {
    color imageColor = get(i, 0);

    noStroke();
    fill(imageColor);
    rect(i, 0, 1, 9);
  }

  noLoop();
}
</code></pre>

<p>Here are the visuals :
<img src="https://c6.staticflickr.com/6/5626/30739867845_ba8c9cb93c_o.jpg" alt="" /></p>

<p>So as you can see first column of the modified file should have the same color as the first pixel of the original file (255;242;6), but strangely it doesn't, it's even a totally new color (255;225;75) which doesn't exist in any of the existing pixels !</p>

<p>So do any of you know how is this possible?
Thanx a lot for your help</p>
]]></description>
   </item>
   <item>
      <title>PGraphics Output Doesn't... (large pngs)</title>
      <link>https://forum.processing.org/two/discussion/17877/pgraphics-output-doesn-t-large-pngs</link>
      <pubDate>Wed, 17 Aug 2016 14:11:00 +0000</pubDate>
      <dc:creator>Jim_Plaxco</dc:creator>
      <guid isPermaLink="false">17877@/two/discussions</guid>
      <description><![CDATA[<p>Hi folks, 
My story is that I am running P302 on Ubuntu Linux. I have a sketch that outputs a PGraphics object in PNG format no problem. The other day I upped the size of the PNG output to 10x7K. The program ran the same as always (no error messages) but the output file simply wasn't there. Dropping back to a smaller size, the output file was written to disk. Going back to the 10x7K size - program runs normally but no output file on disk.</p>

<p>I then changed my output file format from PNG to TIF and the output file was output!</p>

<p>So my two questions are:</p>

<p>1) Have others experienced problems saving large PGraphics objects as PNGs?</p>

<p>2) Is there a way I can discover what is going on under the covers in the creation of PNG output such that it fails but produces no error message in the console? Note I haven't tried a try/catch but as the statement appears to run normally (no error messages and program execution continues normally) I'm betting try/catch wouldn't tell me anything.</p>

<p>Thanks.</p>
]]></description>
   </item>
   <item>
      <title>[Likely a Bug] Processing can't save() different PGraphics of different sizes</title>
      <link>https://forum.processing.org/two/discussion/17320/likely-a-bug-processing-can-t-save-different-pgraphics-of-different-sizes</link>
      <pubDate>Mon, 27 Jun 2016 02:17:07 +0000</pubDate>
      <dc:creator>Henri</dc:creator>
      <guid isPermaLink="false">17320@/two/discussions</guid>
      <description><![CDATA[<p>Hi, i was trying to save various PGraphics as an "export" function on my sketch and noticed a strange behavior.
When exporting some PGraphics would be saved perfectly, while others would be saved as entire black images. I've reduced the code and made an minimal sketch to test the PGraphic's save() method and i noticed when you're saving various PGraphics and they have the same size, everything works perfectly. When they have different sizes, the output is buggy and some images will be black (and of varying size)</p>

<p>Below is just the code, but i've uploaded the sketch+images to my dropbox: <a rel="nofollow" href="https://dl.dropboxusercontent.com/u/42670557/Software/testPGraphics.rar">download (5 kb)</a></p>

<pre><code>PGraphics[] pg;
PImage[] imgs;
File dir;
File[] files;

void setup() {
  size(300, 300);
  initialize();
}

void draw() { 
  background(0, 255, 0);
  //draw the image on every PGraphics. Then draw the PGraphics on the screen.
  for (int i = 0; i&lt; imgs.length; ++i)
  {
    pg[i].beginDraw();
    pg[i].image(imgs[i], 0, 0);
    pg[i].endDraw();
    image(pg[0], 0, 0);
  }
}

void initialize() {
  dir = new File(sketchPath("")+"/img"); 
  files = dir.listFiles();
  loadImages();
  //initialize the PGraphics
  pg = new PGraphics[imgs.length];
  for (int i = 0; i&lt; imgs.length; ++i)
  {
    pg[i] = createGraphics(imgs[i].width, imgs[i].height);
  }
}

void loadImages() {
  imgs = new PImage[files.length];
  //loads every .png file into the imgs array
  for (int i = 0; i &lt;= files.length - 1; ++i)
  {
    String path = files[i].getAbsolutePath();
    if (   path.toLowerCase().endsWith(".png")   )
    {
      imgs[i] = loadImage(path);
    }
    println("image "+i+":  "+path);
  }
}

void keyPressed() {
  if (key=='s') {
    println("EXPORTING");
    for (int i = 0; i&lt; imgs.length; ++i)
    {
      //pg[i].beginDraw();//tried without beginDraw() and endDraw. Results are the same
      pg[i].save("test-"+i+".png");
      //pg[i].endDraw();//tirar isso se não funfar
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>High Resolution Output for P3D</title>
      <link>https://forum.processing.org/two/discussion/17162/high-resolution-output-for-p3d</link>
      <pubDate>Wed, 15 Jun 2016 22:00:23 +0000</pubDate>
      <dc:creator>chrisb78</dc:creator>
      <guid isPermaLink="false">17162@/two/discussions</guid>
      <description><![CDATA[<p>I'm using the following code snippet (from <a href="https://amnonp5.wordpress.com/2012/01/28/25-life-saving-tips-for-processing/" target="_blank" rel="nofollow">https://amnonp5.wordpress.com/2012/01/28/25-life-saving-tips-for-processing/</a> - number 16) to export a scaled-up high resolution file. Everything works perfectly as long as size() and createGraphics() use the 2D renderer:</p>

<pre><code>void setup() {
  size(500, 500); // IMPLICIT USE OF 2D RENDERER
}

void draw() {
  background(255);
  smooth();
  strokeWeight(10);
  fill(255, 0, 0);
  ellipse(width/2, height/2, 200, 200);
}

void keyPressed() {
  if (key == 's') {
    save("normal.png");
    saveHiRes(5);
    exit();
  }
}

void saveHiRes(int scaleFactor) {
  PGraphics hires = createGraphics(width*scaleFactor, height*scaleFactor, JAVA2D); // CREATION OF 2D PGRAPHICS OBJECT
  beginRecord(hires);
  hires.scale(scaleFactor);
  draw();
  endRecord();
  hires.save("hires.png");
}
</code></pre>

<p>However, once the two bold lines use P3D instead (code at the end of this post), the program results in two problems:
1. The following error message appears: "OpenGL error 1282 at top endDraw(): invalid operation" (on Win7 with updated drivers)
2. Scaling doesn't actually happen - instead, unscaled image sits in the left bottom of the hi-res PGraphics object - like this:
<img src="https://forum.processing.org/two/uploads/imageupload/439/RUX1T1PICDSM.png" alt="_hires_800px_test" title="_hires_800px_test" /></p>

<p>The correct result should look like this:
<img src="https://forum.processing.org/two/uploads/imageupload/644/BSEB4ZNGTSG3.png" alt="normal" title="normal" /></p>

<p>After researching this, I couldn't find any high-resolution output for people working with a 3D renderer. I don't care so much about how to create hi-res output, and tried several approaches - without luck yet.</p>

<p>Any help would be greatly appreciated!</p>

<p>Here's the 3D version of the initial code snippet:
    void setup() {
      size(500, 500, P3D); // 3D RENDERER
    }</p>

<pre><code>void draw() {
  background(255);
  smooth();
  strokeWeight(10);
  fill(255, 0, 0);
  ellipse(width/2, height/2, 200, 200);
}

void keyPressed() {
  if (key == 's') {
    save("normal.png");
    saveHiRes(5);
    exit();
  }
}

void saveHiRes(int scaleFactor) {
  PGraphics hires = createGraphics(width*scaleFactor, height*scaleFactor, P3D); // CREATION OF 3D PGRAPHICS OBJECT
  beginRecord(hires);
  hires.scale(scaleFactor);
  draw();
  endRecord();
  hires.save("hires.png");
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Is there a file size limit for the save() method</title>
      <link>https://forum.processing.org/two/discussion/17146/is-there-a-file-size-limit-for-the-save-method</link>
      <pubDate>Tue, 14 Jun 2016 21:31:33 +0000</pubDate>
      <dc:creator>craigson</dc:creator>
      <guid isPermaLink="false">17146@/two/discussions</guid>
      <description><![CDATA[<p>I'm loading an image into memory and manipulating the pixel data inside of my sketch.  However, when I try and use either the save member function of the p5.image object, or the I/O save() method, if the original image was over over a specific size (larger than about 150kb), the download of the manipulated image fails ( the code doesn't throw any errors, but the download fails in the browser, stating "Failed - Network Error".  Is there a known limit to the size of a file that can be saved using either of these methods?</p>

<p>Here's an example of how I'm using the methods:</p>

<p><code>var img = createImage(width, height);
img.save("test", "png");
// or this save(img, "test.png");</code></p>
]]></description>
   </item>
   <item>
      <title>PImage.save() not working?</title>
      <link>https://forum.processing.org/two/discussion/16399/pimage-save-not-working</link>
      <pubDate>Tue, 03 May 2016 09:57:23 +0000</pubDate>
      <dc:creator>RaulF</dc:creator>
      <guid isPermaLink="false">16399@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I'm trying to save a PImage and I'm getting the famous "PImage.save() requires an absolute path...".
The PImage.save() code reference doesn't work either.</p>

<pre><code>size(100, 100);
PImage tower = loadImage("tower.jpg");
PImage newImage = createImage(100, 100, RGB);
newImage = tower.get();
newImage.save("outputImage.jpg");
</code></pre>

<p>Any idea? It should work. I'm working with the last version, and Mac OSX.</p>

<p>thanks!</p>
]]></description>
   </item>
   <item>
      <title>How do I export an image that is larger than my monitor?</title>
      <link>https://forum.processing.org/two/discussion/16228/how-do-i-export-an-image-that-is-larger-than-my-monitor</link>
      <pubDate>Sun, 24 Apr 2016 17:40:16 +0000</pubDate>
      <dc:creator>BITs_</dc:creator>
      <guid isPermaLink="false">16228@/two/discussions</guid>
      <description><![CDATA[<p>Hello! 
I have a bit of experience with processing, but nothing really in depth, so perhaps someone with more experience than me can help. 
I am attempting to write a program that will take an image I have created, and quickly crop it into all the necessary sizes to be put onto Sense6 products. The code I have so far is:</p>

<pre><code>PImage input; 

void setup(){
  size(2047, 2047);
  surface.setResizable(true);

  selectInput("Select an image to process:", "selectImage");     
  interrupt();
  println("Delay stopped");
}

void selectImage(File selection){
  if (selection == null){
    println("error- no file selected");
  }else{
    input = loadImage(selection.getAbsolutePath());
    println("image loaded");
  }
}

void interrupt(){
  while(input == null)delay(200);
}

void draw(){
  PImage phoneCase; //1300px (width) X 2000px (height)

  phoneCase = input.get(input.width/2-650, input.height/2-1000, 1300, 2000);
  println("phonecase image got");
  surface.setSize(phoneCase.width, phoneCase.height);
  image(phoneCase, 0,0);
  saveFrame("output/phoneCase.jpeg");
  exit();

}
</code></pre>

<p>I've cut out a lot of the other products because I'm just trying to test it right now. 
So anyway, what I'm expecting currently is an image in the folder (sketch folder)/output called phoneCase.jpeg that is 1300px X 2000px. Except that what I'm getting is an image called phoneCase.jpeg that is 1300px x 741px. 741px happens to be really close to the height of my monitor, which is 768px. This sketch gives no errors, so I have nothing to go on. 
I looked into using code like <code>save(phoneCase, "output/phoneCase.jpeg");</code>, but just based on the reference documentation, it seemed like that wouldn't work. 
So, with my monitor being 1366px X 768px, how can I save a PImage that is 1300px X 2000px?</p>
]]></description>
   </item>
   <item>
      <title>PGraphics saves messed up images after creating a new PGraphics object in a different size</title>
      <link>https://forum.processing.org/two/discussion/15878/pgraphics-saves-messed-up-images-after-creating-a-new-pgraphics-object-in-a-different-size</link>
      <pubDate>Wed, 06 Apr 2016 10:24:29 +0000</pubDate>
      <dc:creator>bckmnn</dc:creator>
      <guid isPermaLink="false">15878@/two/discussions</guid>
      <description><![CDATA[<p>Hi there,
below i attached a small program that generates PNGs. If i change the size of the new PGraphics objects the saved PNGs start to look messed up.</p>

<p>To reproduce the issue run the code from the bottom. Conversion will start an you will get pngs like this:</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/231/JU8OTVD7LAY6.png" alt="Bildschirmfoto 2016-04-06 um 12.12.56" title="Bildschirmfoto 2016-04-06 um 12.12.56" /></p>

<p>if you do a mouse click on the canvas, the size of the pngs that should be generated is changed and a few new items are added. The results look like in the screenshot below, some of the images are blank, some are distorted and they still have the old size.</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/010/KCHMBM2X2J5U.png" alt="Bildschirmfoto 2016-04-06 um 12.13.11" title="Bildschirmfoto 2016-04-06 um 12.13.11" /></p>

<p>Is there a way to avoid this behavior? is this a bug in processing? am i missing something?</p>

<p>Any input appreciated!</p>

<pre><code>PGraphics png;
ArrayList&lt;String&gt; cue = new ArrayList&lt;String&gt;();
boolean conversion = false;
int pngSize = 64;

void setup() {
  size(400, 400);
  println("creating 64px letters");
  cue.add("A");
  cue.add("B");
  cue.add("C");
  conversion = true;
}

public void mousePressed(){
  println("creating 128px letters");
  pngSize = 128;
  cue.add("A");
  cue.add("B");
  cue.add("C");
  cue.add("D");
  cue.add("E");
  cue.add("F");
  conversion = true;
}

void saveNextInCue(){
  String letter = cue.remove(0);
  println("pngSize value is "+pngSize);
  png = createGraphics( pngSize, pngSize);
  png.beginDraw();
  png.textSize(30);
  png.text(letter,30,30);
  png.fill(random(255),0,255);
  png.rect(0,0,10,10);
  png.endDraw();
  png.save(sketchPath(letter+".png"));
}

void draw() {
  int bg = color(255,0,0);
  if (!conversion){
    bg = color(0,255,0);
  }
  background(bg);
  if( conversion == true){
    saveNextInCue();
    if(cue.size() == 0){
      conversion = false;
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>p5js - save(); only works in setup();</title>
      <link>https://forum.processing.org/two/discussion/15711/p5js-save-only-works-in-setup</link>
      <pubDate>Sun, 27 Mar 2016 15:36:00 +0000</pubDate>
      <dc:creator>afzalghareeb</dc:creator>
      <guid isPermaLink="false">15711@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone,</p>

<p>I am trying to save a single string in a .txt file, but the save(); function seems to work only inside the setup(); function.
Here is an exemple that doesn't work:<br />
<code>
var data;
function setup() {
   Canvas = createCanvas(300, 300);
   data = "I am a string";
}
function saveMe() {
   save(data, 'myText.txt');
}
function mouseClicked() {
   saveMe();
}
function draw() {
   background(255);
}</code></p>

<p>Any idea??
Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Saving Errors</title>
      <link>https://forum.processing.org/two/discussion/15166/saving-errors</link>
      <pubDate>Sun, 28 Feb 2016 00:07:59 +0000</pubDate>
      <dc:creator>lindsayhickson</dc:creator>
      <guid isPermaLink="false">15166@/two/discussions</guid>
      <description><![CDATA[<p>So, it's me once again, sounding like an absolute n00b. I have now come to realize that the starter code given to me for my school project has an error with its save feature. If you upload a photo, put the grayscale effect on it, and then try to save it, it will do a random streak or streaks of color over the image. Every time you save it, the random streak is in a different spot. Please help me. I'm very new to this, so I don't know where to even begin:</p>

<pre><code>  /**   DM Filter Project Starter Code
  /*    v.20131126
  /*    Bradley Beth
  **/

  boolean PicLoaded = false;
  boolean Grayscale = false;
  boolean Effect1 = false;
  boolean Effect2 = false;
  boolean Effect3 = false;
  int picWidth = 0;
  int picHeight = 0;
  PImage img;

  /***********************************/

  void setup() 
  {
    size(800, 480);
    background(185);
    textAlign(LEFT);
    textSize(16); 
  }

  void draw()
  {

    background(185);
    noStroke();
    int picStart = 0;
    int picEnd = 0;

    /* draw buttons */

    stroke(0);
    fill(0);
    textSize(16);
    text("File Operations",665,30);
    line(650,0,650,480);
    noStroke();

    fill(255);
    rect(660, 50, 130, 40, 10);
    fill(55);
    text("Load Picture", 675, 75);

    fill(255);
    rect(660, 100, 130, 40, 10);
    fill(55);
    text("Save Picture", 675, 125);

    stroke(0);
    line(650,150,800,150);
    noStroke();

    stroke(0);
    fill(0);
    textSize(16);
    text("Filter Effects",675,180);
    line(650,0,650,480);
    noStroke();

    if (Grayscale)
      fill(#FFFF7D);    //Effect on means a yellow lighted button
    else
      fill(255);
    rect(660, 200, 130, 40, 10);
    fill(55);
    text("Grayscale", 680, 225);

    if (Effect1)
      fill(#FFFF7D);    //Effect on means a yellow lighted button
    else
      fill(255);
    rect(660, 250, 130, 40, 10);
    fill(55);
    text("Effect One", 680, 275);

    if (Effect2)
      fill (#FFFF7D);     //Effect on means a yellow lighted button 
    else
      fill(255); 
    rect(660, 300, 130, 40, 10);
    fill(55);
    text("Effect Two", 680, 325);

    if (Effect3)
      fill (#FFFF7D);    //Effect on means a yellow lighted button
    else
      fill(255);   
    rect(660, 350, 130, 40, 10);
    fill(55);
    text("Effect Three", 680, 375);

    noStroke();
    textSize(16);

    //The following loads and displays an image file.
    //The image is resized to best fit in a 640x480 frame.
    if (PicLoaded)
    {     
      picWidth = img.width;
      picHeight = img.height;

      if (picWidth &gt; 640)
      {
        picHeight = (int)(picHeight*(640.0/picWidth));
        picWidth = 640;
      }
      if (picHeight &gt; 480)
      {
        picWidth = (int)(picWidth*(480.0/picHeight));
        picHeight = 480;
      }
      image(img, 0, 0, picWidth, picHeight);

      picStart = 0;
      picEnd = picStart+width*picHeight;

      /***** Effects Code *****/

      /* This sample grayscale code may serve as an example */
      if (Grayscale)
      {
        loadPixels();
        int i = picStart;
        while (i &lt; picEnd) 
        {
          color c = pixels[i];
          float gray = (red(c)+green(c)+blue(c))/3.0;  //average the RGB colors
          pixels[i] = color(gray, gray, gray);
          i = i + 1;
          if (i % width &gt;= picWidth)        // This will ignore anything on the line that 
            i = i + width - picWidth;       // after the image (such as buttons)
        }   
      }

      if (Effect1)
      {
        //do stuff
      }

      if (Effect2)
      {
        //do stuff
      }

      if (Effect3)
      {
        //do stuff
      }

      updatePixels(); 
      redraw();
    }

    fill(255);
    noStroke();
  }

  void mouseClicked() {

    redraw();
  }

  void mousePressed()
  {
    //The following define the clickable bounding boxes for any buttons used.
    //Note that these boundaries should match those drawn in the draw() function.

    if (mouseX&gt;660 &amp;&amp; mouseX&lt;790 &amp;&amp; mouseY&gt;50 &amp;&amp; mouseY&lt;90)
    {
      selectInput("Select a file to process:", "infileSelected");
    }

    if (mouseX&gt;660 &amp;&amp; mouseX&lt;790 &amp;&amp; mouseY&gt;100 &amp;&amp; mouseY&lt;140)
    {
      selectOutput("Select a file to write to:", "outfileSelected");
    }

    if (mouseX&gt;660 &amp;&amp; mouseX&lt;790 &amp;&amp; mouseY&gt;200 &amp;&amp; mouseY&lt;240 &amp;&amp; PicLoaded)
    {
      Grayscale = true;
    }   

    if (mouseX&gt;660 &amp;&amp; mouseX&lt;790 &amp;&amp; mouseY&gt;250 &amp;&amp; mouseY&lt;290 &amp;&amp; PicLoaded)
    {
      Effect1 = true;
    } 

    if (mouseX&gt;660 &amp;&amp; mouseX&lt;790 &amp;&amp; mouseY&gt;300 &amp;&amp; mouseY&lt;340 &amp;&amp; PicLoaded)
    {
      Effect2 = true;
    }  

    if (mouseX&gt;660 &amp;&amp; mouseX&lt;790 &amp;&amp; mouseY&gt;350 &amp;&amp; mouseY&lt;390 &amp;&amp; PicLoaded)
    {
      Effect3 = true;
    } 

    redraw();
  }

  void infileSelected(File selection) 
  {
    if (selection == null) 
    {
      println("IMAGE NOT LOADED: Window was closed or the user hit cancel.");
    } 
    else 
    {
      println("IMAGE LOADED: User selected " + selection.getAbsolutePath());
      img = loadImage(selection.getAbsolutePath());
      PicLoaded = true;
      Grayscale = false;
      Effect1 = false;
      Effect2 = false;
      Effect3 = false;
      redraw();
    }
  }

  void outfileSelected(File selection) 
  {
    if (selection == null) 
    {
      println("IMAGE NOT SAVED: Window was closed or the user hit cancel.");
    } 
    else 
    {
      println("IMAGE SAVED: User selected " + selection.getAbsolutePath());
      updatePixels();
      redraw();
      save(selection.getAbsolutePath());
      redraw();
    }
  }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Capture image from a small portion of screen</title>
      <link>https://forum.processing.org/two/discussion/15184/capture-image-from-a-small-portion-of-screen</link>
      <pubDate>Mon, 29 Feb 2016 00:06:18 +0000</pubDate>
      <dc:creator>spartacus</dc:creator>
      <guid isPermaLink="false">15184@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
I have created a large interface with a small portion dedicated to my webcam capture.
The problem I am facing is that when ever I attempt to save an image for my webcam, the entirety of my interface is saved.
How can I save just a selected area of my screen?
The relevant code is given below. (I should note that I have created a button to save the images)</p>

<p>`import processing.video.*;</p>

<p>Capture cam;</p>

<pre><code>void setup() {
  size (1600,800);
  cam =  new Capture(this, "name=Logitech HD Webcam C270,size=352x288,fps=30");
  cam.start();

}
void captureEvent(Capture cam) {
cam.read();
}

void draw() {
  background(#BCBCB8);
   image(cam , 1100, 100);
   fill(126,131,245);
   stroke(255);
   rect(1200,450,150,50);

   String s2 = "Capture Image"; 
  stroke(5,5,5); 
  fill(5,5,5);
  textSize(20); 
  text( s2, 1203,480);



    }


void mousePressed() {

  if(mouseX&gt;1200 &amp;&amp; mouseX &lt; 1350 &amp;&amp; mouseY&gt;440 &amp;&amp; mouseY &lt; 500){
  saveFrame("captured_image-##.jpg");


  }
}



  `
</code></pre>
]]></description>
   </item>
   <item>
      <title>saveFrame does not save all frames</title>
      <link>https://forum.processing.org/two/discussion/14545/saveframe-does-not-save-all-frames</link>
      <pubDate>Wed, 20 Jan 2016 03:19:12 +0000</pubDate>
      <dc:creator>plux</dc:creator>
      <guid isPermaLink="false">14545@/two/discussions</guid>
      <description><![CDATA[<p>Hi, all, I'm using saveFrame() because I need to make a video. The code I have is an audio visualization the nI have a song which is playing. the song is about 3 minutes and I'm running the sketch at 60fps. However when the song is finished and I stop the sketch I will have only (more or less) 7200 frames. 7200/60 is about 2 minutes while the song is instead 3+ minutes..why is that?? I also tried to set the framerate at 30 fps but I get the same issue. Am I missing anything?</p>

<p>Thank you</p>

<p>P.</p>
]]></description>
   </item>
   <item>
      <title>Render an Animation while using the Minim Library</title>
      <link>https://forum.processing.org/two/discussion/14501/render-an-animation-while-using-the-minim-library</link>
      <pubDate>Sat, 16 Jan 2016 23:43:42 +0000</pubDate>
      <dc:creator>nightLife</dc:creator>
      <guid isPermaLink="false">14501@/two/discussions</guid>
      <description><![CDATA[<p>I recently created an audio visualizer with the Minim library. I would now like to render it into mp4. I have tried using saveFrame() to create images of the animation but when I later combine the images into an mp4 file the video does not sync with the audio anymore. I am assuming this is because the saveFrame() function is expensive and can not create the correct amount of images in the time given by the program running. So my question now is how can I render my Processing animation such that when I render it into mp4 the animation matches with audio when I combine the video and audio together in a editing software.</p>
]]></description>
   </item>
   <item>
      <title>Need Help!! Pgraphics Clear() does not work well in my code..</title>
      <link>https://forum.processing.org/two/discussion/14166/need-help-pgraphics-clear-does-not-work-well-in-my-code</link>
      <pubDate>Sun, 27 Dec 2015 21:17:59 +0000</pubDate>
      <dc:creator>DongY</dc:creator>
      <guid isPermaLink="false">14166@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I'm new here and very pleasured to be at a minimun level to ask a question understanding Processing codes (&gt;.&lt;)V.
I'm making an interactive drawing tool to save one's own alphabet types(.png) with a transparent background.
But I have a problem to clear the previous type to draw a new type after using PGrphics...
I've found lots of references for this but I couldn't find a solution to clean the type written.</p>

<p>Maybe for someone it's a simple to solve this problem, I hope your help please~!!</p>

<p>Thank you for your help in advance :)</p>

<hr />

<p>Here's my code for it :</p>

<p>PGraphics alphaG;</p>

<p>float med_mouseX=mouseX;</p>

<p>float med_mouseY=mouseY;</p>

<p>void setup() {</p>

<p>size(400, 500);
  background(255);
  smooth();
  frameRate(30);
  alphaG = createGraphics(width, height);
}</p>

<p>void draw() {
  alphaG.beginDraw();</p>

<p>if (mousePressed) {</p>

<pre><code>//draw an alphabet type
//alphaG.noStroke();
med_mouseX=mouseX+random(-5, 30);
med_mouseY=mouseY+random(-5, 30);
alphaG.stroke(255);
alphaG.strokeWeight(random(20, 60));
alphaG.strokeCap(ROUND);
alphaG.stroke(0, random(0, 255), random(0, 255));
alphaG.line(mouseX, mouseY, pmouseX, pmouseY);
alphaG.endDraw();
image(alphaG, 0, 0);
</code></pre>

<p>}
}</p>

<p>void keyPressed() {
//clear a type written 
  if (key == BACKSPACE) {
    alphaG.clear();
  }
//save an alpha written with keyboard(this code can be shorter? ^^?)
  if (key=='a') {
    String fileName = "data/"+"a"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='b') {
    String fileName = "data/"+"b"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='c') {
    String fileName = "data/"+"c"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='d') {
    String fileName = "data/"+"d"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='e') {
    String fileName = "data/"+"e"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='f') {
    String fileName = "data/"+"f"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='g') {
    String fileName = "data/"+"g"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='h') {
    String fileName = "data/"+"h"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='i') {
    String fileName = "data/"+"i"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='j') {
    String fileName = "data/"+"j"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='k') {
    String fileName = "data/"+"k"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='l') {
    String fileName = "data/"+"l"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='m') {
    String fileName = "data/"+"m"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='n') {
    String fileName = "data/"+"n"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='o') {
    String fileName = "data/"+"o"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='p') {
    String fileName = "data/"+"p"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='q') {
    String fileName = "data/"+"q"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='r') {
    String fileName = "data/"+"r"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='s') {
    String fileName = "data/"+"s"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='t') {
    String fileName = "data/"+"t"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='u') {
    String fileName = "data/"+"u"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='v') {
    String fileName = "data/"+"v"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='w') {
    String fileName = "data/"+"w"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='x') {
    String fileName = "data/"+"x"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='y') {
    String fileName = "data/"+"y"+"1"+".png";
    alphaG.save(fileName);
  }</p>

<p>if (key=='z') {
    String fileName = "data/"+"z"+"1"+".png";
    alphaG.save(fileName);
  }
}</p>
]]></description>
   </item>
   </channel>
</rss>