Chinaunix
标题:
求助:能帮我写段代码吗?
[打印本页]
作者:
tyyx
时间:
2003-02-20 08:20
标题:
求助:能帮我写段代码吗?
webalizer 中graphs.c因该是用C编的吧,我对C一窍不通...
void init_graph(char *title, int xsize, int ysize)
{
int i;
im = gdImageCreate(xsize,ysize);
/* allocate color maps, background color first (grey) */
grey = gdImageColorAllocate(im, 192, 192, 192);
dkgrey = gdImageColorAllocate(im, 128, 128, 128);
black = gdImageColorAllocate(im, 0, 0, 0);
white = gdImageColorAllocate(im, 255, 255, 255);
green = gdImageColorAllocate(im, 0, 128, 92);
orange = gdImageColorAllocate(im, 255, 128, 0);
blue = gdImageColorAllocate(im, 0, 0, 255);
red = gdImageColorAllocate(im, 255, 0, 0);
cyan = gdImageColorAllocate(im, 0, 192, 255);
yellow = gdImageColorAllocate(im, 255, 255, 0);
/* make borders */
for (i=0; i<5 ;i++) /* do shadow effect */
{
gdImageLine(im, i, i, xsize-i, i, white);
gdImageLine(im, i, i, i, ysize-i, white);
gdImageLine(im, i, ysize-i-1, xsize-i-1, ysize-i-1, dkgrey);
gdImageLine(im, xsize-i-1, i, xsize-i-1, ysize-i-1, dkgrey);
}
gdImageRectangle(im, 20, 25, xsize-21, ysize-21, black);
gdImageRectangle(im, 19, 24, xsize-22, ysize-22, white);
gdImageRectangle(im, 0, 0, xsize-1, ysize-1, black);
gdImageStringFT(im,0,blue,myfont,10,0.0,20,8,title); /*
return;
}
复制代码
想把char *title由GB2312编码变成UTF-8编码怎么做?
gdImageStringFT(im,0,blue,myfont,10,0.0,20,8,"汉字"
;生成的图片中汉字是乱码 ,
gdImageStringFT(im,0,blue,myfont,10,0.0,20,8,"锘挎眽瀛"
;生成的图片汉字正常了.......
http://xcin.linux.org.tw/i18n/pc2000/p4/node2.html
http://cosoft.org.cn/snippet/detail.php?type=snippet&id=4571
我觉得
#include <iconv.h>;
...
fd = iconv_open("UTF-8", "936"
;
trans_size = iconv(fd, &fromstr_p, &fromsize, &tostr_p, &tosize);
iconv_close(fd);
.....
就是我要用的......
gdImageStringFT字符肯定要UTF-8才能正确显示汉字.
谢谢!
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2