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 ) ); }
public void Free() { if (!IsNull) { GDImport.gdFree(mPtr); mPtr = IntPtr.Zero; } }
protected virtual void Dispose(bool managed) { if (!this.disposed) { GDImport.gdImageDestroy(this.Handle); this.disposed = true; } }
// 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); }
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); }
/// <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); } }
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); } }
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); }
/***********************************************************************************\ * 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 ) ); }
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); }
public void Sharpen(int pct) { GDImport.gdImageSharpen(this.Handle, pct); }
public void PaletteCopy(GD src) { GDImport.gdImagePaletteCopy(this.Handle, src.GetHandle().Handle); }
public void SquareToCircle(int radius) { GDImport.gdImageSquareToCircle(this.Handle, radius); }
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); }
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); }
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); }
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); }
public GDColor GetPixel(int x, int y) { return(new GDColor(GDImport.gdImageGetPixel(this.Handle, x, y))); }
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)); }
public void SetStyle(int[] style) { GDImport.gdImageSetStyle(this.Handle, style, style.Length); }
/***********************************************************************************\ * 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); }
public void SetThickness(int thickness) { GDImport.gdImageSetThickness(this.Handle, thickness); }
public void SetClip(int x1, int y1, int x2, int y2) { GDImport.gdImageSetClip(this.Handle, x1, y1, x2, y2); }
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); }
/***********************************************************************************\ * GD Miscellaneous \***********************************************************************************/ public void Compare(GD handle2) { GDImport.gdImageCompare(this.Handle, handle2.Handle); }
/***********************************************************************************\ * 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); }
public int BoundsSafe(int x, int y) { return(GDImport.gdImageBoundsSafe(this.Handle, x, y)); }
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); }
public void TrueColorToPalette(int ditherFlag, int colorsWanted) { GDImport.gdImageTrueColorToPalette(this.Handle, ditherFlag, colorsWanted); }
public void SetTile(GD brush) { GDImport.gdImageSetTile(this.Handle, brush.GetHandle()); }