Results 1 to 3 of 3

Thread: Create Bitmap from an Array of Bytes

  1. #1

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192

    Question Create Bitmap from an Array of Bytes

    How can I create a Bitmap from an Array of Bytes?

    I tried using createBitmap but I couldn't make it work... Could anyone give me an example of how it is used?


    VB Code:
    1. Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Posts
    192
    This has been an issue with many for a long time. I remain unclear as to why programming language authors do not provide an easy way to access image arrays. My 'opinion' is that 'they' should 'trust' users more, there-by allowing 'us' to 'have more fun'. At any rate, there is the complicated vb way of accessing Refresh buffer arrays, and there are quite a few examples on the web of how this works. Fortunately, processing in this fashion is fast, because as many know, processing an array variable takes only slightly more time than processing a regular variable.

    One thing before I get started with a description of the process: bmp data recognizes blue, then green, then red, in that order.

    If your image had only 1 pixel, and you define your array as byte, and your image as 32 bit,

    ary(0) would be the blue byte ..


    There are several methods you can use to go about defining your array.

    1d vs. 2d
    Type or variable

    for example

    Type BGRQuad
    Blue as byte
    Green as byte
    Red as byte
    Reserved as byte
    end type

    Dim Ary(1023,767) as BGRQuad..
    Ary(40,40).Blue = 255
    Ary(40,40).Green = 255

    ..

    or you can do this

    Const L = 800x600 - 1
    Dim Ary(L) as byte

    ..
    Ary(0) = 255 'Blue
    Ary(1) = 0 'Green
    ..

    It has been my experience that using a Type array is the slowest. I have a friend who mentioned that using 1d arrays are faster than using 2d, and I tried both and found that with all that I have going on in my typical 'pixel shading' renderers, they are about equal.

    Understand that if you have the option of compiling for speed, that what may be slower in the vb ide may be faster in a Native code .exe.

    In VB, doing things like this is slow.

    Bytes(N) = Alpha
    Bytes(N + 1) = Alpha
    Bytes(N + 2) = Alpha
    But this ends up blazingly fast in the Native code .exe

    ......

    Take a look at the attached file. Files will unzip to 2 folders. The project in the folder " .. 2" uses a Byte array, and the regular folder uses a Type array.

    Open either, and look at modFCG (drag all the way down) and you will see the array.

    Here is what to look for in the regular folder:

    Surf.Dib(DrawX, DrawY).Blue
    Surf.Dib(DrawX, DrawY).Green
    Surf.Dib(DrawX, DrawY).Red
    Attached Files Attached Files

  3. #3

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192

    Thanks!

    Thank you, I am going to check it.

    By the way, do you know how to use Interpolation for zooming a Picture?
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width