java - ImageIO.write() method and png -
why imageio.write(bufferedimage_dest,"png",new file(filedest));
writes jpg (without transparency colour) file instead png?
added:
static bufferedimage createresizedcopy(image originalimage, int scaledwidth, int scaledheight, boolean preservealpha) { system.out.println("resizing..."); int imagetype = preservealpha ? bufferedimage.type_int_rgb : bufferedimage.type_int_argb; bufferedimage scaledbi = new bufferedimage(scaledwidth, scaledheight, imagetype); graphics2d g = scaledbi.creategraphics(); if (preservealpha) { g.setcomposite(alphacomposite.src); } g.drawimage(originalimage, 0, 0, scaledwidth, scaledheight, null); g.dispose(); return scaledbi; } public static void scale(string src, int width, int height, string dest) throws ioexception { bufferedimage bsrc = imageio.read(new file(src)); bufferedimage bdest = new bufferedimage(width, height, bufferedimage.type_int_argb); bdest = createresizedcopy(bsrc, width, height, false); imageio.write(bdest,"png",new file(dest)); }
added:
well, in main() function i've called
scalejpg.scale((args[0],integer.parseint(args[1]),integer.parseint(args[2]), args[3]););
instead of
scalepng.scale((args[0],integer.parseint(args[1]),integer.parseint(args[2]), args[3]););
scalejpg similiar, previous class in folder.
i must discard notepad , use ide. question delete.
add
g.setrenderinghint(renderinghints.key_interpolation, renderinghints.value_interpolation_bilinear);
before g.drawimage(originalimage, 0, 0, scaledwidth, scaledheight, null);
to createresizedcopy
function.
Comments
Post a Comment