From: Gabriella T. <Gab...@ni...> - 2014-12-04 21:24:39
|
Thanx for the tip Andrea. That didn't work but this did, debugging I saw that what being returned was a RenderedOp RenderedOp ri = (RenderedOp)gc.getRenderedImage(); sourceBufferedImage = ri.getAsBufferedImage(); Now I figured that I could do the same for getting the BufferedImage for a tif image, but no, it does not. Even though the the instance returned is also a RenderedOp, I run into trouble when trying to render the image: Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -2147385344 at java.awt.image.ComponentColorModel.getRGBComponent(ComponentColorModel.java:903) at java.awt.image.ComponentColorModel.getRed(ComponentColorModel.java:944) at java.awt.image.ComponentColorModel.getRGB(ComponentColorModel.java:1135) at sun.java2d.loops.OpaqueCopyAnyToArgb.Blit(CustomComponent.java:145) at sun.java2d.loops.GraphicsPrimitive.convertFrom(GraphicsPrimitive.java:560) at sun.java2d.loops.GraphicsPrimitive.convertFrom(GraphicsPrimitive.java:541) at sun.java2d.loops.MaskBlit$General.MaskBlit(MaskBlit.java:189) at sun.java2d.loops.Blit$GeneralMaskBlit.Blit(Blit.java:204) at sun.java2d.pipe.DrawImage.blitSurfaceData(DrawImage.java:955) at sun.java2d.pipe.DrawImage.renderImageCopy(DrawImage.java:576) at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:86) at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:1026) at sun.java2d.pipe.ValidatePipe.copyImage(ValidatePipe.java:196) at sun.java2d.SunGraphics2D.copyImage(SunGraphics2D.java:3082) at sun.java2d.pipe.DrawImage.makeBufferedImage(DrawImage.java:332) at sun.java2d.pipe.DrawImage.renderImageXform(DrawImage.java:392) at sun.java2d.opengl.OGLDrawImage.renderImageXform(OGLDrawImage.java:89) at sun.java2d.pipe.DrawImage.transformImage(DrawImage.java:212) at sun.java2d.opengl.OGLDrawImage.transformImage(OGLDrawImage.java:100) at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:3340) at riskscape.map.internal.render.GridCoverageMapContent.draw(GridCoverageMapContent.java:48) Even though from exploring in debug both asc and tif both have a grayscale color model. I tried many ways of obtaining a BufferedImage for the tif and the only way that worked for me was this: ImageDecoder decoder = ImageCodec.createImageDecoder("tiff", file, null); RenderedImage ri = decoder.decodeAsRenderedImage(); PlanarImage pi = new NullOpImage(ri, new ImageLayout(ri), null, OpImage.OP_IO_BOUND); sourceBufferedImage = pi.getAsBufferedImage(); which bypasses reading the file into a grid coverage and sorts of defeats the purpose of what I am trying to do. Why does one work and not the other? Gaby ________________________________ From: and...@gm... <and...@gm...> on behalf of Andrea Aime <and...@ge...> Sent: Thursday, December 4, 2014 10:28 PM To: andrea antonello Cc: Gabriella Turek; geotools users Subject: Re: [Geotools-gt2-users] grid coverage to bufferedimage On Thu, Dec 4, 2014 at 7:36 AM, andrea antonello <and...@gm...<mailto:and...@gm...>> wrote: How can I go from a grid coverage obtained from an ASCII grid file to a buffered image ? RenderedImage renderedImage = coverage.getRenderedImage(); Not sure, but from memory (can't check right now), depending on the file type, this should be a BufferedImage. If you have tiles data in the back, I think you should also call getData, to make sure that everything is read into a single tile and put in the BufferedImage. A general approach would be: RenderedImage renderedImage = coverage.getRenderedImage(); PlanarImage.wrapRenderedImage(renderedImage).getAsBufferedImage(); Checking if the renderedImage is already an instance of buffered image would like help performance too. Cheers Andrea -- == GeoServer Professional Services from the experts! Visit http://goo.gl/NWWaa2 for more information. Please, notice that GeoSolutions will be closed for seasonal holidays from December the 24th to January the 6th == Ing. Andrea Aime @geowolf Technical Lead GeoSolutions S.A.S. Via Poggio alle Viti 1187 55054 Massarosa (LU) Italy phone: +39 0584 962313 fax: +39 0584 1660272 mob: +39 339 8844549 http://www.geo-solutions.it http://twitter.com/geosolutions_it AVVERTENZE AI SENSI DEL D.Lgs. 196/2003 Le informazioni contenute in questo messaggio di posta elettronica e/o nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il loro utilizzo ? consentito esclusivamente al destinatario del messaggio, per le finalit? indicate nel messaggio stesso. Qualora riceviate questo messaggio senza esserne il destinatario, Vi preghiamo cortesemente di darcene notizia via e-mail e di procedere alla distruzione del messaggio stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso, divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od utilizzarlo per finalit? diverse, costituisce comportamento contrario ai principi dettati dal D.Lgs. 196/2003. The information in this message and/or attachments, is intended solely for the attention and use of the named addressee(s) and may be confidential or proprietary in nature or covered by the provisions of privacy act (Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection Code).Any use not in accord with its purpose, any disclosure, reproduction, copying, distribution, or either dissemination, either whole or partial, is strictly forbidden except previous formal approval of the named addressee(s). If you are not the intended recipient, please contact immediately the sender by telephone, fax or e-mail and delete the information in this message that has been received in error. The sender does not give any warranty or accept liability as the content, accuracy or completeness of sent messages and accepts no responsibility for changes made after they were sent or for other risks which arise as a result of e-mail transmission, viruses, etc. ------------------------------------------------------- |