Announcement

Collapse
No announcement yet.

Graphic handle for Windows bitmap

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Michael Mattias
    replied
    >Is there an API analogue to Graphic Get Bits?

    Well, not in so many words, but yes.

    How you get the bits depends on the object. eg if it's a bitmap object, the bmbits member of the BITMAP structure returned by GetObject(hBmp) is a pointer to the data; you have to calculate how many bytes to read at that address using the other members of the bitmap structure.

    Hmmm.... I guess "not in so many words" should be "not in so few words," huh?



    MCM

    Leave a comment:


  • Chris Holbrook
    replied
    Originally posted by Mark Hunter View Post
    Chris (next to last post),If you need a license to drive, why not to use CreateCompatibleBitmap? Seriously, I don’t understand. The above is the first use of the word “license” in this thread.
    please ignore that comment.

    Originally posted by Mark Hunter View Post
    My actual code would only burden people with unnecessary details.
    and would also give them a clear idea what you are trying to do. A lot of people on these forums are much more fluent in PowerBasic than the are in English. Compileable code will communicate directly to their highly adapted brains.

    Originally posted by Mark Hunter View Post
    To use Graphic Set Bits you need to “get” the bitmap into a string.
    I apologise unreservedly. I was thinking about GRAPHIC SET PIXEL and bitmaps. Somewhere in my decaying cerebral cortex the bits and pixels got swapped over.

    Leave a comment:


  • Mark Hunter
    replied
    Chris (next to last post),
    You don't need a license to use CreateCompatibleBitmap.
    If you need a license to drive, why not to use CreateCompatibleBitmap? Seriously, I don’t understand. The above is the first use of the word “license” in this thread. In any case CreateCompatibleBitmap is accidental to my question. However it is that you create a bitmap using the Windows API, how do you give it to PowerBasic?

    Though this thread is not about CreateCompatibleBitmap, there’s a place, for people to discuss that function, namely the Programming Forum, which covers API calls.

    My actual code would only burden people with unnecessary details. If you start with the Windows bitmap handle obtained by APIs, then what I’ve posted is actual code.

    In a way this thread is about DCs, and isn’t it in the right forum? The console compiler has a statement to get the DC of the current Graphic window:
    GRAPHIC GET DC TO hDC???
    The DC handle may be used with various Windows API functions to perform specialized graphic operations in the graphic window. The graphic window must first be selected with GRAPHIC ATTACH.
    This thread is about the inverse of that function: Start with hDC??? and create a PowerBasic handle.

    Dave Biggs,

    Thanks for the thought. That method could be a stop gap. However the job I have in mind involves large files which will be saved, and that method would double an already time consuming process.

    Chris (last post),

    To use Graphic Set Bits you need to “get” the bitmap into a string. Is there an API analogue to Graphic Get Bits?
    So, how did you do it, Mark?
    Unfortunately a loaded question!

    Leave a comment:


  • Chris Holbrook
    replied
    Or use a bitwise copy method to copy from the bitmap into the GRAPHIC WINDOW's DC, either using an API method or GRAPHIC SET BITS.

    So, how did you do it, Mark?

    Leave a comment:


  • Dave Biggs
    replied
    A possible solution/work-around might be for Mark to copy his API created Bitmap to a file which could then be Graphic Rendered into a PB Graphic object.. ?

    Leave a comment:


  • Chris Holbrook
    replied
    You don't need a licence to use CreateCompatibleBitmap.

    If you have a code example which creates a bitmap that way and you want to simplify the image handling by using the DDT GRAPHIC stuff, then it seems like a reasonable question.

    BTW if you want to research CreateCompatibleBitmap, the forums are not the place to do it, for a similar reason to why they are not the place to research DCs.

    Leave a comment:


  • Michael Mattias
    replied
    Call me an optimist or naive or something....

    But it seems to me anyone who can use CreateCompatibleBitmap() ought to able to get said bitmap onto the screen without the use of GRAPHICS statements.

    Heck, I do not understand CreateCompatibleBitmap(), and I can get a bitmap on the screen.

    Leave a comment:


  • Chris Holbrook
    replied
    Originally posted by Michael Mattias View Post
    That cannot work.
    ...So I read the first post again.

    What Mark seems to be asking is how to convert a bitmap into something which the DDT GRAPHICS statements can manipulate successfully. The only answer I can think of is to create a DDT graphic object and copy the bitmap into it by getting its device context.

    Which would make sense because the GRAPHIC statements operate on a GRAPHIC object, not a bitmap. A GRAPHIC WINDOW being a custom control, not a bitmap, although a bitmap lives inside it. Turning a bitmap into a GRAPHIC object would be a bit like turning a worm into an apple.

    Leave a comment:


  • Michael Mattias
    replied
    >Graphic Copy winC, 0 ......................... ' try to copy the Windows bitmap to it

    That cannot work. Doc says...
    The expression hbmpSource??? specifies the handle of the source GRAPHIC BITMAP, GRAPHIC WINDOW, or dialog containg [sic] a GRAPHIC CONTROL.
    winC is 'none of the above'

    Leave a comment:


  • Chris Holbrook
    replied
    Mark, is your bitmap handle non-zero? Could you show compileable non-working code?

    Leave a comment:


  • Mark Hunter
    replied
    Chris,

    If I understand your hint I’d tried it, like this (PBCC 4.04):

    Graphic Bitmap New W,H To winD ........ ' set up PowerBasic bitmap
    Graphic Attach winD, 0 ....................... ' make it current
    Graphic Copy winC, 0 ......................... ' try to copy the Windows bitmap to it
    Graphic Save "foo.bmp" ..................... ' test if it worked

    and foo.bmp is hash

    MCM,

    The following is my understanding of Set/Get Bits.

    Say you already have a PB bitmap and it is current (Graphic Attach). You can turn it into a string like this:
    Graphic Get Bits To BigOldString$
    Then you can manipulate the string. When you’re done you can turn it back into a bitmap (the same handle as in Graphic Attach):
    Graphic Set Bits BigOldString$

    I gather you could start with a string of any provenance and use Set Bits on it (after having set up and made current a PB bitmap handle with the desired width and height).

    This would be a solution to the problem if what Get Bits does can be done with the Windows API.

    Leave a comment:


  • Michael Mattias
    replied
    I'm not a graphic guy but IIRC the handles returned by GRAPHIC BITMAP are not windows handles. (Not in doc either way).

    It looks like the help for GRAPHIC SET BITS includes some info on how to copy the bits from a Windows bitmap to a PB bitmap.

    Leave a comment:


  • Chris Holbrook
    replied
    graphic copy?

    Leave a comment:


  • Mark Hunter
    started a topic Graphic handle for Windows bitmap

    Graphic handle for Windows bitmap

    Probably an elementary question, but after an hour ...

    Say a program determines a bitmap handle using the Windows API. For example:

    winC = CreateCompatibleBitmap(...)

    and along the way it computes the width W and height H of the bitmap.

    Problem: Get the various Graphic statements to recognize this bitmap. Graphic Attach winC, 0 doesn’t work.

    In other words, how can the program set up a handle for this bitmap that PowerBasic’s Graphic statements recognize, a handle, call it winD, that can be used as if the bitmap had been set up with

    Graphic Bitmap New W,H to winD
    ?

    A sort of inverse of Get DC.
    Last edited by Mark Hunter; 15 Oct 2009, 05:52 AM.
Working...
X