C++ Bilder zeichnen
-
Ist es möglich ein PNG Bild in C++ ohne Windows Fenster zu zeichnen? Ich bräuchte nur simple Befehle die es mir ermöglichen Linien in einer bestimmten Farbe zu zeichnen und als Bild abzuspeichern. Das Bild muss nicht einmal angezeigt werden. Es soll nur gezeichnet werden.
-
#include <windows.h> #include <gdiplus.h> #include <stdio.h> using namespace Gdiplus; #pragma comment(lib, "gdiplus.lib") int GetEncoderClsid(const WCHAR* format, CLSID* pClsid) { UINT num = 0; // number of image encoders UINT size = 0; // size of the image encoder array in bytes ImageCodecInfo* pImageCodecInfo = NULL; GetImageEncodersSize(&num, &size); if(size == 0) return -1; // Failure pImageCodecInfo = (ImageCodecInfo*)(malloc(size)); if(pImageCodecInfo == NULL) return -1; // Failure GetImageEncoders(num, size, pImageCodecInfo); for(UINT j = 0; j < num; ++j) { if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 ) { *pClsid = pImageCodecInfo[j].Clsid; free(pImageCodecInfo); return j; // Success } } free(pImageCodecInfo); return -1; // Failure } INT main() { GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); { // Diese Klammer ist erforderlich weil der Destruktor von bmp vor GdiplusShutdown // aufgerufen werden muss Bitmap bmp(200,200); for(int y = 0; y < bmp.GetHeight(); y++) for(int x = 0; x < bmp.GetWidth(); x++) { bmp.SetPixel(x,y, Color(255, 255,0, 0)); } // Save the altered image. CLSID pngClsid; GetEncoderClsid(L"image/png", &pngClsid); bmp.Save(L"Test.png", &pngClsid, NULL); } GdiplusShutdown(gdiplusToken); return 0; }
-
Du redest aber vom Zeichnen. Wo willst du die Farbwerte hinzeichnen? Oder möchtest du die einezlnen Pixel einfach nur in einem Buffer (Array) haben?