C language > Windows questions

Gdi+ image operation

<< < (2/4) > >>

TimoVJL:
Maybe those are constants.

--- Code: ---const CLSID CLSID_image_bmp =  {0x557CF400,0x1A04,0x11D3,0x9A,0x73,0x00,0x00,0xF8,0x1E,0xF3,0x2E};
const CLSID CLSID_image_jpeg = {0x557CF401,0x1A04,0x11D3,0x9A,0x73,0x00,0x00,0xF8,0x1E,0xF3,0x2E};
const CLSID CLSID_image_gif =  {0x557CF402,0x1A04,0x11D3,0x9A,0x73,0x00,0x00,0xF8,0x1E,0xF3,0x2E};
const CLSID CLSID_image_tiff = {0x557CF405,0x1A04,0x11D3,0x9A,0x73,0x00,0x00,0xF8,0x1E,0xF3,0x2E};
const CLSID CLSID_image_png =  {0x557CF406,0x1A04,0x11D3,0x9A,0x73,0x00,0x00,0xF8,0x1E,0xF3,0x2E};
const CLSID CLSID_image_ico =  {0x557CF407,0x1A04,0x11D3,0x9A,0x73,0x00,0x00,0xF8,0x1E,0xF3,0x2E};

--- End code ---
EDIT: with one variable
--- Code: ---CLSID CLSID_image =  {0x557CF400,0x1A04,0x11D3,0x9A,0x73,0x00,0x00,0xF8,0x1E,0xF3,0x2E};
--- End code ---
just change one byte like
--- Code: ---*(BYTE*)&CLSID_image = 6; // PNG
--- End code ---

--- Code: ---#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <objbase.h>
#pragma comment(lib, "ole32.lib")

CLSID CLSID_image =  {0x557CF400,0x1A04,0x11D3,0x9A,0x73,0x00,0x00,0xF8,0x1E,0xF3,0x2E};

void __cdecl WinMainCRTStartup(void)
{
wchar_t *pwc, wcTmp[555];
pwc = wcTmp;
for (char i=0; i<=7;i++) {
*(BYTE*)&CLSID_image = i;
pwc += StringFromGUID2(&CLSID_image, pwc, 39);
*(pwc-1) = 10;
}
MessageBoxW(0, wcTmp, 0, 0);
ExitProcess(0);
}
--- End code ---

liut:
Thanks Timo. It works with these const perfectly!

frankie:
Sorry I was wrong with use of GdipSaveImageToFile.
I edited the post above.

bitcoin:
How I can make screenshot with gdi? I tried source code , but i get 'Access violation' in string GdipGetImageEncodersSize(&num, &size);
Why?

bitcoin:
Updated. I found a mistake and made it. It looks like a piece of shit, but it works. Maybe someone will come in handy (I doubt, because this is an example of "how not to code" and I am the worst coder on the planet, I have to kill myself).


--- Code: ---void MakeScr(void)
{
GUID  FormatPNG = {0x557CF406,0x1A04,0x11d3,0x9A,0x73,0x00,0x00,0xf8,0x1e,0xf3,0x2e};     
const CLSID CLSID_image_png =  {0x557CF406,0x1A04,0x11D3,0x9A,0x73,0x00,0x00,0xF8,0x1E,0xF3,0x2E};

const GUID EncoderQuality = {0x1d5be4b5, 0xfa4a, 0x452d, 0x9c, 0xdd, 0x5d, 0xb3, 0x51, 0x05, 0xe7, 0xeb};


GdiplusStartupInput gdiplusStartupInput = {1,0,0,0};
ULONG_PTR gdiplusToken;

//i dont know how to check errors here, only log, if != 0 - error
  printf("%d",GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL));
 
HDC dc, hdc;
HBITMAP hbitmap;

dc = GetDC(0);

int Height, Width;
Height = GetSystemMetrics(SM_CYSCREEN);
Width = GetSystemMetrics(SM_CXSCREEN);

hbitmap = CreateCompatibleBitmap(dc, Width, Height);


hdc = CreateCompatibleDC(dc);

SelectObject(hdc, hbitmap);
BitBlt(hdc, 0, 0, Width, Height, dc, 0, 0, SRCCOPY);

GpBitmap *newBp;
printf ("%d \n",GdipCreateBitmapFromHBITMAP(hbitmap,0,&newBp));


CLSID encoderClsid;
EncoderParameters para;
ULONG quality;

//GetEncoderClsid(L"image/png",&encoderClsid); -

printf("%d\n",GdipSaveImageToFile(newBp, L"mybitmap.png", &FormatPNG, NULL));

    DeleteObject(hbitmap);
 
    //GdiplusShutdown?
    return 0;
}

--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version