ThinkGeo.com    |     Documentation    |     Premium Support

Transparency on raster layers

At my request, you added the KeyColors property to the raster layer.    I haven't really had a chance to test it, but am now having trouble.   We have some imagery with black edges, and setting the KeyColor to black makes the black transparent.    However, we have some imagery with white edges, and setting the KeyColor to white does not make the white transparent.    Does white not work?   Or is this an issue with the imagery source.    In both cases, the imagery is Jpeg2000, but from two different sources.


To use the KeyColors collection, I just load it with colors that are to be transparent, right?


I can upload a coupe of overlapping 90kb images, if that will help.


Thanks!



Ted, 
  
   Send the images in to Support and have them forwarded to Yale and David.  One thing is to make 100% sure white is white.  I would take it under a program where you can test the pixel to determine the ARBG value exactly.  I don’t think the imagery source would matter except that they may use an off white or maybe the Alpha value is not exactly what we expected.  Any slight variance and it throws the matrix calculation off. 
  
 David

David… I have done some more testing.    On my original image with a pseudo black color, KeyColor of black removes most of the black.   I created a function to load up KeyColors with all permutations and combinations values 0-2 for RGB (27 combinations) and more got removed.   All permutations and combinations of 0-4 for R, G, and B removed practially all of it.   So clearly the KeyColors option works.    I did notice an increase in drawing time as I increased the number of transparent colors.   I’m guessing you iterate the bitmap to accomplish this function? 
  
 This does not work on the white collar at all.    My first thought earlier was that maybe white wasn’t white.   However, I created all permutations and combinations of values 255-246 on R, G, and B… and it made no difference.   Obviously, it is a different image.     It is a 24-bit, 3-plane image, so I didn’t think Alpha comes into play.     Do you know of a tool that I can use to check the value of a specific pixel in a JPeg2000 image?    I’ll be glad to do that before I bug your support people. 
  


Ted,


We also did some tests, and it seems it works fine even for White color(we only tested the 32 bit image).
 
Attachment contains the while color which is non-transparent, when we set the KeyColor(or KeyColors), then the hidden world map can be seen.

   if (!File.Exists("../../white.gif"))
            {
                Bitmap bitmap = new Bitmap(winformsMap1.Width, winformsMap1.Height);

                Graphics graphic = Graphics.FromImage(bitmap);
                graphic.Clear(Color.White);

                bitmap.Save("../../white.gif");
            }

            ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer("../../data/Countries02.shp");
            worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
            worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            worldLayer.Open();
            RectangleShape extent = worldLayer.GetBoundingBox();
            worldLayer.Close();

            GdiPlusRasterLayer rashLayer = new GdiPlusRasterLayer("../../white.gif", extent);
            //rashLayer.KeyColor = GeoColor.StandardColors.White;
            rashLayer.KeyColors.Add(GeoColor.StandardColors.White);
            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
            winformsMap1.CurrentExtent = extent;

            winformsMap1.StaticOverlay.Layers.Add(worldLayer);
            winformsMap1.StaticOverlay.Layers.Add(rashLayer);

            winformsMap1.Refresh();

 

Any more questions please feel free to let me know.
 
Thanks.
 
Yale


I have sent an e-mail to support with a download link to a couple of relatively small files.   Can you recommend a tool to find the pixel color of any location in a JP2, ECW, or SID image?

Ted, 
  
   We will check them out.  Here is a little, and I mean little, tool you can use.  I used it a few times and seemed to do the job. 
  
 nattyware.com/pixie.php 
  
 David

I have just encountered some black collar imagery that won’t be transparent.   I think the common theme is that the imagery that won’t go transparent is 24 bit… RGB.    I think the imagery that works is 32 bit, so there is an alpha plane available.  The transparency logic is probably setting the alpha channel to transparent. 
  
 I’m investigating further.

Ted, 
  
   Interesting.  I would image then maybe a good way would be to create a new bitmap in memory with an alpha channel and then suck in the image with the color.  Then we can apply the matrix operation to turn the white alpha.  I thought that is how it was but maybe not.  Keep digging though so we can have as much information possible to proceed.  On the various colors I wonder if there is a matrix operation that can do a color range in one fell swoop.  Hmm, we will continue to look. 
  
 David

Guys… I’m very sorry… this is my error.    Did you know that you could open a .jp2 file with the Jpeg2000Raster, the EcwRaster, and the SidRaster, all at the same time?   And if you only set the KeyColors on the Jpeg2000Raster, but draw all the layers in your collection, you get completely random presentatoin, depending upon what files you open, and in what order :( 
  
 I apologize for the time you have wasted on this. 
  


Ted, 
  
   No worries.  The reason they all open Jpeg2000 is that the ECW library actually processes Jpeg2000.  Since MrSid and Ecw both use C++ libraries we created a bridge dll in C++ that is half managed and half un-managed.  All of the raster calls go through there so that must be why it kind of worked.  The Jpeg2000RasterSource is actually inherited from EcwRasterSource and we just renamed it.  We wanted to do this as we thought people might find it better.  Anyway I am glad you have it working. 
  
 David