How to reduce the size of an image in C# and .NET 3.5? -
i have screen shot take in mobile app. screen shot takes 32 kb when saved png on disk.
i sending these central sql server , 32 kb big amount of times need store screen shot (approx 2500 times day).
is there kind of trickery can save smaller?
here code using take bitmap
bytes (to send server storage):
memorystream stream = new memorystream(); _signatureimage.save(stream, imageformat.png); return stream.toarray();
_signatureimage
bitmap
, screenshot in question.
here example of screen shot saving:
things pop mind (but don't know how them):
- reduce actual height , width of image (but in way not distort it).
- change black , white image (not sure if see real space savings this)
- compress more (i don't because not readable database).
note, has done programatically, , cannot take long, complex image manipulations out.
thanks help.
private static image resizeimage(int newsize, image originalimage) { if (originalimage.width <= newsize) newsize = originalimage.width; var newheight = originalimage.height * newsize / originalimage.width; if (newheight > newsize) { // resize height instead newsize = originalimage.width * newsize / originalimage.height; newheight = newsize; } return originalimage.getthumbnailimage(newsize, newheight, null, intptr.zero); }
this should work bitmap object type , resize height or width, depending on appropriate image dimensions. maintain scale.
edit:
you create new bitmap object , resize original image bitmap object.
bitmap b = new bitmap(newwidth, newheight); graphics g = graphics.fromimage((image)b); g.interpolationmode = interpolationmode.highqualitybicubic; g.drawimage(imgtoresize, 0, 0, newwidth, newheight); g.dispose(); return (image)b;
i don't have compact framework installed, seems should work you.
Comments
Post a Comment