java - Using TYPE_SHORT_GRAY for bufferedImage -


i have scenario where,

i need process image signed 16-bit, create bufferedimage using type_ushort_gray.

as mentioned signed java doesn't support type_short_gray.

also when use,

databufffer d = bi.getraster().getdatabuffer(); //bi buffered image 

d instance of databufferushort.

but expect instance of databuffershort.

how can create bufferedimage of type_short_gray (signed short).

am new this. in advance.

to create bufferedimage using signed short backing, need create databuffer/raster yourself. there's no type_short_gray constant.

try like:

int w = 1600; int h = 900;  // create signed 16 bit data buffer, , compatible sample model databuffer databuffer = new databuffershort(w * h); samplemodel samplemodel = new componentsamplemodel(databuffer.type_short, w, h, 1, w, new int[] {0});  // create raster sample model , data buffer writableraster raster = raster.createwritableraster(samplemodel, databuffer, null);  // create 16 bit signed gray color model colorspace colorspace = colorspace.getinstance(colorspace.cs_gray); colormodel colormodel = new componentcolormodel(colorspace, false, false, transparency.opaque, databuffer.type_short);  // create signed 16 bit image bufferedimage image = new bufferedimage(colormodel, raster, colormodel.isalphapremultiplied(), null);  system.out.println("image: " + image); 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -