示例#1
0
文件: GD.cs 项目: ststeiger/GdCaptcha
        // 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);
        }