Alpha channel not being saved in tiffwriter
Posted: Wed Jul 26, 2017 3:52 pm
Hi, I'm trying to create tiff images with alpha channels. As a basic example, I've modified the MinimumWiter example to do this. The code below is supposed to create a 512x512 RGBA image with a random color/alpha at each pixel. I get a color image with random colors, but the alpha channel appear to be locked at opaque. How can I modify this code so that the alpha values show up as random too?
- Code: Select all
String id = "d:\\images\\blank.tif";
int w = 512, h = 512, c = 4;
int pixelType = FormatTools.UINT8;
byte[] img = new byte[w * h * c * FormatTools.getBytesPerPixel(pixelType)];
for (int i=0; i<img.length; i++) img[i] = (byte) (256 * Math.random());
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
IMetadata meta = service.createOMEXMLMetadata();
MetadataTools.populateMetadata(meta, 0, null, false, "XYZCT",FormatTools.getPixelTypeString(pixelType), w, h, 1, c, 1, c);
meta.setPixelsSizeC(new PositiveInteger(4), 0);
IFormatWriter writer = new ImageWriter();
writer.setMetadataRetrieve(meta);
writer.setId(id);
writer.saveBytes(0, img);
writer.close();
System.out.println("Done.");