No announcement yet.

Graphics question about black squares

  • Filter
  • Time
  • Show
Clear All
new posts

  • Graphics question about black squares

    I have a simple question about graphics :
    I want to remove the black square around an imported picture ( let's say a planet ) which I use in animations .
    It is very anoying to see in the animation for instance bodies being eclipsed by the body itself , but also by the black square around it.
    Is its possible to use only the important content of an imported picture .
    I guess there must be a pretty simple command in VB WinApi32 to cope with this ?
    FYI : I use PBasic for highly performant and accurate dynamical simulations of celestial bodies .

  • #2
    If and only if the planet portion of the image has no black pixels can this be done fairly easily. Otherwise you would be into some edge detections, etc. The technique involves using several bitmaps the size of your planet bittmap and GRAPHIC GET BITS. This assumes using PBWin/PBCC graphics commands only in this post. However you could look into GDI+ and other graphic standards as an alternative.

    Then you will need to use typical compositing techniques using before and after bitmaps that can be copied to the display as the planet moves across the screen. Essentially you need a full copy of the display screen without the planet(s), from that you can extract, as needed, working bitmaps for making the before and after bitmaps for copy to tthe new display page. Note that you would be using GRAPHIC ATTACH witth the REDRAW option and when all the copying, compositing is done then GRAPHIC REDRAW.

    As you move the plane, you copy the BEFORE bitmap into a copy of the display bitmap, erasing the current position of the planet. Then with a copy of the NEXT area of the display you composite a copy the planet bitmap to this equivalent sized NEXT bitmap, only copying pixels which are not black, using bitstrings. Finally copy that composite into the next display bitmap and REDRAW.

    Might be some examples in the source forum. Others might sugges using GDI+ ... if I can find an exaaample, I'll post later.
    Rick Angell


    • #3
      Thanks Rick for your help ! I'll give it a try .
      This forum is great having a lot of experienced people here who , I guess , have gone through all steps of trial and error ....
      It would be great if anywhere in the help files of PB there were sections in which these kind of things ( and thousands of others ) would have been explained step by step .
      This isn't a critic on PB but for most of other applications...
      How to....


      • #4
        Check into POFFS. it will help you search for posted code faster, offline. Of course it does no include examples later than is published date. There maay be an update in the future ... seems a saw a post talking about that recently.

        That said, here's an example of the simple graphics method I was talking about. There are many. many more approaches with PB's GRAPHIC tools and the WinAPI where you can use DIB sections, etc. The attached uses a strip of bitmaps in its resource file (not included). This is simply a sequential strip of bitmaps of the character walking in a certain direction (N,E,S,W) or doing some action. It was done as a test of concept, so is not very refined in the graphics (read: crude like in crayon) ... just enough to illustrate the idea. it does use a small bit of assembler to speed up part of the compositing process.
        Attached Files
        Rick Angell


        • #5
          The posted example uses the pixel in the upper left hand corner of the image as the key pixel not to copy when blending the new image with the next area to place. I recommend it should be a primary color for best results.
          Rick Angell


          • #6
            Thank you very much Richard , I'll go over the code ...!