Ejemplo 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 ) );
        }
Ejemplo n.º 2
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);
        }