Announcement

Collapse
No announcement yet.

How to place a small bmp image on a graphic control

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

    How to place a small bmp image on a graphic control

    I got a program that can plot intersection point of 2 straight lines as in the below image, as the round points are mundane looking, I'm looking for a way to place
    nice custom made bitmap images at a certain location on the graphic control

    Click image for larger version

Name:	Intersec pt.png
Views:	176
Size:	5.1 KB
ID:	823981


    can I use a small bitmap and place it on this graphics control at a certain coordinate point such as this image below
    Click image for larger version

Name:	purple up arrow.bmp
Views:	148
Size:	1.7 KB
ID:	823982

    it will make the graphic plot looks better than those mundane looking points ?

    #2
    Still not reading Help?



    User GRAPHIC RENDER if the image is a Resource or file.
    Use GRAPHIC COPY if it's the content of a GRAPHIC BITMAP, WINDOW or CONTROL.
    Use GRAPHIC STRETCH if you wan to change the size of the bitmap when COPYing it.
    =========================
    https://camcopng.com
    =========================

    Comment


      #3
      This will give you something like what you want. Pass the intersection point(or point of interest) to the sub with desired colour.
      Code:
      #COMPILE EXE
      #DIM ALL
      TYPE triangle
       count AS LONG       'this TYPE will be needed
       x1 AS SINGLE
       y1 AS SINGLE
       x2 AS SINGLE
       y2 AS SINGLE
       x3 AS SINGLE
       y3 AS SINGLE
      END TYPE
      
      MACRO PI =ATN(1)*4     ' this will be needed if you don't have something equivalent
      MACRO grp = GRAPHIC PRINT
      FUNCTION PBMAIN () AS LONG
        LOCAL gWin AS LONG
        LOCAL xx, yy AS SINGLE
        GRAPHIC WINDOW NEW "", 100,100,200,200 TO gWin
        GRAPHIC SCALE (0,10)-(10,0)
        indicator 5, 5, %RGB_PURPLE
        GRAPHIC WAITKEY$
        GRAPHIC WINDOW END
      END FUNCTION
      
      SUB indicator(x AS SINGLE, y AS SINGLE, klr AS LONG)  'This sub may need the .5 and .2 values adjusted
        LOCAL imag AS triangle                              'for your scaling
        imag.count=3                                        ' all points are relative to the triangle's centre
        imag.x1=x+(.5)*COS((90*PI)/180)
        imag.y1=y+(.5)*SIN((90*PI)/180)
        imag.x2=x+(.5)*COS((210*PI)/180)
        imag.y2=y+(.5)*SIN((210*PI)/180)
        imag.x3=x+(.5)*COS((330*PI)/180)
        imag.y3=y+(.5)*SIN((330*PI)/180)
        GRAPHIC POLYGON imag, klr, klr
        GRAPHIC WIDTH 3
        GRAPHIC LINE (imag.x2, imag.y2-.2)-(imag.x3, imag.y3-.2)
        GRAPHIC WIDTH 1
      END SUB
      Rod
      In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

      Comment


        #4
        It can be good to look at provided examples. In this case, take a look at your PBWin10\samples\DDT\Graphic\Hitgame\HITGAME.BAS, where GRAPHIC COPY is used to flash a picture at different places. There are other examples in your PBWin10\samples\DDT\Graphic.. folder that will teach many things. PB says about HitGame, "' Shows how to load and show bitmaps stored in a resource file,
        ' how to play wav sound files stored in a resource file,​"
        etc.

        Comment


          #5
          Originally posted by Rodney Hicks View Post
          This will give you something like what you want. Pass the intersection point(or point of interest) to the sub with desired colour.
          May I sugges a small mod? Subtract 0.5 from the "Y"s so that the top point of the triangle is located at the stated coordinates:


          Code:
           SUB indicator(x AS SINGLE, y AS SINGLE, klr AS LONG)  'This sub may need the .5 and .2 values adjusted
            LOCAL imag AS triangle                              'for your scaling
            imag.count=3                                        ' all points are relative to the triangle's centre
            imag.x1=x+(.5)*COS((90*PI)/180)
            imag.y1=y+(.5)*SIN((90*PI)/180)
            imag.x2=x+(.5)*COS((210*PI)/180)
            imag.y2=y+(.5)*SIN((210*PI)/180)
            imag.x3=x+(.5)*COS((330*PI)/180)
            imag.y3=y+(.5)*SIN((330*PI)/180)
            GRAPHIC POLYGON imag, klr, klr
            GRAPHIC WIDTH 3
            GRAPHIC LINE (imag.x2, imag.y2-.2)-(imag.x3, imag.y3-.2)
            GRAPHIC WIDTH 1
          END SUB

          i.e. for 5,5:
          Click image for larger version  Name:	pointcentre.png Views:	0 Size:	2.0 KB ID:	823988rather than Click image for larger version  Name:	centrecentre.png Views:	0 Size:	1.1 KB ID:	823989
          =========================
          https://camcopng.com
          =========================

          Comment


            #6
            Good point, Stuart! (no pun intended)
            Rod
            In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

            Comment


              #7
              Originally posted by Tim Lakinir View Post
              I got a program that can plot intersection point of 2 straight lines as in the below image, as the round points are mundane looking, I'm looking for a way to place
              nice custom made bitmap images at a certain location on the graphic control
              I put a few programs for graphic manipulation in the source code forum a while back.
              These generally use conversion of the bitmap or graphic control to a string, and then
              creation of an array within the string, to allow pixels to be manipulated directly.
              They include the use of multiple small bitmaps on a larger one, as sprites, with transparency.
              The world is strange and wonderful.*
              I reserve the right to be horrifically wrong.
              Please maintain a safe following distance.
              *wonderful sold separately.

              Comment


                #8
                Thank you Sir Rodney, that was very good , thanks all others for their comments and I w'd need to check those sample codes

                Comment


                  #9
                  Modified Rodney's program to have a star shape point

                  Code:
                  ' Graphics Triangle Point.bas
                  ' https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/823980-how-to-place-a-small-bmp-image-on-a-graphic-control?p=823985#post823985
                    ' Great Thanks to Rodney
                    ' Draws Triangular and Star points
                  
                  #COMPILE EXE
                  #DIM ALL
                  
                  TYPE TriangleShape
                    count AS LONG       'this TYPE will be needed
                    x1 AS SINGLE
                    y1 AS SINGLE
                    x2 AS SINGLE
                    y2 AS SINGLE
                    x3 AS SINGLE
                    y3 AS SINGLE
                  END TYPE
                  
                  
                  TYPE StarShape
                    count AS LONG       'this TYPE will be needed
                    x1 AS SINGLE
                    y1 AS SINGLE
                    x2 AS SINGLE
                    y2 AS SINGLE
                    x3 AS SINGLE
                    y3 AS SINGLE
                    x4 AS SINGLE
                    y4 AS SINGLE
                    x5 AS SINGLE
                    y5 AS SINGLE
                  
                    x6 AS SINGLE
                    y6 AS SINGLE
                    x7 AS SINGLE
                    y7 AS SINGLE
                    x8 AS SINGLE
                    y8 AS SINGLE
                  
                  END TYPE
                  
                  
                  
                  
                  
                  
                  MACRO PI =ATN(1)*4     ' this will be needed if you don't have something equivalent
                  
                  
                  
                  
                  FUNCTION PBMAIN () AS LONG
                    LOCAL gWin AS LONG
                    LOCAL xx, yy AS SINGLE
                    GRAPHIC WINDOW NEW "", 100,100,300,300 TO gWin
                    GRAPHIC ATTACH gWin, 0
                     'white background
                      GRAPHIC CLEAR %WHITE
                  
                     GRAPHIC SCALE (0,20)-(20,0)
                  
                     indicator 5, 5, %RGB_PURPLE
                  
                     indicator 3, 2.5,%RGB_MAGENTA
                  
                     TriPt( 10,6, %RGB_DARKGREEN , 0.3)
                  
                     StarPt( 13,9, %RGB_DEEPPINK, 0.3)
                  
                  
                    GRAPHIC WAITKEY$
                    GRAPHIC WINDOW END
                  END FUNCTION
                  
                  
                  
                  
                  SUB indicator(x AS SINGLE, y AS SINGLE, kcolor AS LONG)  'This sub may need the .5 and .2 values adjusted
                    LOCAL imag AS TriangleShape                              'for your scaling
                    imag.count=3                                        ' all points are relative to the triangle's centre
                    imag.x1=x+(.5)*COS((90*PI)/180)
                    imag.y1=y+(.5)*SIN((90*PI)/180) - 0.5
                    imag.x2=x+(.5)*COS((210*PI)/180)
                    imag.y2=y+(.5)*SIN((210*PI)/180) - 0.5
                    imag.x3=x+(.5)*COS((330*PI)/180)
                    imag.y3=y+(.5)*SIN((330*PI)/180) - 0.5
                    GRAPHIC POLYGON imag, kcolor, kcolor
                    GRAPHIC WIDTH 3
                   ' GRAPHIC LINE (imag.x2, imag.y2-.2)-(imag.x3, imag.y3-.2)
                    GRAPHIC WIDTH 1
                  END SUB
                  
                  
                  
                  ' Draw the Triangular point at the stated coordinates xt , yt
                  ' This sub may need the .5 and .2 values adjusted
                  ' for your scaling
                  ' all points are relative to the triangle's centre
                  SUB TriPt(xt AS SINGLE, yt AS SINGLE, kcolor AS LONG, TSize AS SINGLE)
                    LOCAL imag AS TriangleShape
                    imag.count= 3
                    imag.x1=xt + TSize*COS((90*PI)/180)
                    imag.y1=yt + TSize*SIN((90*PI)/180) - TSize
                    imag.x2=xt + TSize*COS((210*PI)/180)
                    imag.y2=yt + TSize*SIN((210*PI)/180) - TSize
                    imag.x3=xt + TSize*COS((330*PI)/180)
                    imag.y3=yt + TSize*SIN((330*PI)/180) - TSize
                    GRAPHIC POLYGON imag, kcolor, kcolor
                    GRAPHIC WIDTH 3
                    GRAPHIC WIDTH 1
                  END SUB
                  
                  
                  
                  
                  ' Draw the Star point at the stated coordinates xt , yt
                  ' This sub may need the .5 and .2 values adjusted
                  ' for your scaling
                  ' all points are relative to the triangle's centre
                  SUB StarPt(xt AS SINGLE, yt AS SINGLE, kcolor AS LONG, TSize AS SINGLE)
                    LOCAL imag AS StarShape
                    LOCAL MSize AS SINGLE
                    MSize = 2
                    imag.count= 8
                    imag.x1=xt + TSize*COS((45*PI)/180)
                    imag.y1=yt + TSize*SIN((45*PI)/180) - TSize
                  
                    imag.x2=xt + MSize*TSize*COS((90*PI)/180)
                    imag.y2=yt + MSize*TSize*SIN((90*PI)/180) - TSize
                  
                    imag.x3=xt + TSize*COS((135*PI)/180)
                    imag.y3=yt + TSize*SIN((135*PI)/180) - TSize
                  
                    imag.x4=xt + MSize*TSize*COS((180*PI)/180)
                    imag.y4=yt + MSize*TSize*SIN((180*PI)/180) - TSize
                  
                    imag.x5=xt + TSize*COS((225*PI)/180)
                    imag.y5=yt + TSize*SIN((225*PI)/180) - TSize
                  
                    imag.x6=xt + MSize*TSize*COS((270*PI)/180)
                    imag.y6=yt + MSize*TSize*SIN((270*PI)/180) - TSize
                  
                    imag.x7=xt + TSize*COS((315*PI)/180)
                    imag.y7=yt + TSize*SIN((315*PI)/180) - TSize
                  
                    imag.x8=xt + MSize*TSize*COS((360*PI)/180)
                    imag.y8=yt + MSize*TSize*SIN((360*PI)/180) - TSize
                  
                  
                    GRAPHIC POLYGON imag, kcolor, kcolor
                    GRAPHIC WIDTH 3
                    GRAPHIC WIDTH 1
                  END SUB
                  
                  
                  ​


                  Click image for larger version

