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];
}
}