Hello Simone,
Here is the sample code:
protected RenderedImage resampleImage(BufferedImage image,
com.vividsolutions.jts.geom.Envelope sourceEnvelope, String sourceCS, String
targetCS)throws FactoryException{
CoordinateReferenceSystem sourceCRS = CRS.decode(sourceCS);
CoordinateReferenceSystem targetCRS = CRS.decode(targetCS);
DirectPosition2D dpmax = new
DirectPosition2D(sourceCRS,sourceEnvelope.getMaxX(),sourceEnvelope.getMaxY())
;
DirectPosition2D dpmin = new
DirectPosition2D(sourceCRS,sourceEnvelope.getMinX(),sourceEnvelope.getMinY())
;
org.opengis.geometry.Envelope imageEnvelope = new
Envelope2D(dpmin,dpmax);
GridCoverage2D coverage = new GridCoverageFactory().create("My
coverage", image, imageEnvelope);
coverage = (GridCoverage2D)Operations.DEFAULT.resample(coverage,
targetCRS);
return coverage.getRenderedImage();
}
com.vividsolutions.jts.geom.Envelope wgs84Envelope = ...
BufferedImage bi = null;
bi = new BufferedImage(500,500,BufferedImage.TYPE_INT_BGR);
bi.getGraphics().setColor(java.awt.Color.WHITE);
bi.getGraphics().fillRect(0, 0, 500, 500);
// Painting some other BufferedImages PNG or JPEGS on the Canvas of by using
the bi.getGraphics().drawImage(Image,..) Method
RenderedImage resampled = this.resampleImage(bi , wgs84Envelope, "EPSG:4326",
"EPSG:32632");
bi.getGraphics().drawRenderedImage(resampled,
AffineTransform.getTranslateInstance(0,0)); ==> Exception occurs
or
JPEGEncodeParam jep = new JPEGEncodeParam();
jep.setQuality(1.0F);
jep.setWriteJFIFHeader(true);
try {
ImageEncoder ie = ImageCodec.createImageEncoder("JPEG", os, jep);
ie.encode(source); ==> Exception occurs
} catch (IOException e) {
log.error(e,e);
}
As you can see I haven't got any static Images that I can sent to you. I hope
the sourcecode may help to find the issue.
I am working on the trunk.
Thanks a lot
Tim
-----Ursprüngliche Nachricht-----
Von: Simone Giannecchini [mailto:[EMAIL PROTECTED]
Gesendet: Donnerstag, 23. August 2007 17:06
An: Tim Englich
Cc: Martin Desruisseaux; [email protected]
Betreff: Re: [Geotools-gt2-users] Image Transformation form one CRS to
an other
Please, provide a test image with same sample code to test the issue
and hopefully fix it :-)
Simone.
On 8/23/07, Tim Englich <[EMAIL PROTECTED]> wrote:
> Hello Martin
>
> thanks for your quick response.
>
> The Transformation works. But when I try to use the Image, which I can get
> with coverage.getRenderedImage(), e.g encoding the Image or draw it to an
> graphics like this (drawRenderedImage(RenderedImage,
> AffineTransform.getTranslateInstance(0,0));) I got the following
Exception:
>
> java.lang.NullPointerException
> at
>
com.sun.media.jai.iterator.RandomIterFallback.makeCurrent(RandomIterFallback.
> java:110)
> at
>
com.sun.media.jai.iterator.RandomIterFallback.getSample(RandomIterFallback.ja
> va:117)
> at
>
com.sun.media.jai.opimage.WarpNearestOpImage.computeRectInt(WarpNearestOpImag
> e.java:362)
> at
>
com.sun.media.jai.opimage.WarpNearestOpImage.computeRect(WarpNearestOpImage.j
> ava:108)
> at javax.media.jai.WarpOpImage.computeTile(WarpOpImage.java:577)
> at
>
com.sun.media.jai.util.SunTileScheduler.scheduleTile(SunTileScheduler.java:90
> 4)
> at javax.media.jai.OpImage.getTile(OpImage.java:1129)
> at javax.media.jai.RenderedOp.getTile(RenderedOp.java:2257)
> at
>
sun.java2d.SunGraphics2D.drawTranslatedRenderedImage(SunGraphics2D.java:2542)
> at
> sun.java2d.SunGraphics2D.drawRenderedImage(SunGraphics2D.java:2429)
> ...
>
> Do you have an idea how to solve this problem?
>
> Thanks a lot
> Tim
>
> -----Ursprüngliche Nachricht-----
> Von: Martin Desruisseaux [mailto:[EMAIL PROTECTED]
> Gesendet: Donnerstag, 23. August 2007 12:56
> An: Tim Englich
> Cc: [email protected]
> Betreff: Re: [Geotools-gt2-users] Image Transformation form one CRS to
> an other
>
>
> Tim Englich a écrit :
> >> I am looking for a possibility to transform an georefrenced image to an
> >> other coordinatereferencesystem.
> >> E.g. from EPSG:4326 to EPSG:32632
> >> Provide GeoTools such a functionality? Do anyone know a (Java)-library
> >> which can do that.
>
> CoordinateReference sourceCRS = CRS.decode("EPSG:4326");
> CoordinateReference targetCRS = CRS.decode("EPSG:32632");
> RenderedImage image = ...
> Envelope imageEnvelope = ...
> imageEnvelope.setCoordinateReferenceSystem(sourceCRS);
> GridCoverage2D coverage = coverageFactory.create("My coverage", image,
> envelope);
> coverage = Operations.DEFAULT.resample(coverage, targetCRS);
>
>
> Martin
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
--
-------------------------------------------------------
Eng. Simone Giannecchini
President /CEO GeoSolutions S.A.S.
Via Carignoni 51
55041 Camaiore (LU)
Italy
phone: +39 0584983027
fax: +39 0584983027
mob: +39 333 8128928
http://www.geo-solutions.it
-------------------------------------------------------
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users