// This loads the image
        protected override LocalLoadResult LocalLoadImage()
        {
            // Load file data
            Bitmap       bitmap   = null;
            string       error    = null;
            MemoryStream filedata = datareader.LoadFile(filepathname);             //mxd

            isBadForLongTextureNames = false;

            if (filedata != null)
            {
                // Get a reader for the data
                bitmap = ImageDataFormat.TryLoadImage(filedata, probableformat, General.Map.Data.Palette);

                // Not loaded?
                if (bitmap == null)
                {
                    error = "Image file \"" + filepathname + "\" data format could not be read, while loading texture \"" + this.Name + "\"";
                }

                filedata.Dispose();
            }

            return(new LocalLoadResult(bitmap, error));
        }
Ejemplo n.º 2
0
        // This loads the image
        protected override void LocalLoadImage()
        {
            // Leave when already loaded
            if (this.IsImageLoaded)
            {
                return;
            }

            lock (this)
            {
                // Load file data
                if (bitmap != null)
                {
                    bitmap.Dispose();
                }
                bitmap = null;
                MemoryStream filedata = datareader.LoadFile(filepathname);                 //mxd

                if (filedata != null)
                {
                    // Get a reader for the data
                    IImageReader reader = ImageDataFormat.GetImageReader(filedata, probableformat, General.Map.Data.Palette);
                    if (!(reader is UnknownImageReader))
                    {
                        // Load the image
                        filedata.Seek(0, SeekOrigin.Begin);
                        try
                        {
                            bitmap = reader.ReadAsBitmap(filedata);
                        }
                        catch (InvalidDataException)
                        {
                            // Data cannot be read!
                            bitmap = null;
                        }
                    }

                    // Not loaded?
                    if (bitmap == null)
                    {
                        General.ErrorLogger.Add(ErrorType.Error, "Image file \"" + filepathname + "\" data format could not be read, while loading texture \"" + this.Name + "\"");
                        loadfailed = true;
                    }
                    else
                    {
                        // Get width and height from image
                        width  = bitmap.Size.Width;
                        height = bitmap.Size.Height;
                    }

                    filedata.Dispose();
                }

                // Pass on to base
                base.LocalLoadImage();
            }
        }
        // This loads the image
        protected override LocalLoadResult LocalLoadImage()
        {
            // Load file data
            Bitmap       bitmap   = null;
            string       error    = null;
            MemoryStream filedata = datareader.LoadFile(filepathname);             //mxd

            isBadForLongTextureNames = false;

            if (filedata != null)
            {
                // Get a reader for the data
                IImageReader reader = ImageDataFormat.GetImageReader(filedata, probableformat, General.Map.Data.Palette);
                if (!(reader is UnknownImageReader))
                {
                    // Load the image
                    filedata.Seek(0, SeekOrigin.Begin);
                    try
                    {
                        bitmap = reader.ReadAsBitmap(filedata);
                    }
                    catch (InvalidDataException)
                    {
                        // Data cannot be read!
                        bitmap = null;
                    }
                }

                // Not loaded?
                if (bitmap == null)
                {
                    error = "Image file \"" + filepathname + "\" data format could not be read, while loading texture \"" + this.Name + "\"";
                }

                filedata.Dispose();
            }

            return(new LocalLoadResult(bitmap, error));
        }