Beispiel #1
0
        private FreeImageBitmap CreateFreeImageViaDIB()
        {
            FreeImageBitmap fi;

            using (DllManager dllManager = new DllManager())
            {
                dllManager.LoadDll("FreeImage.DLL");
                Logger.Info("CreateFreeImageViaDIB: Copy to clipboard and get data from it");
                if (!CopySelection())
                {
                    return(null);
                }

                MemoryStream stream = Clipboard.GetData(System.Windows.DataFormats.Dib) as MemoryStream;
                using (DibBitmap dibBitmap = new DibBitmap(stream))
                {
                    Logger.Info("CreateFreeImageViaDIB: Create FreeImage bitmap");
                    fi = new FreeImageBitmap(dibBitmap.Bitmap);
                    bool convertType = fi.ConvertType(FREE_IMAGE_TYPE.FIT_BITMAP, true);
                    Logger.Debug("CreateFreeImageViaDIB: FreeImageBitmap.ConvertType returned {0}", convertType);
                    bool convertColorDepth = fi.ConvertColorDepth(FREE_IMAGE_COLOR_DEPTH.FICD_24_BPP); // won't work with 32 bpp!
                    Logger.Debug("CreateFreeImageViaDIB: FreeImageBitmap.ConvertColorDepth returned {0}", convertColorDepth);
                    fi.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);
                }
            }
            return(fi);
        }
Beispiel #2
0
        private FreeImageBitmap CreateFreeImageViaDIB()
        {
            if (!CopySelection())
            {
                return(null);
            }
            FreeImageBitmap fi;
            MemoryStream    stream = null;

            Bovender.WpfHelpers.MainDispatcher.Invoke((Action)(
                                                          () =>
            {
                Logger.Info("CreateFreeImageViaDIB: Copy to clipboard and get data from it");
                stream = Clipboard.GetData(System.Windows.DataFormats.Dib) as MemoryStream;
            })
                                                      );
            using (DibBitmap dibBitmap = new DibBitmap(stream))
            {
                Logger.Info("CreateFreeImageViaDIB: Create FreeImage bitmap");
                fi = new FreeImageBitmap(dibBitmap.Bitmap);
                bool convertType = fi.ConvertType(FREE_IMAGE_TYPE.FIT_BITMAP, true);
                Logger.Debug("CreateFreeImageViaDIB: FreeImageBitmap.ConvertType returned {0}", convertType);
                bool convertColorDepth = fi.ConvertColorDepth(FREE_IMAGE_COLOR_DEPTH.FICD_24_BPP); // won't work with 32 bpp!
                Logger.Debug("CreateFreeImageViaDIB: FreeImageBitmap.ConvertColorDepth returned {0}", convertColorDepth);
                fi.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);
            }
            stream.Dispose();
            return(fi);
        }
