Results 1 to 3 of 3

Thread: RC6: Rendering parts of one cairo surface to another

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    513

    Question RC6: Rendering parts of one cairo surface to another

    Hello!

    I am loading an image of a button into a cairo surface.

    I have attached it.Name:  longkey.png
Views: 70
Size:  3.6 KB

    I want to render this button as various sizes without stretching it.
    Therefore I try to render the top left corner to another surface, then the top right corner, then the top middle section (in a stretched way to allow for different button sizes).

    I believe this approach is well know.

    I am stuck because RC6 RenderSurface does not behave like BitBlt which has 2 more parameters. Instead it creates a stretched render.

    Can somebody suggest a solution?

    I have attached another version on which numbers are printed that show where stretching / shrinking occurs.

    Thank you.
    Attached Images Attached Images  

  2. #2
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,494

    Re: RC6: Rendering parts of one cairo surface to another

    Not sure if there's a better way, but one option would be to create a rectangle path for each corner at the size you want, then call TranslateDrawings to "offset" the rendering, and finally Fill the path with a surface pattern. Something like this:

    Code:
       Cairo.ImageList.AddImage "button", "path to a button image file"   ' Add a button image to the Cairo ImageList with the key "button"
       
       With New_c.Cairo.CreateSurface(1000, 1000)
          With .CreateContext
             .Rectangle 100, 100, 16, 16   ' Create a 16x16 rectangle path at 100px from the top-left corner of the surface
             .TranslateDrawings 100, 100   ' Translate the drawings so the top-left corner of the button surface appears at 100x100
             .Fill , Cairo.ImageList("button").CreateSurfacePattern   ' Fill the path with the button image
          End With
       End With

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    513

    Re: RC6: Rendering parts of one cairo surface to another

    Thank you. It works.
    It even works when I draw a rectangle that exceeds the size of the surface. I expected that this would throw an error, but it does not.

    I don't understand why these 2 arguments were left out that would make RenderSurfaceContent behave like BitBlt. I miss that, and while you have shown me a solution now, I find it unexcepted that I must do it like this.
    ps: I really really like the syntax of cCairoSurface and cCairoContext. It is very beautiful code! That is why I ask myself what the deal with the 2 left-out arguments is.
    Last edited by tmighty2; Sep 14th, 2024 at 11:35 PM.

Tags for this Thread

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