Is there a way to request the camera to restrict the size of pictures taken? My project needs two small pictures that would be displayed or printed in a "thumbnail" size, approximately 200x200 pixels. A 6mb picture is way too big for this use. I thought about limiting the file size in the component, but I don't think that would force the camera to downsize the photo.
Thanks!
edit: For future people, this is what I ended up with in the onFileReceived
event to solve my issue. Forgive my dirty code.
def runAction(self, event):
from io import BytesIO
from java.io import ByteArrayInputStream
from java.io import ByteArrayOutputStream
from javax.imageio import ImageIO
from java.awt import Image
from java.awt.image import BufferedImage
pic_data = event.file.getBytes()
stream = ByteArrayInputStream(pic_data)
original_image = ImageIO.read(stream)
# set target size and preserve aspect ratio
target_width = 640
original_width = original_image.getWidth(None)
original_height = original_image.getHeight(None)
ratio = float(original_height) / float(original_width)
target_height = int(target_width * ratio)
# rescale
scaled = original_image.getScaledInstance(target_width, target_height, Image.SCALE_SMOOTH)
# buffer image for writing
buffered = BufferedImage(target_width, target_height, BufferedImage.TYPE_INT_RGB)
g = buffered.createGraphics()
g.drawImage(scaled, 0, 0, None)
g.dispose()
# encode to JPEG
out = ByteArrayOutputStream()
ImageIO.write(buffered, 'jpg', out)
out.flush()
rescaled_data = out.toByteArray()
out.close()
this takes a 7mb image from an ipad and shrinks the file size to 27k