Select to view content in your preferred language

ArcEngine import tiff wrong colours

2982
5
03-17-2016 07:29 AM
PaulCole
Deactivated User

Using Arc Engine, I have produce a map handling product for our clients. It takes their low level mapping and produces bit maps at diffferent scales though an automatic procedure.

The software produces Geo Tiff files. I have checked these files and they are correct, but when I do an automatic import of the bit maps, some of the files have their colours changed.

There isn't any rendering on those files, as they are on their own separate layer files. If I clear the map down, and run the import again, different bitmaps have their colours wrong.

I am using the following code to import the tiff file

private ILayer AddBitmap(string mapDirectory,string imageDirectory, string sFile, object minimum, object maximum, IGroupLayer groupLayer)

        {

            IRasterLayer prlyr = null;

            try

            {

                WriteLog("loading " + sFile);

                string layerName = System.IO.Path.GetFileNameWithoutExtension(sFile);

                string lName = imageDirectory + @"\" + layerName + ".lyr";

                if (mapDoc != null)

                {

                    int c = mapDoc.get_Map(0).LayerCount;

                    for (int i = 0; i < c; i++)

                    {

                        ILayer layer = mapDoc.get_Map(0).get_Layer(i);

                        if (layer.Name == sFile)

                            return null;

                    }

                }

                IWorkspaceFactory pWsFact;

                IRasterWorkspace pWs;

                IRasterDataset pRasterDataset;

                //Open the workspace

                pWsFact = new RasterWorkspaceFactoryClass();

                pWs = pWsFact.OpenFromFile(imageDirectory, 0) as IRasterWorkspace;

                //Open the raster dataset

                pRasterDataset = pWs.OpenRasterDataset(sFile);

                //Open the raster layer

                prlyr = new RasterLayerClass();

                prlyr.CreateFromDataset(pRasterDataset);

            

                ILayerFile layerFile = new LayerFileClass();

                layerFile.New(mapDirectory + @"\" + layerName + ".lyr");

                layerFile.ReplaceContents(prlyr);

                layerFile.Save();

                int index = axMapControl1.LayerCount;

                if (groupLayer == null)

                {

                    axMapControl1.AddLayer((ILayer)prlyr, index);

                    if (mapDoc != null)

                    {

                        mapDoc.get_Map(0).AddLayer((ILayer)prlyr);

                    }

                }

                else

                {

                    groupLayer.Add(prlyr as ILayer);

                }

               

                //Thread.Sleep(2000);

                 if (maximum != null)

                {

                    ((ILayer)prlyr).MaximumScale = Convert.ToDouble(maximum);

                }

                if (minimum != null)

                {

                    ((ILayer)prlyr).MinimumScale = Convert.ToDouble(minimum);

                }

              

            }

            catch (Exception ex)

            {

                WriteLog("error of " + ex);

                MessageBox.Show("Error\n" + ex.Message);

            }

            return prlyr;

        }

0 Kudos
5 Replies
PaulCole
Deactivated User

I have now tried it with PNG bitmaps, and I am getting the same results. When I do an identify on the bit map, it says the rgb values re 128,128,128 which is what they are suppose to be at that point, but the colour being displayed is a bright green.

This has to be issue with Arc Engine somewhere, either something not being set up or some other issue.

Can someone please help with this situation. I can supply a copy of the bitmaps in question.

0 Kudos
ModyBuchbinder
Esri Regular Contributor

Hi

Check the stretch on the lyr file.

It might change the colors

0 Kudos
PaulCole
Deactivated User

Thanks for the suggestion, I will check it out, but I am not changing the default strech value, I have also noticed that when I do an add raster image from the open menu, it also does the same thing, this is a layer that has been created by ArcEngine through the esri add data function.

0 Kudos
PaulCole
Deactivated User

Can you please tell me where the stretch information is stored, as the only stretch I can find is under the RasterRGBRenderer which I am not using.

0 Kudos
ModyBuchbinder
Esri Regular Contributor

I see it in ArcMap in the layer properties in symbolgy tab.

Not sure how to do it in code. Maybe get IRasterStretch from the renderer.

0 Kudos