Beispiel #1
0
        public FreeImage(Bitmap bitmap, ImageFormat imageFormat)
        {
            FreeImageFormat fif = ImageFormatToFIF(imageFormat);

            if (fif == FreeImageFormat.Unknown)
            {
                throw new Exception("Image format \"" + imageFormat.ToString() + "\" is not supported");
            }

            MemoryStream ms = new MemoryStream();

            bitmap.Save(ms, imageFormat);
            ms.Flush();

            byte[] buffer = new byte[((int)(ms.Length - 1)) + 1];
            ms.Position = 0;
            ms.Read(buffer, 0, (int)ms.Length);
            ms.Close();

            IntPtr dataPtr = Marshal.AllocHGlobal(buffer.Length);

            Marshal.Copy(buffer, 0, dataPtr, buffer.Length);

            m_MemPtr = FreeImageApi.OpenMemory(dataPtr, buffer.Length);
            m_Handle = FreeImageApi.LoadFromMemory(fif, m_MemPtr, 0);
        }
Beispiel #2
0
        internal override void Run(FreeImage image)
        {
            int hwnd = FreeImageApi.Rescale(image.GetFreeImageHwnd(), this.Width
                                            , this.Height, _Filter);

            image.DisposeAndSetHandle(hwnd);
        }
Beispiel #3
0
        public bool Save(string filename, FreeImageFormat type)
        {
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            FreeImageApi.SetPluginEnabled(type, true);

            return(FreeImageApi.Save(type, m_Handle, filename, 0));
        }
Beispiel #4
0
        public FreeImage(string filename)
        {
            FreeImageFormat fif = FreeImageApi.GetFIFFromFilename(filename);

            if (fif == FreeImageFormat.Unknown)
            {
                throw new Exception("Unknown file format");
            }

            m_Handle = FreeImageApi.Load(fif, filename, 0);
            m_MemPtr = IntPtr.Zero;
        }
Beispiel #5
0
        public byte[] ConvertToRaw()
        {
            IntPtr bits = IntPtr.Zero;

            bits = Marshal.AllocHGlobal(this.Height * this.Pitch);

            FreeImageApi.ConvertToRawBits(bits, m_Handle, this.Pitch, (uint)this.Bpp, (uint)0, (uint)0, (uint)0, false);
            byte[] bts = new byte[this.Height * this.Pitch];
            Marshal.Copy(bits, bts, 0, bts.Length);

            return(bts);
        }
Beispiel #6
0
        public bool Save(string filename)
        {
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            FreeImageFormat fif = FreeImageApi.GetFIFFromFilename(filename);

            FreeImageApi.SetPluginEnabled(fif, true);

            return(FreeImageApi.Save(fif, m_Handle, filename, 0));
        }
Beispiel #7
0
 public void Dispose()
 {
     if (!disposed)
     {
         FreeImageApi.Unload(m_Handle);
         if (m_MemPtr != IntPtr.Zero)
         {
             FreeImageApi.CloseMemory(m_MemPtr);
         }
     }
     disposed = true;
     //FreeImageApi.DeInitialize();
 }
Beispiel #8
0
 public void PaintToDevice(IntPtr destDC, int x, int y, int width, int height, int srcX, int srcY, int scan, int mumScans, int wUsage)
 {
     try
     {
         IntPtr ptrBits = FreeImageApi.GetBits(m_Handle);
         IntPtr ptrInfo = FreeImageApi.GetInfo(m_Handle);
         SetDIBitsToDevice(destDC, x, y, width, height, srcX, srcY, scan, mumScans, ptrBits, ptrInfo, wUsage);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #9
0
        public FreeImage Rotate(double angle)
        {
            int i = FreeImageApi.RotateClassic(m_Handle, angle);

            return(new FreeImage(i));
        }
Beispiel #10
0
 public bool Invert()
 {
     return(FreeImageApi.Invert(m_Handle));
 }
Beispiel #11
0
        /// <summary>
        /// Converts a bitmap to 1-bit monochrome bitmap using a threshold T between [0..255].
        /// The function first converts the bitmap to a 8-bit greyscale bitmap. Then, any brightness
        /// level that is less than T is set to zero, otherwise to 1. For 1-bit input bitmaps, the
        /// function clones the input bitmap and builds a monochrome palette.
        /// </summary>
        /// <param name="range"></param>
        /// <returns></returns>
        public FreeImage Threshold(byte range)
        {
            int i = FreeImageApi.Threshold(m_Handle, range);

            return(new FreeImage(i));
        }
 internal override void Run(FreeImage image)
 {
     _completed = FreeImageApi.AdjustBrightness(image.GetFreeImageHwnd(), _brightness);
 }
Beispiel #13
0
 internal override void Run(FreeImage image)
 {
     _completed = FreeImageApi.AdjustGamma(image.GetFreeImageHwnd(), _gamma);
 }
Beispiel #14
0
        internal void DisposeAndSetHandle(int hwnd)
        {
            FreeImageApi.Unload(m_Handle);

            m_Handle = hwnd;
        }
Beispiel #15
0
 static void CurrentDomain_DomainUnload(object sender, EventArgs e)
 {
     FreeImageApi.DeInitialise();
 }
Beispiel #16
0
 static FreeImage()
 {
     FreeImageApi.Initialise(false);
     AppDomain.CurrentDomain.DomainUnload += new EventHandler(CurrentDomain_DomainUnload);
 }
Beispiel #17
0
 public static string GetVersion()
 {
     return(FreeImageApi.GetVersion());
 }
Beispiel #18
0
 public static string GetCopyright()
 {
     return(FreeImageApi.GetCopyrightMessage());
 }
Beispiel #19
0
        public FreeImage Clone()
        {
            int clone = FreeImageApi.Clone(m_Handle);

            return(new FreeImage(clone));
        }
Beispiel #20
0
        public FreeImage RotateExtended(double angle, double xShift, double yShift, double xOrigin, double yOrigin, bool mask)
        {
            int i = FreeImageApi.RotateEx(m_Handle, angle, xShift, yShift, xOrigin, yOrigin, mask);

            return(new FreeImage(i));
        }
Beispiel #21
0
        internal override void Run(FreeImage image)
        {
            int dib = FreeImageApi.ConvertTo32Bits(image.GetFreeImageHwnd());

            image.DisposeAndSetHandle(dib);
        }
Beispiel #22
0
        public FreeImage Rescale(int width, int height)
        {
            int newHandle = FreeImageApi.Rescale(m_Handle, width, height, FreeImageFilter.BICUBIC);

            return(new FreeImage(newHandle));
        }
Beispiel #23
0
 internal override void Run(FreeImage image)
 {
     _completed = FreeImageApi.AdjustContrast(image.GetFreeImageHwnd(), _constrast);
 }
Beispiel #24
0
 public bool FlipVertical()
 {
     return(FreeImageApi.FlipVertical(m_Handle));
 }
Beispiel #25
0
 public bool FlipHorizontal()
 {
     return(FreeImageApi.FlipHorizontal(m_Handle));
 }
Beispiel #26
0
 public FreeImage(byte[] bts, int width, int height, int pitch, uint bpp, uint redMask,
                  uint greenMask, uint blueMask, bool topDown)
 {
     m_Handle = FreeImageApi.ConvertFromRawBits(bts, width, height,
                                                pitch, bpp, redMask, greenMask, blueMask, topDown);
 }