Beispiel #3
0
        private void ReplaceBitmap(FreeImageBitmap newBitmap)
        {
            // Checks whether the bitmap is usable
            if (newBitmap == null || newBitmap.IsDisposed)
            {
                MessageBox.Show("Unexpected error.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Check whether the image type of the new bitmap is 'FIT_BITMAP'.
            // If not convert to 'FIT_BITMAP'.
            if (newBitmap.ImageType != FREE_IMAGE_TYPE.FIT_BITMAP)
            {
                if (!newBitmap.ConvertType(FREE_IMAGE_TYPE.FIT_BITMAP, true))
                {
                    MessageBox.Show("Error converting bitmap to standard type.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            if ((bitmap != null) && !object.ReferenceEquals(bitmap, newBitmap))
            {
                bitmap.Dispose();
            }
            if (resultbmp != null)
            {
                resultbmp.Dispose();
            }
            bitmap    = newBitmap;
            resultbmp = (Bitmap)bitmap;
            UpdateBitmapInformations();
        }
Beispiel #4
0
        /// <summary>
        /// Load a FreeImage bitmap specifying different flags according to the file extension
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private FreeImageBitmap LoadBitmap(string fileName)
        {
            FREE_IMAGE_LOAD_FLAGS flags = FREE_IMAGE_LOAD_FLAGS.DEFAULT;

            // Rotate Jpegs if possible
            if (fileName.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith("jpeg", StringComparison.OrdinalIgnoreCase))
            {
                flags = FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE | FREE_IMAGE_LOAD_FLAGS.JPEG_EXIFROTATE;
            }

            // Load the image from disk
            try
            {
                var bmp = new FreeImageBitmap(fileName, flags);

                // Convert the image to bitmap
                if (bmp.ImageType != FREE_IMAGE_TYPE.FIT_BITMAP)
                {
                    bmp.ConvertType(FREE_IMAGE_TYPE.FIT_BITMAP, true);
                }

                return(bmp);
            }
            catch
            {
                throw;
//                return null;
            }
        }
        public void SetImage(byte[] data, string filePath)
        {
            button3.Enabled     = false;
            button3.MouseHover += Button3MouseHover;
            button2.Enabled     = false;
            button2.MouseHover += Button2MouseHover;
            button1.MouseHover += Button1MouseHover;
            button1.Enabled     = filePath.EndsWith(".dds");

            try {
                var ending = Path.GetExtension(filePath);
                FREE_IMAGE_FORMAT format;
                switch (ending)
                {
                case ".tga":
                    format = FREE_IMAGE_FORMAT.FIF_TARGA;
                    break;

                case ".dds":
                    format = FREE_IMAGE_FORMAT.FIF_DDS;
                    break;

                case ".png":
                    format = FREE_IMAGE_FORMAT.FIF_PNG;
                    break;

                case ".jpg":
                    format = FREE_IMAGE_FORMAT.FIF_JPEG;
                    break;

                case ".bmp":
                    format = FREE_IMAGE_FORMAT.FIF_BMP;
                    break;

                case ".psd":
                    format = FREE_IMAGE_FORMAT.FIF_PSD;
                    break;

                default:
                    format = FREE_IMAGE_FORMAT.FIF_BMP;
                    break;
                }

                FreeImageBitmap bitmap;
                using (MemoryStream stream = new MemoryStream(data)) {
                    bitmap = new FreeImageBitmap(stream, format);
                }
                bitmap.ConvertType(FREE_IMAGE_TYPE.FIT_BITMAP, true);
                if (pictureBox1.Image != null)
                {
                    pictureBox1.Image.Dispose();
                }
                pictureBox1.Image = (Bitmap)bitmap;
            } catch (Exception e) {
                MessageBox.Show(string.Format("Error opening image file. \r\n FreeImage error : {0}", e.Message),
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #6
0
 public Bitmap Decode(Stream stream)
 {
     try {
         FreeImageBitmap bitmap = new FreeImageBitmap(stream, format);
         bitmap.ConvertType(FREE_IMAGE_TYPE.FIT_BITMAP, true);
         return((Bitmap)bitmap);
     } catch (Exception e) {
         Console.WriteLine(e);
     }
     return(null);
 }
Beispiel #7
0
        // Replaces the current bitmap with the given one.
        private void ReplaceBitmap(FreeImageBitmap newBitmap)
        {
            // Checks whether the bitmap is usable
            if (newBitmap == null || newBitmap.IsDisposed)
            {
                MessageBox.Show(
                    "Unexpected error.",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }

            // Check whether the image type of the new bitmap is 'FIT_BITMAP'.
            // If not convert to 'FIT_BITMAP'.
            if (newBitmap.ImageType != FREE_IMAGE_TYPE.FIT_BITMAP)
            {
                if (!newBitmap.ConvertType(FREE_IMAGE_TYPE.FIT_BITMAP, true))
                {
                    MessageBox.Show(
                        "Error converting bitmap to standard type.",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    return;
                }
            }

            // Dispose the old bitmap only in case it exists and
            // the old instance is another than the new one.
            if ((bitmap != null) && !object.ReferenceEquals(bitmap, newBitmap))
            {
                bitmap.Dispose();
            }
            // Dispose the picturebox's bitmap in case it exists.
            if (pictureBox.Image != null)
            {
                pictureBox.Image.Dispose();
            }

            // Set the new bitmap.
            pictureBox.Image = (Bitmap)(bitmap = newBitmap);

            // Update gui.
            UpdateBitmapInformations();
            UpdateFrameSelection();
        }
 public Bitmap Decode(Stream stream)
 {
     try
     {
         FreeImageBitmap bitmap = new FreeImageBitmap(stream, format);
         bitmap.ConvertType(FREE_IMAGE_TYPE.FIT_BITMAP, true);
         return((Bitmap)bitmap);
     }
     catch (DllNotFoundException)
     {
         MessageBox.Show("Unable to located the FreeImageBitmap dll. Please install it.", "Dll load error");
     }
     catch (BadImageFormatException)
     {
         MessageBox.Show("Unable to located the FreeImageBitmap dll. Probably 32v64 bit mixup", "Dll load error");
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
     return(null);
 }
Beispiel #9
0
        // Replaces the current bitmap with the given one.
        private void ReplaceBitmap(FreeImageBitmap newBitmap)
        {
            // Checks whether the bitmap is usable
            if (newBitmap == null || newBitmap.IsDisposed)
            {
                MessageBox.Show(
                    "Nispodziewany błąd.",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }

            // Check whether the image type of the new bitmap is 'FIT_BITMAP'.
            // If not convert to 'FIT_BITMAP'.
            if (newBitmap.ImageType != FREE_IMAGE_TYPE.FIT_BITMAP)
            {
                if (!newBitmap.ConvertType(FREE_IMAGE_TYPE.FIT_BITMAP, true))
                {
                    MessageBox.Show(
                        "Błąd konwersji bitmapy do standardowego typu.",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    return;
                }
            }

            // Dispose the old bitmap only in case it exists and
            // the old instance is another than the new one.
            if ((bitmap != null) && !object.ReferenceEquals(bitmap, newBitmap))
            {
                bitmap.Dispose();
            }

            if ((smallbitmap != null) && !object.ReferenceEquals(smallbitmap, bitmap))
            {
                smallbitmap.Dispose();
            }

            bitmap = newBitmap;
            smallbitmap = bitmap;
            smallbitmap.Rescale(mForm.smallbitmap.Width, mForm.smallbitmap.Height, FREE_IMAGE_FILTER.FILTER_BICUBIC);

            UpdateBitmapInformations();
        }
Beispiel #10
0
        // Replaces the current bitmap with the given one.
        private void ReplaceBitmap(FreeImageBitmap newBitmap)
        {
            // Checks whether the bitmap is usable
            if (newBitmap == null || newBitmap.IsDisposed)
            {
                MessageBox.Show(
                    "Unexpected error.",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }

            // Check whether the image type of the new bitmap is 'FIT_BITMAP'.
            // If not convert to 'FIT_BITMAP'.
            if (newBitmap.ImageType != FREE_IMAGE_TYPE.FIT_BITMAP)
            {
                if (!newBitmap.ConvertType(FREE_IMAGE_TYPE.FIT_BITMAP, true))
                {
                    MessageBox.Show(
                        "Error converting bitmap to standard type.",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    return;
                }
            }

            // Dispose the old bitmap only in case it exists and
            // the old instance is another than the new one.
            if ((bitmap != null) && !object.ReferenceEquals(bitmap, newBitmap))
            {
                bitmap.Dispose();
            }
            // Dispose the picturebox's bitmap in case it exists.
            if (pictureBox.Image != null)
            {
                pictureBox.Image.Dispose();
            }

            // Set the new bitmap.
            pictureBox.Image = bitmap = newBitmap;

            // Update gui.
            UpdateBitmapInformations();
            UpdateFrameSelection();
        }