Hi Daniele, im currently using 23.1 but i also tried with 23.4 and i get the same result, seems like the alpha band can't be handled because i tried to remove it with GDAL and everything works fine.
Il giorno mer 24 feb 2021 alle ore 09:43 Daniele Romagnoli < daniele.romagn...@geo-solutions.it> ha scritto: > Hi Lorenzo, > which GeoTools version are you using? > > I have just quickly tried with GeoTools master your very same code also > adding a final piece of code doing a rewrite on disk: > > writer = new GeoTiffWriter(new File("d:/download/writeback.tif"), null); > writer.write(grid, null); > writer.dispose(); > > and I didn't see any error and the image looks as the input one. > > > Please,let me know. > Regards, > Daniele > > > > On Mon, Feb 22, 2021 at 9:36 PM Lorenzo Di Giacomo <loridi...@gmail.com> > wrote: > >> Hi, i have a problem that i dont understand if GEOTOOLS handles (maybe >> with some HINTS), basically i read a TIFF image then i serialized it : >> >> >> >> >> >> >> >> >> >> >> *public static byte[] gridToBytes(GridCoverage2D grid) throws IOException >> { ByteArrayOutputStream baos = new ByteArrayOutputStream(); GeoTiffWriter >> writer = new GeoTiffWriter(baos, null); writer.write(grid, >> null); writer.dispose(); byte[] bytes = >> baos.toByteArray(); baos.flush(); baos.close(); return bytes;}* >> >> Then i deserialize it with: >> >> >> >> >> >> >> >> >> >> >> >> >> >> * public static GridCoverage2D bytesToGrid(byte[] bytes) throws >> IOException { ByteArrayInputStream bais = new >> ByteArrayInputStream(bytes); GeoTiffReader reader = null; try >> { Hints hints = new >> Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); >> reader = new GeoTiffReader(bais, hints); GridCoverage2D grid = >> reader.read(null); bais.close(); return grid; >> } catch (IllegalArgumentException e) { throw new >> IOException("Error on deserialization on tile"); } }* >> >> It works fine with some images, but i found some tiff (i have 150 of >> those, uploaded one for you if you wanna try: >> https://mega.nz/file/qJlEyTIQ#jgCE5pwfD5Y_AiUj2hSLTvTIS0lZ4CSm5D0Vb0eTk7U >> ) >> that gaves this error on deserialization: >> >> >> >> >> >> >> >> >> *Caused by: java.lang.IllegalArgumentException: bandOffsets.length is >> wrong! at >> javax.imageio.ImageTypeSpecifier$Interleaved.<init>(ImageTypeSpecifier.java:286) >> at >> javax.imageio.ImageTypeSpecifier.createInterleaved(ImageTypeSpecifier.java:399) >> at >> it.geosolutions.imageio.plugins.tiff.TIFFDecompressor.getRawImageTypeSpecifier(TIFFDecompressor.java:1027) >> at >> it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.getImageTypes(TIFFImageReader.java:1359) >> at >> org.geotools.coverage.grid.io.AbstractGridCoverage2DReader.setLayout(AbstractGridCoverage2DReader.java:1167) >> at org.geotools.gce.geotiff.GeoTiffReader.getHRInfo(GeoTiffReader.java:342)* >> And, using gdal i get: >> >> *Warning 1: TIFFReadDirectory:Sum of Photometric type-related color >> channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color >> channels as ExtraSamples.* >> GDAL handle it putting this band (should bhe the 4th band, alpha channel) >> as ExtraSamples. >> How can I walk-around with GeoTools to read the image back? Are there any >> HINTS that i could use? >> >> Thanks >> >> _______________________________________________ >> GeoTools-Devel mailing list >> GeoTools-Devel@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/geotools-devel >> > > > -- > Regards, > Daniele Romagnoli > == > GeoServer Professional Services from the experts! Visit > http://goo.gl/it488V for more information. > == > > Ing. Daniele Romagnoli > Senior Software Engineer > > GeoSolutions S.A.S. > Via di Montramito 3/A > 55054 Massarosa (LU) > Italy > phone: +39 0584 962313 > fax: +39 0584 1660272 > > http://www.geo-solutions.it > http://twitter.com/geosolutions_it > > ------------------------------------------------------- > > Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE > 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si > precisa che ogni circostanza inerente alla presente email (il suo > contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è > riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il > messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra > operazione è illecita. Le sarei comunque grato se potesse darmene notizia. > > This email is intended only for the person or entity to which it is > addressed and may contain information that is privileged, confidential or > otherwise protected from disclosure. We remind that - as provided by > European Regulation 2016/679 “GDPR” - copying, dissemination or use of this > e-mail or the information herein by anyone other than the intended > recipient is prohibited. If you have received this email by mistake, please > notify us immediately by telephone or e-mail. >
_______________________________________________ GeoTools-Devel mailing list GeoTools-Devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-devel