⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.cpp

📁 在windows和linux下
💻 CPP
字号:
// test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
//#include <hash_set>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>

//#include "config.h"
#include "gd.h"
#include "gdfontt.h"
#include "gdfonts.h"
#include "gdfontmb.h"
#include "gdfontl.h"
#include "gdfontg.h"


//---------------------------------------------------------------------------

#pragma hdrstop

//---------------------------------------------------------------------------


//#include <regex.h>
using namespace std;
//////////////////////////////////////////////////////////////////////////
#define MAX_FILE_LEN	200*1024
#define MAX_REVC_LEN	1024
int getpng(char *string,int strlen)
{
	int back,word,front,len,sx,sy,i;
	char *str;
	gdImagePtr newimg;
	FILE *f;
	int size;
	char *data;
	int x1,x2;
	gdFontPtr gfontp;
	str=string;
	len=strlen;
	sx=10+len*9;
	sy=20;
	newimg=gdImageCreate(sx,sy); 
	f=fopen("mypng.gif","a+");
	back=gdImageColorAllocate(newimg,0,255,128); 
	word=gdImageColorAllocate(newimg,128,128,128); 
	front=gdImageColorAllocate(newimg,255,64,128);
	gdImageFill(newimg,0,0,back);  
	gfontp = gdFontGetLarge();
//	gdImageString(newimg,gdFontGiant,5,1,(unsigned char *)str,word);
	x1 = newimg->sx/2 - strlen * gfontp->w/2;
	x2 = newimg->sy / 2 - gfontp->h / 2;
	gdImageString(newimg, gfontp, x1,x2, (unsigned char *)str, word);

	 for(i=0;i<len;(i=i+2))
	  gdImageLine(newimg,(5+i*9),0,(23+i*9),20,front);
//	gdImagePngEx(newimg,f,9);
//	gdImagePng(newimg,f);
//	data = (char *) gdImagePngPtr(newimg, &size);
	data = (char *) gdImageGifPtr(newimg, &size);
	fwrite(data, sizeof(unsigned char), size, f);
	gdImageDestroy(newimg); 
	fclose(f);
	gdFree(data);
	return 1;
}

char* getImage(char *sSource,char* sDest,int iImg)
{
	int back,word,front,len,sx,sy,i;
	char *str;
	gdImagePtr newimg;
	int size;
	char *data;
	int x1,x2;
	gdFontPtr gfontp;

	if (sSource == NULL)
	{
		return sSource;
	}
	str=sSource;
	len=strlen(str);
	sx=10+len*9;
	sy=20;

	newimg=gdImageCreate(sx,sy); 	
	back=gdImageColorAllocate(newimg,0,255,128); 
	word=gdImageColorAllocate(newimg,128,128,128); 
	front=gdImageColorAllocate(newimg,255,64,128);
	gdImageFill(newimg,0,0,back);  
	gfontp = gdFontGetLarge();
	
	x1 = newimg->sx/2 - len * gfontp->w/2;
	x2 = newimg->sy / 2 - gfontp->h / 2;
	gdImageString(newimg, gfontp, x1,x2, (unsigned char *)str, word);
	
	for(i=0;i<len;(i=i+2))
	{
		gdImageLine(newimg,(5+i*9),0,(23+i*9),20,front);
	}
	if (iImg == 1)
	{
		data = (char *) gdImagePngPtr(newimg, &size);
	}
	else
	{
		data = (char *) gdImageGifPtr(newimg, &size);
	}
	sDest = new char[size];
	memset(sDest,0,size);
	gdImageDestroy(newimg); 
	memcpy(sDest,data,size);
	int len2 = strlen(sDest);
	gdFree(data);
	return sDest;
}



int main(int argc, char* argv[])
{
	try
	{
		
		gdImagePtr im;
		
		im = gdImageCreate(64, 64);
		gdImageDestroy(im);
		char* c="12A4F6";
		int len = strlen(c);
		char* sDest = NULL;
		getpng(c,len);
		getImage(c,sDest,2);
		FILE *f;
		f=fopen("1.gif","a");
		fwrite(sDest, 1, strlen(sDest), f);
		fclose(f);
		delete sDest;
		
		
		int sx,sy,skyblue;
		gdImagePtr newimg;
//		FILE *f;
		int size;
		char *data;

		sx=250;
		sy=250;
		newimg=gdImageCreate(sx, sy);
		f=fopen("skyblue.png","a");

		skyblue=gdImageColorAllocate(newimg, 136, 193, 255);
		gdImageFill(newimg, 0, 0, skyblue);
//		gdImagePng(newimg, pngfp);
		data = (char *) gdImagePngPtr(newimg, &size);
		fwrite(data, 1, size, f);
		gdImageDestroy(newimg);

		fclose(f);
		printf("good\n");
	}
	catch (...)
	{
		printf("exception\n");
	}


	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -