コード例 #1
0
ファイル: GD.cs プロジェクト: ststeiger/GdCaptcha
        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 ) );
        }