FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


C++, drawing an image





Xcelerate
I've got a problem. This code doesn't work. I have tried everything to get it to draw a large blue square, but it only does a black one:


Globals:
Code:

HBITMAP graphic;
HBITMAP dib_graph;
int x_pixels_per_meter = 0;
int y_pixels_per_meter = 0;
BITMAPINFO bitmap_info;
BITMAPINFOHEADER bitmap_info_header;
RGBQUAD rgb_quad[640*480];


WM_CREATE:
Code:

bitmap_info_header.biSize = sizeof(BITMAPINFOHEADER);
         bitmap_info_header.biWidth = 640;
         bitmap_info_header.biHeight = 480;
         bitmap_info_header.biPlanes = 1;
         bitmap_info_header.biBitCount = 24;
         bitmap_info_header.biCompression = BI_RGB;
         bitmap_info_header.biSizeImage = 0;
         bitmap_info_header.biXPelsPerMeter = x_pixels_per_meter;
         bitmap_info_header.biYPelsPerMeter = y_pixels_per_meter;
         bitmap_info_header.biClrUsed = 0;
         bitmap_info_header.biClrImportant = 0;

         int x;
         for (x = 0; x < 640*480; x++)
            {
            rgb_quad[x].rgbBlue = 255;
            rgb_quad[x].rgbGreen = 0;
            rgb_quad[x].rgbRed = 0;
            rgb_quad[x].rgbReserved = 0;
         }

         char bmiColors[640*480];

         bitmap_info.bmiHeader = bitmap_info_header;
         bitmap_info.bmiColors[1] = (RGBQUAD)rgb_quad[1];


WM_PAINT:
Code:

                BITMAP bitmap;
           PAINTSTRUCT paint_structure;
           HDC window_hdc = BeginPaint(window_handle, &paint_structure);

           HDC hdc_memory = CreateCompatibleDC(window_hdc);
         dib_graph = CreateDIBSection(hdc_memory, &bitmap_info, DIB_RGB_COLORS, &bits, NULL, 0);
         if (dib_graph == NULL)
            error("Error creating DIB graph!");
           HBITMAP bitmap_object = SelectObject(hdc_memory, dib_graph);

           GetObject(dib_graph, sizeof(bitmap), &bitmap);

           BitBlt(window_hdc, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdc_memory, 0, 0, SRCCOPY);
           SelectObject(hdc_memory, bitmap_object);
           DeleteDC(hdc_memory);
DX-Blog
Can't find the error in your code that quickly and dont have a compiler installed on this sytem to check it out, but why use such a lengthy code in order to draw a coloured rectangle?

The following code would create a blue rectangle of 100x100.
Code:
HDC hdc;
PAINTSTRUCT ps;

hdc = BeginPaint(hWnd, &ps);
RECT rt = {0, 0, 100, 100};
static HBRUSH brBlue;
if (!brBlue) brBlue = CreateSolidBrush(RGB(0,0,255));

SelectObject(hdc,brBlue);
FillRect(hdc,&rt,brBlue);
DeleteObject(hdc,brBlue);

EndPaint(hWnd, &ps);
break;
Related topics
about ma gal
Image manupulation in Java
Creating Hard Drive Image With Norton Ghost
adobe photoshop or the gimp?
Image Processing in C++ by Shirish
Image Display Problem
Frankfurt Motor Show, 2005
image drawing with php
Jamatus' Dynamic image store
why do christians make prophet jesus as a god?
Dynamic arrangement of buttons in C# Win Form
Make a image with wordwrap
Einstein proves Religion
"drawing" with JavaScript
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.