Jump to content
Maximus

C++ adaugare text pe imagine

Recommended Posts

Salut, am gasit acest cod pe net


#include "stdafx.h"
#include <stdio.h>
#include <gd.h>
#include <gdfontg.h>

int main(int argc, char *argv[]) {
gdImagePtr img;
FILE *fp = {0};
int width, white, black;

width = white = black = 0;

if(argc != 3) {
fprintf(stderr, "Usage: pngtxt image.png 'Hello world.. !'\n");
return 1;
}

fp = fopen(argv[1], "wb");
if(fp == NULL) {
fprintf(stderr, "Error - fopen(%s)\n", argv[1]);
return 1;
}

width = strlen(argv[2]);

img = gdImageCreate(width * 10, 20);

white = gdImageColorAllocate(img, 255, 255, 255);
black = gdImageColorAllocate(img, 0, 0, 0);

gdImageString(img, gdFontGiant, 2, 1, argv[2], black);

gdImagePng(img, fp);

fclose(fp);
gdImageDestroy(img);

return 0;
}

Cand compilez, imi da


Error 3 error C2664: 'gdImageString' : cannot convert parameter 5 from 'char *' to 'unsigned char *' c:\users\maximus\documents\visual studio 2010\projects\text2pic\text2pic\text2pic.cpp 31 1 text2pic
Error 2 error C3861: 'strlen': identifier not found c:\users\maximus\documents\visual studio 2010\projects\text2pic\text2pic\text2pic.cpp 24 1 text2pic
5 IntelliSense: argument of type "char *" is incompatible with parameter of type "unsigned char *" c:\users\maximus\documents\visual studio 2010\projects\text2pic\text2pic\text2pic.cpp 31 40 text2pic
4 IntelliSense: identifier "strlen" is undefined c:\users\maximus\documents\visual studio 2010\projects\text2pic\text2pic\text2pic.cpp 24 10 text2pic
Warning 1 warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. c:\users\maximus\documents\visual studio 2010\projects\text2pic\text2pic\text2pic.cpp 18 1 text2pic

Ma poate ajuta cineva? Raman recunoscator.Multumesc

Link to comment
Share on other sites

De fapt, ala nu se compileaza cu c++ ci cu c

Ala e cod de c. Compileaza-l cu gcc in loc de g++ si ar trebui sa functioneze fara probleme.

Fii mai atent, foloseste visual studio.

Cat despre erorile tale..

http://msdn.microsoft.com/en-us/library/78zh94ax(v=vs.100).aspx

http://www.learncpp.com/cpp-tutorial/44-type-conversion-and-casting/

http://msdn.microsoft.com/en-us/library/yeby3zcb(v=vs.100).aspx

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...