Exemplo n.º 1
0
        /// <summary>
        /// Retrieve the image dimensions.
        /// </summary>
        public ImageProperties Properties()
        {
            var result = new ImageProperties();

            Emg.PropertiesHDR(this.Pointer, out result.width, out result.height, out result.depth);

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieve the image from unmanaged memory into a Bitmap instance.
        /// </summary>
        public Bitmap Get()
        {
            var properties = this.Properties();
            var result     = new Bitmap(properties.width, properties.height, properties.depth == 3 ? PixelFormat.Format48bppRgb : PixelFormat.Format16bppGrayScale);
            var data       = result.LockBits(new Rectangle(0, 0, properties.width, properties.height), ImageLockMode.ReadWrite, result.PixelFormat);

            Emg.GetHDR(this.Pointer, data.Scan0, data.Stride, true);

            result.UnlockBits(data);

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Set the image in unmanaged memory from the supplied Bitmap.
        /// </summary>
        public bool Set(Bitmap image)
        {
            if (image.PixelFormat == PixelFormat.Format48bppRgb || image.PixelFormat == PixelFormat.Format16bppGrayScale)
            {
                var data = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadWrite, image.PixelFormat);

                Emg.SetHDR(this.Pointer, data.Scan0, image.Width, image.Height, image.PixelFormat == PixelFormat.Format48bppRgb ? 3 : 1, data.Stride, true);

                image.UnlockBits(data);

                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Retrieve the image from unmanaged memory into a Bitmap instance.
        /// </summary>
        public Bitmap Get()
        {
            var properties = this.Properties();
            var result     = new Bitmap(properties.width, properties.height, properties.depth == 3 ? PixelFormat.Format24bppRgb : PixelFormat.Format8bppIndexed);
            var data       = result.LockBits(new Rectangle(0, 0, properties.width, properties.height), ImageLockMode.ReadWrite, result.PixelFormat);

            Emg.Get(this.Pointer, data.Scan0, data.Stride, true);

            result.UnlockBits(data);

            if (properties.depth == 1)
            {
                var palette = result.Palette;

                for (int i = 0; i < 256; i++)
                {
                    palette.Entries[i] = Color.FromArgb(i, i, i);
                }

                result.Palette = palette;
            }

            return(result);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Save image to the given path (filetype is based upon extension used).
 /// If raw is set to true then the filetype is ignored and the data saved out in a custom raw format.
 /// </summary>
 public bool Save(string path, bool raw = false)
 {
     return(Emg.Save(this.Pointer, path, raw) == (int)ReturnCodes.Ok);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Releases all resource used by the <see cref="libpsinc.Image"/> object.
 /// </summary>
 /// <remarks>Call <see cref="Dispose"/> when you are finished using the <see cref="libpsinc.Image"/>. The <see cref="Dispose"/>
 /// method leaves the <see cref="libpsinc.Image"/> in an unusable state. After calling <see cref="Dispose"/>, you must
 /// release all references to the <see cref="libpsinc.Image"/> so the garbage collector can reclaim the memory that
 /// the <see cref="libpsinc.Image"/> was occupying.</remarks>
 public void Dispose()
 {
     Emg.Delete(this.Pointer);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="libpsinc.Image"/> class.
 /// </summary>
 /// <param name="colour">
 /// If set to <c>true</c> a 24-bit colour image will be allocated.
 /// If <c>false</c> an 8-bit greyscale image will be allocated.
 /// </param>
 public Image(bool colour = false)
 {
     this.Pointer = Emg.Create(colour);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Load an image from the given path.
 /// If raw is set to true then the file data is assumed to be of a custom raw format.
 /// </summary>
 public bool Load(string path, bool raw = false)
 {
     return(Emg.LoadHDR(this.Pointer, path, raw) == (int)ReturnCodes.Ok);
 }