Exemplo n.º 1
0
        public GD(FileType type, string filename)
        {
            IntPtr imageHandle;
            IntPtr fileHandle = GDImport.fopen(filename, "rb");

            if (fileHandle == IntPtr.Zero)
            {
                throw new ApplicationException(filename + " not found.");
            }

            switch (type)
            {
            case FileType.Jpeg:
                imageHandle = GDImport.gdImageCreateFromJpeg(fileHandle);
                break;

            case FileType.Png:
                imageHandle = GDImport.gdImageCreateFromPng(fileHandle);
                break;

            case FileType.Gd:
                imageHandle = GDImport.gdImageCreateFromGd(fileHandle);
                break;

            case FileType.Gd2:
                imageHandle = GDImport.gdImageCreateFromGd2(fileHandle);
                break;

            case FileType.WBMP:
                imageHandle = GDImport.gdImageCreateFromWBMP(fileHandle);
                break;

            case FileType.Xbm:
                imageHandle = GDImport.gdImageCreateFromXbm(fileHandle);
                break;

            case FileType.Xpm:
                imageHandle = GDImport.gdImageCreateFromXpm(fileHandle);
                break;

            case FileType.Gif:
                imageHandle = GDImport.gdImageCreateFromGif(fileHandle);
                break;

            default:
                GDImport.fclose(fileHandle);
                throw new ApplicationException(type + " is unknown import type.");
            }

            GDImport.fclose(fileHandle);

            if (imageHandle == IntPtr.Zero)
            {
                throw new ApplicationException("ImageCreateFrom failed.");
            }

            this.handle = new HandleRef(this, imageHandle);

            //this.imageData = (GDImage) Marshal.PtrToStructure( this.Handle, typeof( GDImage ) );
        }
Exemplo n.º 2
0
 public void Free()
 {
     if (!IsNull)
     {
         GDImport.gdFree(mPtr);
         mPtr = IntPtr.Zero;
     }
 }
Exemplo n.º 3
0
 protected virtual void Dispose(bool managed)
 {
     if (!this.disposed)
     {
         GDImport.gdImageDestroy(this.Handle);
         this.disposed = true;
     }
 }
Exemplo n.º 4
0
        // Parameter:
        // PNG - level of compression ( 0 - no compression ... )
        // Jpeg - quality
        public bool Save(FileType type, string filename, int parameter)
        {
            IntPtr fileHandle = GDImport.fopen(filename, "wb");

            if (fileHandle == IntPtr.Zero)
            {
                return(false);
            }

            switch (type)
            {
            case FileType.Jpeg:
                GDImport.gdImageJpeg(this.Handle, fileHandle, parameter);
                break;

            case FileType.Png:
                GDImport.gdImagePngEx(this.Handle, fileHandle, parameter);
                break;

            case FileType.Gd:
                GDImport.gdImageGd(this.Handle, fileHandle);
                break;

            case FileType.Gd2:
                GDImport.gdImageGd2(this.Handle, fileHandle);
                break;

            case FileType.WBMP:
                GDImport.gdImageWBMP(this.Handle, parameter, fileHandle);
                break;

            case FileType.Gif:
                GDImport.gdImageGif(this.Handle, fileHandle);
                break;

            case FileType.Xbm:
            //gdImageXbm( this.Handle, fileHandle );
            //break;
            case FileType.Xpm:
                //gdImageXpm( this.Handle, fileHandle );
                //break;
                throw new ApplicationException(type + " not implemented.");

            default:
                GDImport.fclose(fileHandle);
                throw new ApplicationException(type + " is an unknown file type.");
            }

            GDImport.fclose(fileHandle);

            return(true);
        }
