dcsimg
Results 1 to 3 of 3

Thread: Show image using RC5

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2016
    Posts
    86

    Show image using RC5

    Hello Schmidt

    I am trying to start with RC5 by showing a simple image in some designated area of an existing project's form, let's call it Form1. I included a reference to vbRichClient5. I have a few questions.

    1. The first few simple "CairoTutorial" demos all rely on a mouse click on the form before anything happens. In "1 Hello World", when I moved the contents of "Form_Click()" into "Form_Load()" and ran it, the form was empty, "Hello Cairo" did not appear. How do you get things to show on a form without requiring a click?

    2. What sort of controls can I use to draw a cairo surface over? If I want to show a cairo surface in a designated area on my pre-existing form, do I have to use a control with an hDC, so a "Picture"? Are there any "cheaper" controls, or other ways of tying a cairo surface to something I can visually drag and position in a form at design time?

    3. How do you get an image to perpetually rotate, let's say 360 per second, do I use a Timer or does Cairo have some tricks for that?

    4. How do you get an animated GIF to animate? I tried using this random image, it was displayed but did not animate: https://www.thisiscolossal.com/wp-co...Isopoly_01.gif

  2. #2
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,322

    Re: Show image using RC5

    Sorry for the late reply - but too many questions at once often cause a "down-shifting" on my "todo-later-stack" (with the risk of "falling out" at some time)...

    Quote Originally Posted by OldClock View Post
    1. The first few simple "CairoTutorial" demos all rely on a mouse click on the form before anything happens. In "1 Hello World", when I moved the contents of "Form_Click()" into "Form_Load()" and ran it, the form was empty, "Hello Cairo" did not appear. How do you get things to show on a form without requiring a click?
    The probably easiest way is, to cover the entire Form-Background (DoubleBuffering with a Cairo-Surface as BackGround-Image-Holder).
    Here is the minimum-code, how you can achieve that in a "standard-VB-Form" (leaving AutoRedraw at False, since Cairo does the DoubleBuffering already).
    Code:
    Option Explicit
    
    Private BBuf As cCairoSurface 'a fully Form-Covering BBuf-DIB (here encapsulated by a Cairo-Surface-Object)
     
    Private Sub Form_Resize()
      ScaleMode = vbPixels: Set BBuf = Cairo.CreateSurface(ScaleWidth, ScaleHeight) 'ensure a fully Form-covering BackBuf-Surface
      RedrawBBuf BBuf.CreateContext
    End Sub
     
    Private Sub RedrawBBuf(CC As cCairoContext) 'that's the Refresh-Routine you will have to call, when you want to reflect changes on your BackGround
      CC.Paint 1, Cairo.CreateSolidPatternLng(Me.BackColor) 'erase and redraw the background in Form.BackColor
     
      CC.TextOut 5, 5, "Hello Cairo-Form-BackGround" 'example for a drawing call on your new, dynamic Form-Background
      
      BBuf.DrawToDC Me.hDC 'draw the now refrehed contents of BBuf immediately to the Form
    End Sub
     
    Private Sub Form_Paint() 'since the Form is not defined with AutoRedraw=True, this event will happen occasionally...
      BBuf.DrawToDC Me.hDC '...and so we will have to ensure proper Form-BG-Refreshs from the contents of our current BBuf-Surface
    End Sub
    
    Private Sub Form_Terminate()
      New_c.CleanupRichClientDll
    End Sub
    Quote Originally Posted by OldClock View Post
    2. What sort of controls can I use to draw a cairo surface over? If I want to show a cairo surface in a designated area on my pre-existing form, do I have to use a control with an hDC, so a "Picture"? Are there any "cheaper" controls, or other ways of tying a cairo surface to something I can visually drag and position in a form at design time?
    The cheapest way is, to just use a Cairo-Surface-Instance as a "non-visual-Control-like Object".
    You can draw such a Surface at any position on the Forms BBuf-Surface via CC.RenderSurfaceContent
    (e.g. when using the approach under your question 1, you will have to add an additional line:
    Code:
    Private Sub RedrawBBuf(CC As cCairoContext) 'that's the Refresh-Routine you will have to call, when you want to reflect changes on your BackGround
      CC.Paint 1, Cairo.CreateSolidPatternLng(Me.BackColor) 'erase and redraw the background in Form.BackColor
      
      CC.RenderSurfaceContent MyCairoSurfaceInACertainPixelSize, 50, 50 'draw a "SubSurface" on the BackGround-Surface with a 50,50 x,y PixelOffset
      CC.TextOut 5, 5, "Hello Cairo-Form-BackGround" 'example for a drawing call on your new, dynamic Form-Background
      
      BBuf.DrawToDC Me.hDC 'draw the now refrehed contents of BBuf immediately to the Form
    End Sub
    Quote Originally Posted by OldClock View Post
    3. How do you get an image to perpetually rotate, let's say 360 per second, do I use a Timer or does Cairo have some tricks for that?
    The following Demo is rotating a Roulette.png Image (using the BBuff-approach as shown under 1):
    RouletteCairo.zip

    Here is a ScreenShot:


    Quote Originally Posted by OldClock View Post
    4. How do you get an animated GIF to animate? I tried using this random image, it was displayed but did not animate
    There was a thread for that already (with a little cGifFrames.cls from me, which does not require GDIPlus to load the animated GIF-frames):
    http://www.vbforums.com/showthread.p...t-Animated-GIF

    I've just tested it with the GIF-link you've posted - and it seems to work well with that image.

    Olaf

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2016
    Posts
    86

    Re: Show image using RC5

    Fantastic, thank you, this will keep me busy for a while.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width