c# - File size increases after reading png file from disk and saving it back -
i'm working on small program read png files disk, modifications , save back. running smoothly except 1 small problem, after saved file disk, size increases, example, 27.1mb file become 33.3mb.
after debugging narrow down reading , saving code. code i'm using:
bitmap img = new bitmap(<path file>); //omitted img.save(<path new file>, imageformat.png);
i've verified no matter if or not make modification, reading , saving image cause size change. furthermore, if opened saved file paint , save there, file shrink original size.
how read , save image without changing size?
have tried playing endoder.colordepth field? png supports transparency , might saving information not needed image.
imagecodecinfo pngcodec = imagecodecinfo.getimageencoders().where(codec => codec.formatid.equals(imageformat.png.guid)).firstordefault(); if (pngcodec != null) { encoderparameters parameters = new encoderparameters(); parameters.param[0] = new encoderparameter(encoder.colordepth, 24); //8, 16, 24, 32 (base on format) image.save(stream, pngcodec, parameters); }
additional info here: https://msdn.microsoft.com/en-us/library/system.drawing.imaging.encoder.colordepth(v=vs.110).aspx
Comments
Post a Comment