We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpVideo Capture,  Movie Playback,  Vision Libraries › Just grabbing jpg of current frame of webcam vid
Page Index Toggle Pages: 1
Just grabbing jpg of current frame of webcam vid (Read 405 times)
Just grabbing jpg of current frame of webcam vid
Nov 18th, 2009, 8:13pm
 
So I see the examples where the webcam is put out to the main drawing window via set or image.  This is great, but in my app I wanna put other stuff out to that and instead just get the jpg when I hit a key.  I have this app that gets the bytes of a PGraphics.  So is there a way to grab snap shot of web cam and then say getBytes on it... ?

I am new to all this graphics stuff or at least the way processing does it, so trying to figure out whats part of the system and whats not.  I wish the video capture had like theCapture.getJPG(); or something that grabs the latest frame...if I knew how to write it...

course then i couldnt say getBytes(theJPG) cause its not a PGraphics, its an PImage I am guessing...



my get bytes is this: (This is borrowed yes).
Code:
/**
* Get the given PGraphics bytearray
* @param src the source graphics
*/
public byte[] getBytes(PGraphics src){

switch(type){
case ImageToTwitter.JPEG:
// We need a new buffered image without the alpha channel
BufferedImage imageNoAlpha = new BufferedImage(src.width, src.height, BufferedImage.TYPE_INT_RGB);
src.loadPixels();
imageNoAlpha.setRGB(0, 0, src.width, src.height, src.pixels, 0, src.width);
return getBytesJPEG(imageNoAlpha);

case ImageToTwitter.PNG:
case ImageToTwitter.GIF:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
{
ImageIO.write((BufferedImage)src.image, imageType, baos);
}
catch (Exception e)
{
e.printStackTrace();
return new byte[0]; // Problem
}
return baos.toByteArray();

case ImageToTwitter.TIFF:
return getBytesTIFF(src);

default:
println("Unknown type");
return new byte[0];
}
}
Page Index Toggle Pages: 1