Exemplo n.º 5
0
        public string StringFT(ArrayList list, int fg, string fontname, double ptsize, double angle, int x, int y, string message, bool draw)
        {
            int[] brect = new int[8];

            string result = GDImport.gdImageStringFT(draw? this.Handle: IntPtr.Zero, brect, fg, fontname, ptsize, angle, x, y, message);

            list.Clear();
            list.Add(new Point(brect[0], brect[1]));
            list.Add(new Point(brect[2], brect[3]));
            list.Add(new Point(brect[4], brect[5]));
            list.Add(new Point(brect[6], brect[7]));

            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sout"></param>
        /// <param name="globalCm"></param>
        /// <param name="loops">Netscape 2/0 extension for animation loop count. 0 - infinite, -1 for not used. -1 is default</param>
        public void GifAnimBegin(Stream sout, bool globalCm, int loops)
        {
            int size;

            using (GDIntPtr rawdata = GDImport.gdImageGifAnimBeginPtr(this.Handle, out size, BoolToInt(globalCm), loops))
            {
                if (rawdata.IsNull)
                {
                    throw new ApplicationException("Function GifAnimBegin failed");
                }
                byte[] data = new byte[size];
                Marshal.Copy(rawdata, data, 0, size);
                sout.Write(data, 0, size);
            }
        }
Exemplo n.º 7
0
        public void GifAnimAdd(Stream sout, int localCm, int leftOfs, int topOfs, int delay, Disposal disposal, GD previm)
        {
            int    size;
            IntPtr prevhandle = previm == null ? IntPtr.Zero : previm.handle.Handle;

            using (GDIntPtr rawdata = GDImport.gdImageGifAnimAddPtr(this.Handle, out size, localCm, leftOfs, topOfs, delay, (int)disposal, prevhandle))
            {
                if (rawdata.IsNull)
                {
                    throw new ApplicationException("Function GifAnimAdd failed");
                }
                byte[] data = new byte[size];
                Marshal.Copy(rawdata, data, 0, size);
                sout.Write(data, 0, size);
            }
        }
Exemplo n.º 8
0
        public void Resize(int destW, int destH)
        {
            CheckDisposed();

            //TODO: resize img and replace this.handle with new img
            IntPtr imageHandle;

            imageHandle = GDImport.gdImageCreateTrueColor(destW, destH);
            if (imageHandle == IntPtr.Zero)
            {
                throw new ApplicationException("ImageCreatefailed.");
            }

            GDImport.gdImageCopyResampled(
                imageHandle, this.Handle,
                0, 0, 0, 0,
                destW, destH, this.Width, this.Height);

            GDImport.gdImageDestroy(this.Handle);
            this.handle = new HandleRef(this, imageHandle);
        }
Exemplo n.º 9
0
        /***********************************************************************************\
        *  GD Creation/Destruction/Loading/Saving
        \***********************************************************************************/

        public GD(int width, int height, bool trueColor)
        {
            IntPtr imageHandle;

            if (trueColor)
            {
                imageHandle = GDImport.gdImageCreateTrueColor(width, height);
            }
            else
            {
                imageHandle = GDImport.gdImageCreate(width, height);
            }

            if (imageHandle == IntPtr.Zero)
            {
                throw new ApplicationException("ImageCreate failed.");
            }

            this.handle = new HandleRef(this, imageHandle);

            //this.imageData = (GDImage) Marshal.PtrToStructure( this.Handle, typeof( GDImage ) );
        }
Exemplo n.º 10
0
        public Font(Type font)
        {
            IntPtr fontHandle;

            switch (font)
            {
            case Type.Small:
                fontHandle = GDImport.gdFontGetSmall();
                break;

            case Type.Large:
                fontHandle = GDImport.gdFontGetLarge();
                break;

            case Type.MediumBold:
                fontHandle = GDImport.gdFontGetMediumBold();
                break;

            case Type.Giant:
                fontHandle = GDImport.gdFontGetGiant();
                break;

            case Type.Tiny:
                fontHandle = GDImport.gdFontGetTiny();
                break;

            default:
                throw new ApplicationException(font + " is no valid font.");
            }

            if (fontHandle == IntPtr.Zero)
            {
                throw new ApplicationException("The font retrieval failed.");
            }

            this.handle = new HandleRef(this, fontHandle);
        }
Exemplo n.º 11
0
 public void Sharpen(int pct)
 {
     GDImport.gdImageSharpen(this.Handle, pct);
 }
Exemplo n.º 12
0
 public void PaletteCopy(GD src)
 {
     GDImport.gdImagePaletteCopy(this.Handle, src.GetHandle().Handle);
 }
Exemplo n.º 13
0
 public void SquareToCircle(int radius)
 {
     GDImport.gdImageSquareToCircle(this.Handle, radius);
 }
Exemplo n.º 14
0
 public void CopyRotated(GD src, double dstX, double dstY, int srcX, int srcY, int srcW, int srcH, int angle)
 {
     GDImport.gdImageCopyRotated(this.Handle, src.GetHandle().Handle, dstX, dstY, srcX, srcY, srcW, srcH, angle);
 }
Exemplo n.º 15
0
 public void CopyMerge(GD src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct)
 {
     GDImport.gdImageCopyMerge(this.Handle, src.GetHandle().Handle, dstX, dstY, srcX, srcY, w, h, pct);
 }
Exemplo n.º 16
0
        public bool Save(FileType type, Stream outstream, int parameter)
        {
            try
            {
                IntPtr imgDataHandle = IntPtr.Zero;
                int    len;
                try
                {
                    switch (type)
                    {
                    case FileType.Jpeg:
                        imgDataHandle = GDImport.gdImageJpegPtr(this.Handle, out len, parameter);
                        break;

                    case FileType.Png:
                        imgDataHandle = GDImport.gdImagePngPtr(this.Handle, out len);
                        break;

                    case FileType.Gd:
                        imgDataHandle = GDImport.gdImageGdPtr(this.Handle, out len);
                        break;

                    case FileType.Gd2:
                        imgDataHandle = GDImport.gdImageGd2Ptr(this.Handle, 0, GD2_FMT_COMPRESSED, out len);
                        break;

                    case FileType.WBMP:
                        imgDataHandle = GDImport.gdImageGdPtr(this.Handle, out len);
                        break;

                    case FileType.Xbm:
                    case FileType.Xpm:
                        throw new ApplicationException(type + " not implemented.");

                    default:
                        throw new ApplicationException(type + " is an unknown file type.");
                    }

                    if (imgDataHandle == IntPtr.Zero)
                    {
                        throw new ApplicationException("function Save(FileType type, Stream outstream, int parameter )");
                    }

                    byte[] imgData = new byte[len];

                    Marshal.Copy(imgDataHandle, imgData, 0, len);
                    MemoryStream img = new MemoryStream(imgData);

                    int    BUFFER = 4096;
                    byte[] buffer = new byte[BUFFER];
                    int    numBytes;

                    while ((numBytes = img.Read(buffer, 0, BUFFER)) > 0)
                    {
                        outstream.Write(imgData, 0, len);
                    }
                }
                finally
                {
                    // 2004-01-10 - Must free memory!! - Kevin Tam
                    if (imgDataHandle != IntPtr.Zero)
                    {
                        GDImport.gdFree(imgDataHandle);
                    }
                }
            }
            catch (Exception e)
            {
                throw new ApplicationException("function Save(FileType type, Stream outstream, int parameter ) failed", e);
            }
            return(true);
        }
Exemplo n.º 17
0
 public void CopyResampled(GD src, int dstX, int dstY, int srcX, int srcY, int destW, int destH, int srcW, int srcH)
 {
     GDImport.gdImageCopyResampled(this.Handle, src.GetHandle().Handle, dstX, dstY, srcX, srcY, destW, destH, srcW, srcH);
 }
Exemplo n.º 18
0
 public GDColor GetPixel(int x, int y)
 {
     return(new GDColor(GDImport.gdImageGetPixel(this.Handle, x, y)));
 }
Exemplo n.º 19
0
 public string StringFTCircle(int cx, int cy, double radius, double textRadius, double fillPortion, string font, double points, string top, string bottom, GDColor fgcolor)
 {
     return(GDImport.gdImageStringFTCircle(this.Handle, cx, cy, radius, textRadius, fillPortion, font, points, top, bottom, fgcolor));
 }
Exemplo n.º 20
0
 public void SetStyle(int[] style)
 {
     GDImport.gdImageSetStyle(this.Handle, style, style.Length);
 }
Exemplo n.º 21
0
        /***********************************************************************************\
        *  GD Query
        \***********************************************************************************/

        public void GetClip(ref int x1, ref int y1, ref int x2, ref int y2)
        {
            GDImport.gdImageGetClip(this.Handle, ref x1, ref y1, ref x2, ref y2);
        }
Exemplo n.º 22
0
 public void SetThickness(int thickness)
 {
     GDImport.gdImageSetThickness(this.Handle, thickness);
 }
Exemplo n.º 23
0
 public void SetClip(int x1, int y1, int x2, int y2)
 {
     GDImport.gdImageSetClip(this.Handle, x1, y1, x2, y2);
 }
Exemplo n.º 24
0
        public void CharUp(Font font, int x, int y, int c, GDColor color)
        {
            HandleRef fontHandle = font.GetHandle();

            GDImport.gdImageCharUp(this.Handle, fontHandle, x, y, c, color);
        }
Exemplo n.º 25
0
        /***********************************************************************************\
        *  GD Miscellaneous
        \***********************************************************************************/

        public void Compare(GD handle2)
        {
            GDImport.gdImageCompare(this.Handle, handle2.Handle);
        }
Exemplo n.º 26
0
        /***********************************************************************************\
        *  GD Copying/Resizing
        \***********************************************************************************/

        public void Copy(GD src, int dstX, int dstY, int srcX, int srcY, int w, int h)
        {
            GDImport.gdImageCopy(this.Handle, src.GetHandle().Handle, dstX, dstY, srcX, srcY, w, h);
        }
Exemplo n.º 27
0
 public int BoundsSafe(int x, int y)
 {
     return(GDImport.gdImageBoundsSafe(this.Handle, x, y));
 }
Exemplo n.º 28
0
        public void StringUp(Font font, int x, int y, string message, GDColor color)
        {
            HandleRef fontHandle = font.GetHandle();

            GDImport.gdImageStringUp(this.Handle, fontHandle, x, y, message, color);
        }
Exemplo n.º 29
0
 public void TrueColorToPalette(int ditherFlag, int colorsWanted)
 {
     GDImport.gdImageTrueColorToPalette(this.Handle, ditherFlag, colorsWanted);
 }
Exemplo n.º 30
0
 public void SetTile(GD brush)
 {
     GDImport.gdImageSetTile(this.Handle, brush.GetHandle());
 }