線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1130
推到 Plurk!
推到 Facebook!

GD函數載入與使用

尚未結案
renth555
一般會員


發表:32
回覆:65
積分:19
註冊:2003-02-17

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-08-23 17:11:50 IP:61.56.xxx.xxx 未訂閱
GD Library FAQ    Why does bgd.dll crash with my C program? You are trying to use gd's stdio library functions with a different C runtime library. Read on for notes on individual compilers.  Microsoft Visual C++: If you want to use gdImageCreateFromPng, gdImagePng, and other functions that take a FILE *, you MUST use Visual C++ 6.0 or earlier and you MUST link with the "multithreaded DLL" runtime library option. If you wish to use the .NET compiler, read the "Borland C++" section for an alternative method.     If you do not take the time to understand this, your program simply will not work! Note: the "multithreaded debug DLL" option is NOT the same thing and will NOT work. If you don't want to use the "multithreaded DLL" runtime library option (see "code generation" under "settings"), then read the "Borland C++" section for an alternative method.     GNU mingw32: you should have no problems. The mingw32 compiler is designed to link your application with msvcrt.dll, the same C runtime library that bgd.dll was linked with. (We build it with mingw32, as it happens.)     GNU cygwin: if you are compiling with -mno-cygwin, see the GNU mingw32 entry, above. If you are linking with the full cygwin runtime library, you might be better off installing gd from source. "configure" and "make install" should work for you as they do on full Unix systems. If you have solved the problem of using a win32 DLL from cygwin, however, you can certainly use bgd.dll using the same techniques described below for Borland C++.     Borland C++: this product apparently provides its own C runtime library, incompatible with Microsoft's msvcrt.dll. You cannot use the FILE * functions in gd.h. However, there is an alternative. The gdImagePngPtr and gdImageCreateFromPngPtr functions provide a way to write image file data to a memory buffer, or load an image from a buffer of image file data. See the next two questions for code samples.     How do I load an image file from a buffer in memory? The following C code shows how to load an entire image file into a buffer in memory, then ask gd to read the image from that buffer. Please note that since you are responsible for allocating the buffer, You are also responsible for freeing the buffer with your normal memory management functions.  Note to Borland C++ programmers: this code will allow you to load an image using the bgd.dll library, because no FILE * objects are passed across the DLL boundary.     Of course, there is a gdImageCreateFromJpegPtr function available as well. This particular example loads a PNG image.     
    #include 
#include 
#include     gdImagePtr myLoadPng(char *filename)
{
  FILE *in;
  struct stat stat_buf;
  gdImagePtr im;
  in = fopen("myimage.png", "rb");
  if (!in) {
    /* Error */
  }
  if (fstat(fileno(in), &stat_buf) != 0) {
    /* Error */
  }
  /* Read the entire thing into a buffer 
    that we allocate */
  char *buffer = malloc(stat_buf.st_size);
  if (!buffer) {
    /* Error */
  }
  if (fread(buffer, 1, stat_buf.st_size, in) 
    != stat_buf.st_size) 
  {
    /* Error */
  }
  im = gdImageCreateFromPngPtr(
    stat_buf.st_size, buffer);
  /* WE allocated the memory, WE free 
    it with our normal free function */
  free(buffer);
  fclose(in);
  return im;
} 
How do I save an image to a buffer in memory? The following C code shows how to save a gd image to a memory buffer, and then write that buffer to a file on disk. You could also write it directly to stdout, preceded by a Content-type: image/png header and two CR/LF sequences, to directly return an image from a CGI program. Note to Borland C programmers: this code will allow you to save an image using the bgd.dll library, because no FILE * objects are passed across the DLL boundary. For your convenience, gd allocates the buffer for you; when you are done with it, you must call gdFree to release it. Of course, there is a gdImageJpegPtr function available as well. This particular example saves a PNG image.
#include 
#include 
#include     void mySavePng(char *filename, 
  gdImagePtr im)
{
  FILE *out;
  int size;
  char *data;
  out = fopen("filename, "wb");
  if (!out) {
    /* Error */
  }
  data = (char *) gdImagePngPtr(im, &size);
  if (!data) {
    /* Error */
  }
  if (fwrite(data, 1, size, out) != size) {
    /* Error */
  }
  if (fclose(out) != 0) {
    /* Error */
  }
  gdFree(data);  
}    
http://www.boutell.com/gd/faq.html 上面這些使用方法不知我要如何叫用他的dll函數功能 因為GD在影像縮圖處理上有很強大的表現 希望各位前輩研究看看來受惠版上User
系統時間:2024-06-29 15:42:07
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!