Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

GetBitmapBits, SetBitmaps API help

I'm reading a book about game programming with Visual Basic, and I've gotten stuck on a sample program that uses two WinAPI functions, GetBitmapBits and SetBitmapBits. I'm not sure what kind of return I'm getting. I know a get an array of stuff, but not sure whats in this array. Or even how the array is sized. The sample program isn't really explained, it just redims an array of longs to the (bitmaps height * bitmaps widthbytes) the bytes part throws me off. If anyone can tell me exactly what these functions are doing, and how I can use the data returned, please let me know.

Comments

  • SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
    : I'm reading a book about game programming with Visual Basic, and I've gotten stuck on a sample program that uses two WinAPI functions, GetBitmapBits and SetBitmapBits. I'm not sure what kind of return I'm getting. I know a get an array of stuff, but not sure whats in this array. Or even how the array is sized. The sample program isn't really explained, it just redims an array of longs to the (bitmaps height * bitmaps widthbytes) the bytes part throws me off. If anyone can tell me exactly what these functions are doing, and how I can use the data returned, please let me know.
    :
    Normally it's the bitmap bits if it is an array. The array is three-dimensional and either three or four bits deep, depending on whether you're using RGB or RGBA bitmaps. I use RGBA for the alpha-channel effects in OpenGL. Here's a sample.
    [code]
    char bits[32][32][3]; //RGB array
    char bits_2[32][32][4]; //RGBA array

    FILE *bitmapfile;
    BITMAPFILEHEADER bmfh;
    BITMAPINFOHEADER bmih;

    if((bitmapfile = fopen("blah.bmp", "rb")) == NULL)
    return -1;

    fread(&bmfh, sizeof(BITMAPFILEHEADER), 1, bitmapfile);
    fread(&bmih, sizeof(BITMAPINFOHEADER), 1, bitmapfile);
    fread(&bits, sizeof(bits), 1, bitmapfile); //You would use this to
    //read in a 32x32 bitmap
    //with an RGB format!
    fread(&bits_2, sizeof(bits_2), 1, bitmapfile); //Same as above, but for
    //RGBA format.
    fclose(bitmapfile);
    [/code]
    You would now have the bitmap's actual bit-array stored in bits or bits_2. Note that you could only use one array, although you could EASILY use the info in the two headers to find out which format the bitmap is, and then read the bits into the proper array with an "if" statement. I also did something simple and just used "sizeof(array_name)", which limits the bitmap to the exact size of the array. You could always make bits or bits_2 pointers and then allocate memory for them after reading the format in by using the width, height, and RGB or RGBA format with something like "malloc" or "new".

    One final thing. If the array you're getting returned is the bitmap bit array, it's in the format(s) noted above.
    bits[0][0][0] == the bitmap's 0, 0, red color (0 to 255)
    bits[0][0][1] == the bitmap's 0, 0, green color (0 to 255)
    bits[0][0][2] == the bitmap's 0, 0, blue color (0 to 255)
    bits[0][0][3] == the bitmap's 0, 0, alpha channel (0 to 255) (RGBA!!)

    Hope all that helps :D!

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

  • Chris BrownChris Brown USAMember Posts: 4,496 ✭✭

    // http://forcoder.org // free ebooks and video tutorials about \ Swift, Visual Basic, Objective-C, Visual Basic .NET, PHP, Go, C#, Perl, C, JavaScript, Scratch, Delphi, Java, Ruby, Python, PL/SQL, MATLAB, R, C++, Assembly Crystal, SAS, Ada, Bash, FoxPro, ML, Fortran, Clojure, Awk, Scala, F#, D, Logo, Kotlin, LabVIEW, Prolog, Lisp, COBOL, Hack, Transact-SQL, Rust, Alice, Scheme, Apex, ABAP, VBScript, Dart, Julia, Lua, Erlang \ _

Sign In or Register to comment.