how create a GDIPlus Image from HBITMAP?

how create a GDIPlus Image from HBITMAP?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
void NewImage(int Width, int Height)
    {
        if(ImageWidth==0) Dispose();
        ImageWidth=Width;
        ImageHeight=Height;
        HBitampHDC=CreateCompatibleDC(GetDC(NULL));
        memset(&bmi, 0, sizeof(bmi));
        bmi.bmiHeader.biSize = sizeof(bmi);
        bmi.bmiHeader.biWidth = Width;
        bmi.bmiHeader.biHeight = Height;
        bmi.bmiHeader.biPlanes = 1;
        bmi.bmiHeader.biBitCount = 32;
        bmi.bmiHeader.biCompression = BI_RGB;
        hBitmap = CreateBitmap(Width, Height,1,32,NULL);
        OldHBitmap=(HBITMAP)SelectObject(HBitampHDC,hBitmap);
        Gdiplus::BitmapData data;
        img->FromHBITMAP(hBitmap, NULL);
        Gdiplus::Rect rect(0,0, img->GetWidth(), img->GetHeight());
        auto status = img->LockBits(&rect, Gdiplus::ImageLockModeWrite, PixelFormat32bppARGB, &data); // 24 bit jpeg
        Pixels = static_cast<Pixel*>(data.Scan0);
        //img->UnlockBits(&data);


        RECT r={0,0,100,200};
        FillRect(HBitampHDC,&r,CreateSolidBrush(RGB(255,0,0)));

        /*for(unsigned int i=0;  i<(img->GetWidth()* img->GetHeight()-1); i++)
        {
            Pixels->blue=0;
            Pixels->green=255;
            Pixels->red=0;
            ++Pixels;
        }*/
    }

'img->FromHBITMAP(hBitmap, NULL);'
i don't know why i get errors or no results :(
the problem is the Pallet? i used 'NULL', because i don't know how i get it
the problem is the Pallet?
Maybe not. The problem might be line 15. Try FromHBITMAP(...) before the bitmap is selected (i.e. before line 15).
Topic archived. No new replies allowed.