You can scale the image in the call to drawImage. Here’s what is use (bytes is the blob read from the database, you don’t need a temp file):
width = event.source.getWidth()
height = event.source.getHeight()
try:
from javax.imageio import ImageIO
from java.io import ByteArrayInputStream
bais = ByteArrayInputStream(bytes)
image = ImageIO.read(bais)
bais.close()
imgRatio = float(image.getWidth())/float(image.getHeight())
if (imgRatio > 0):
finalWidth = int(height * imgRatio)
if (finalWidth > width):
finalWidth=width;
finalHeight = int(finalWidth / imgRatio)
print imgRatio
else:
finalWidth = width
finalHeight = height
print 'No ratio'
y = (height-finalHeight) / 2
g.drawImage(image,1,y,finalWidth,finalHeight,event.source)
except:
g.drawString(u'Bild kann nicht angezeigt werden', 10, height/2)