Name:	Star point.png
Views:	121
Size:	506 Bytes
ID:	823994

                  Comment


                    #10
                    FWIW, one could easily add an optional parameter(0 to 3) for orientation so the triangle could point in any one of the four directions. Adding the size was a good modification.
                    Rod
                    In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                    Comment


                      #11
                      Originally posted by Rodney Hicks View Post
                      FWIW, one could easily add an optional parameter(0 to 3) for orientation so the triangle could point in any one of the four directions. Adding the size was a good modification.


                      '
                      Code:
                      #COMPILE EXE
                      #DIM ALL
                      TYPE triangle
                       count AS LONG       'this TYPE will be needed
                       x1 AS SINGLE
                       y1 AS SINGLE
                       x2 AS SINGLE
                       y2 AS SINGLE
                       x3 AS SINGLE
                       y3 AS SINGLE
                      END TYPE
                      
                      MACRO d2r = 0.0174532925199432958## 'Degrees to radians
                      
                      FUNCTION PBMAIN () AS LONG
                        LOCAL gWin AS LONG
                        LOCAL xx, yy AS SINGLE
                        GRAPHIC WINDOW NEW "", 100,100,300,300 TO gWin
                        GRAPHIC SCALE (0,100)-(100,0)
                        GRAPHIC LINE (0,0)-(100,100)
                        GRAPHIC LINE (100,0)-(0,100)
                      
                        indicator 50,50,0,100, %RGB_RED
                        indicator 50,50,1,150, %RGB_YELLOW
                        indicator 50,50,2,200, %RGB_GREEN
                        indicator 50,50,3,50, %RGB_BLUE
                      
                      
                        GRAPHIC WAITKEY$
                        GRAPHIC WINDOW END
                      END FUNCTION
                      
                      SUB indicator(x AS SINGLE, y AS SINGLE,direction AS LONG ,scalepercent AS LONG, klr AS LONG)  'This sub may need the .5 and .2 values adjusted
                        LOCAL imag AS triangle
                        LOCAL head,xx,yy AS LONG
                        LOCAL sf AS EXT
                      
                        sf = scalepercent/20
                        SELECT CASE direction ' rotate right
                            CASE 0: head = 0: y-= sf     'point up
                            CASE 1: head = 270: x -= sf  'point left
                            CASE 2: head = 180: y += sf  'point down
                            CASE 3: head = 90:x += sf  'point right
                        END SELECT
                                                            'for your scaling
                        imag.count=3
                        imag.x1=x+sf*COS((head+90)*d2r)
                        imag.y1=y+sf*SIN((head+90)*d2r)
                        imag.x2=x+sf*COS((head+210)*d2r)
                        imag.y2=y+sf*SIN((head+210)*d2r)
                        imag.x3=x+sf*COS((head+330)*d2r)
                        imag.y3=y+sf*SIN((head+330)*d2r)
                                                             ' all points are relative to the triangle's centre
                        GRAPHIC POLYGON imag, klr, klr
                      END SUB
                      '


                      Click image for larger version

Name:	pointcentre2.png
Views:	108
Size:	2.9 KB
ID:	823999
                      =========================
                      https://camcopng.com
                      =========================

                      Comment

                      Working...
                      X
                      😀
                      🥰
                      🤢
                      😎
                      😡
                      👍
                      👎