AnsweredAssumed Answered

ArcEngine import tiff wrong colours

Question asked by askltd on Mar 17, 2016
Latest reply on Mar 22, 2016 by modybsystematics-co-il-esridist

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;

        }

Outcomes