graphics - Flipping vertically a raw image in Java -
i need flip in java raw image has rows inverted. inverted mean, first row of image stored @ end of file.
i managed achive want reordering image rows using auxiliar buffer. included code below.
i think can optimized translating coordinates, avoiding memory copy. tried implement databuffer invert rows, raster i'm using requires databufferbyte (a final class).
does knows more optimized way of doing want?
thank you
... int w = 640; int h = 480; byte[] flippeddata = new byte[640*480*4]; int scanlinelength = w*4; for(int i=0;i!=h; ++i) { system.arraycopy(originaldata, scanlinelength*i, flippeddata, scanlinelength*(h-i)-scanlinelength, scanlinelength); } databuffer db = new databufferbyte(flippeddata,flippeddata.length); writableraster raster = raster.createinterleavedraster(db, w, h, scanlinelength, 4, new int[]{2,1,0}, new point(0,0)); colorspace cs = colorspace.getinstance(colorspace.cs_srgb); colormodel cm = new componentcolormodel(cs, false, false, transparency.opaque, databuffer.type_byte); bufferedimage img = new bufferedimage(cm, raster, false, null); imageio.write(img, "jpeg", new file("out.jpg"));
affine transformations can constructed using sequences of translations, scales, flips, rotations, , shears.
see this , this see how flipping implemented using affinetransform
Comments
Post a Comment