​Hi Anna,

I had to cope with the same issue.
I turned the background to transparent with the
``ImageUtilities#maskColor()" function
(--> ImageWorker).
It is not API, but still I am relying on it for now:

======================================================================
    import org.geotools.resources.image.ImageUtilities;
    ...

    GridCoverage2D coverage = [...]
    Color BLACK = SWTResourceManager.getColor(0x00, 0x00, 0x00);
    double[] BG_RGB = new double[] {
        BLACK.getRed(),
        BLACK.getGreen(),
        BLACK.getBlue()
    };

    RenderedImage renderedImage = ImageUtilities.maskColor(BLACK,
coverage.getRenderedImage());
    GridSampleDimension[] bands = GeoToolsUtils.setTransparency(sourceCov,
BLACK_RGB);
    GridCoverage2D trCoverage = GRIDCOV_FACTORY.create(
        coverage.getName().toString(),
        renderedImage, targetBbox, bands, null, null);
======================================================================


This GeoToolsUtils#setTransparency() prepends an alpha band to the existing
RGB dimensions:
you need to match the rendered image color model with the range type of
your coverage:

​======================================================================
   import org.geotools.coverage.Category
   ...
   public static GridSampleDimension[] setTransparency(GridCoverage2D
gridCov) {

       final int N_BANDS = gridCov.getNumSampleDimensions();
       final GridSampleDimension[] bandsWithAlpha = new
GridSampleDimension[N_BANDS + 1];

       // A
       bandsWithAlpha[0] = new GridSampleDimension("alpha", new Category[]
{ Category.NODATA }, 1, 0);

       // RGB
       for (int i = 0; i < N_BANDS; ++i) {
           final List<Category> categories = new ArrayList<>();
           categories.add(new Category("band", bandColors,
NumberRange.create(0, 255)));
           bandsWithAlpha[i + 1] = new GridSampleDimension(

gridCov.getSampleDimension(0).getDescription().toString(),
                   categories.toArray(new Category[0]), 1, 0);
       }

       return bandsWithAlpha;
   }
======================================================================


hth,
-Piero



On 19 December 2016 at 11:54, <
geotools-gt2-users-requ...@lists.sourceforge.net> wrote:
>
> Message: 2
> Date: Mon, 19 Dec 2016 11:54:20 +0100
> From: Anna Amat <anna.amat...@gmail.com>
> Subject: [Geotools-gt2-users] rotating raster
> To: geotools-gt2-users <geotools-gt2-users@lists.sourceforge.net>
> Message-ID:
>         <
ca+czrevvaxbb8fg1b1mg+3xp_uwuq6cusepwguwg6symavd...@mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hi list,
>
>
> I have reporoduced the ImageLab example but I have rotated the image by
> changing the world file. When displaying the image I get a black border
> where the envelope has no data (see attached file).
> Is there a way to turn it to transparent?
>
>
> Thanks in advance,
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to