-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provide the more available size and format for the getImage() #15
Comments
Hi, I think this is very good idea, even if it requires not a small development effort. In case of formats such as JPG, PNG, BMP and other basic ones supported by ImageIO API, I think it will not be a problem, however in case of e.g. WebP, I would rather like to create separate sub project, to avoid adding more dependencies to Webcam Capture API itself. I will think about how this could be implemented in the best way. Thanks again! |
@sarxos ,i write this to an byteArrayOutPutStream,with the ImageIO,and then get the bytes from the byteArrayOutputStream. public class GrabTask implements Runnable{
protected final Webcam webcam;
protected final ByteArrayOutputStream byteArrayOutputStream;
protected final GrabberListener graberListener;
public GrabTask(Webcam webcam,
ByteArrayOutputStream byteArrayOutputStream,
GrabberListener graberListener) {
super();
this.webcam = webcam;
this.byteArrayOutputStream = byteArrayOutputStream;
this.graberListener = graberListener;
}
@Override
public void run() {
byteArrayOutputStream.reset();
BufferedImage bufferedImage = webcam.getImage();
BufferedImage compressedImage = ImageUtils.convertToType(
bufferedImage, BufferedImage.TYPE_3BYTE_BGR);
// System.out.println("image type :"+bufferedImage.getType());
if (orginData) {
graberListener.onGrabed(compressedImage);
return;
}
try {
ImageIO.write(compressedImage, "JPG", byteArrayOutputStream);
//
graberListener.onGrabed(byteArrayOutputStream.toByteArray());
//graberListener.onGrabed(byteArrayOutputStream.toByteArray());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} |
Just a note to your gist - I think you don't have to convert received image to |
really ?! i will have an test ! update: that's great i just remote the code ,and it still works fine. cause i need to encode the buffered image to h264 packet,so i just follow the example, and decode the packet, i am newbie for video~~ |
Hi @hepin1989, I didn't want to mess with byte[] bytes = WebcamUtils.getImageBytes(webcam, "jpg");
ByteBuffer buffer = WebcamUtils.getImageByteBuffer(webcam, "jpg"); And: byte[] bytes1 = ImageUtils.toByteArray(webcam.getImage(), "jpg");
byte[] bytes2 = ImageUtils.toByteArray(webcam.getImage(), "gif");
byte[] bytes3 = ImageUtils.toByteArray(webcam.getImage(), "webp"); The last example where WebP form,at is used can be done only when you have register ImageIO plugin supporting WebP encoding. It is available in SF: EDIT: (forgot to add link) http://sourceforge.net/projects/javavp8decoder/files/imageIO%20Plugin/ |
I also had to remove resolutions from Instead I've created new enum called Dimension size = WebcamResolution.VGA.getSize(); Sorry for all inconveniences, since, I guess you have already use it in your code. |
@sarxos ,noop,do you know that,your code and design is nice and clean ,i love it.to create several utility methods is more good. and the resolution is nice and clean too,i just wannt to metion you this. |
thanks first
when i use your api ,i always grab the original bufferedImage from the webcam.then i use the imageIO to wirte it to an BytearrayOutputStream,so i think how about.you provide some othere method such as
webcam.getImage(ImageType.JPG)
which can return an Jpeg image,and how about return bytebuffer or byte[] too.
i still implement an grabber which use an schedule service to grab the image with an listener .
i think that you can provide it too.
i think if you can provide the google's webp image type ?
i just wanna your great API to be more easy to use,so ,sorry for so many request.
https://gist.github.com/4489904
an i have found this:
http://code.google.com/p/thumbnailator/
which can scale up and scale down the image,it's fast and high quality
The text was updated successfully, but these errors were encountered: