Results 1 to 17 of 17

Thread: vbRichClient5 - DrawToDC , how to GetFromDC ?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2010
    Location
    Italy
    Posts
    516

    vbRichClient5 - DrawToDC , how to GetFromDC ?

    hi

    vbRichClient5 support the Srf.DrawToDC function, but seems not to have a Srf.GetFromDC...


    how can I Draw to a Cairo Surface the content of a PictureBox ?

    Thanks

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

    Re: vbRichClient5 - DrawToDC , how to GetFromDC ?

    Quote Originally Posted by reexre View Post
    vbRichClient5 support the Srf.DrawToDC function, but seems not to have a Srf.GetFromDC...
    how can I Draw to a Cairo Surface the content of a PictureBox ?
    This "opposite direction" is very rarely needed, since anything you can do on
    a PictureBox, you can do equally well on a Surface directly instead...

    But there's a Surface-Type, which hands out a normal GDI-hDC for GDI-ops,
    creatable per Cairo.CreateWin32Surface(PxlWidth, PxlHeight)...

    Drawing per GDI against such a "Surface-hDC" comes with a caveat though...
    Cairo-PixelSurfaces are generally 32Bit-BGRA (with premultiplied Alpha) -
    and after initalization contain "fully transparent Black" (all Bytes zero, including
    all the Alpha-bytes).

    Now, when you draw against such a "Surface-hDC-DIB", Win-GDI will not care about
    the Alpha-channel, leaving the Alphabytes alone (at Zero, or overwriting them
    with Zeros).

    One of the few Calls, which handle Alpha(Blitting) properly in this case, is GDI-AlphaBlend
    (when fed with proper Arguments).

    Below is an example, which is using "straight GDI-BitBlt", to show what one can do
    about that, *after* the GDI-Ops are finished on that Surface (and further Cairo-Drawing
    on that Surface is planned)...

    Code:
    Private Declare Function BitBlt& Lib "gdi32" (ByVal hDCDst&, ByVal x&, ByVal y&, ByVal dx&, ByVal dy&, ByVal hDCSrc&, ByVal xSrc&, ByVal ySrc&, ByVal dwRop&)
    
    Private Sub Form_Load() 'draw a small rectangle on the Form, so that we have something to "Blit-From"
      AutoRedraw = True
      ScaleMode = vbPixels
      Line (0, 0)-(99, 99), vbGreen, BF
      DrawWidth = 4
      Line (10, 10)-(90, 90), vbRed, B
    End Sub
    
    Private Sub Form_Click()
      Dim Srf As cCairoSurface, B() As Byte
      Set Srf = Cairo.CreateWin32Surface(100, 100)
    
      BitBlt Srf.GetDC, 0, 0, 100, 100, Me.hDC, 0, 0, vbSrcCopy
    
      Srf.BindToArray B 'just to give proof, that the Alpha-Bytes are indeed Zero and not 255
        Debug.Print "AlphaValue of the TopLeft-Pixel"; B(3, 0), "Arr-Bounds:"; UBound(B, 1), UBound(B, 2)
      Srf.ReleaseArray B 'release the Mapping of the ByteArray to the Surface
      
      'correct potential Alpha-Errors from the GDI-Operation above
      '(since Cairo-Surfaces are equal to premultiplied 32Bit-BGRA-DIBs, and
      ' the above GDI-Operation was not providing Alpha=255 in the A-Byte)
      'The GDI-AlphaBlend-call is one of the few, where this is not necessary.
      With Srf.CreateContext
        .Operator = CAIRO_OPERATOR_DEST_ATOP
        .Paint 1, Cairo.CreateSolidPatternLng(vbBlack) 'after this call, all Alpha-Bytes are at 255
      End With
      
      Srf.BindToArray B 'let's check again...
        Debug.Print "AlphaValue of the TopLeft-Pixel"; B(3, 0), "Arr-Bounds:"; UBound(B, 1), UBound(B, 2)
      Srf.ReleaseArray B
      
      Srf.DrawToDC Me.hDC, 100, 100 'normal Blit-Output from the Surface, back to the Form.hDC
      Refresh
    End Sub
    In case you want to avoid APIs (and prefer using VBs built-in Drawing-Routines,
    as e.g. PaintPicture or Line, Circle etc. against Cairo-Surfaces, there's an alternative,
    which involves instancing of a kind of "PictureBox" first (a Widget-PanelControl with an hWnd).

    The below code does the same as the snippet above, but without using any GDI-APIs
    or any need for "Alpha-considerations" (VBs Line or Circle-commands would be drawn
    antialiased in this mode too - though the example below does only PaintPicure, to keep
    it simple and mimick only the BitBlt-call from above).

    Code:
    Private Sub Form_Load() 'draw a small rectangle on the Form, so that we have something to "Blit-From"
      AutoRedraw = True
      ScaleMode = vbPixels
      Line (0, 0)-(99, 99), vbGreen, BF
      DrawWidth = 4
      Line (10, 10)-(90, 90), vbRed, B
    End Sub
     
    Private Sub Form_Click()
      Dim Panel As cWidgetForm '<- this is similar to a VB-PictureBox (a ChildControl with a hWnd)
      Set Panel = Cairo.WidgetForms.CreateChild(hWnd, False, False, False) 'similar to Controls.Add of a PictureBox to the Form
          Panel.Move 0, 0, 100, 100 'give our (created with Visible=False) "Panel-Box" the right size
    
      Dim Drw As Printer 'since each WidgetRoot-BaseCanvas implements a VB.Printer-DrawingInterface, we can...
      Set Drw = Panel.WidgetRoot.VBDrawing  '...get that interface from the WidgetRoot-Canvas...
          Drw.PaintPicture Me.Image, 0, 0 'and perform normal VB-Drawing-Ops on it (PaintPicture included)
    
      Dim Srf As cCairoSurface 'let's retrieve the Srf-Object we have drawn to just now (per PaintPicture) ...
      Set Srf = Panel.WidgetRoot.Widget.BackBuffer 'copy-over the *reference* to the Backing-Surface ...
      Panel.Unload 'to prevent it from being destroyed along with the (now unnecessary) "Panel-Box"
    
      Srf.DrawToDC Me.hDC, 100, 100 'the rest is normal Surface-stuff again, as in the other example
      Refresh
    End Sub
    HTH

    Olaf

  3. #3
    Fanatic Member
    Join Date
    Aug 2013
    Posts
    806

    Re: vbRichClient5 - DrawToDC , how to GetFromDC ?

    Quote Originally Posted by Schmidt View Post
    This "opposite direction" is very rarely needed, since anything you can do on
    a PictureBox, you can do equally well on a Surface directly instead...

    But there's a Surface-Type, which hands out a normal GDI-hDC for GDI-ops,
    creatable per Cairo.CreateWin32Surface(PxlWidth, PxlHeight)...
    I could be mistaken, but it sounds like OP was looking for something like "create cairo surface from existing Win32 hDC"...? In which case I think the appropriate underlying function would be:

    Code:
    cairo_win32_surface_create (HDC hdc);
    ...per the cairo manual.

    My apologies for not knowing what the matching vbRichClient wrapper function is, but I believe the OP's looking for a function that takes a DC as input, and returns a Cairo surface with matching contents...?
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

  4. #4
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,930

    Re: vbRichClient5 - DrawToDC , how to GetFromDC ?

    Quote Originally Posted by Tanner_H View Post
    I could be mistaken, but it sounds like OP was looking for something like "create cairo surface from existing Win32 hDC"...?
    Dunno, Reexre would have to give a bit more info about what he really needs this for...
    To me it sounded, like he was only interested "to copy pixels over into a Surface in a fast way per GDI"
    (using BitBlt as the fastest "Pixel-Mover" which GDI has to offer for that task).

    Quote Originally Posted by Tanner_H View Post
    In which case I think the appropriate underlying function would be:
    Code:
    cairo_win32_surface_create (HDC hdc);
    ...per the cairo manual.
    I've used this years ago in my early experiments with cairo - but as described in the manual,
    it will be backed up (and work) *only* with a 24Bit-cairo-Pixel-surface (to avoid the Alpha-issues I described).

    I later decided, to allow only one single cairo-pixelformat in my wrapper (32Bit-BGRA),
    to keep things straight and consistent, also avoiding Padding-issues when accessing the
    underlying Bytes of a Surface directly (as shown in the BindArray-Functions in my small example #1 above).

    It's a common approach in most modern GUI-frameworks (for the Desktop at least) - and
    most graphics-cards and OS-defaults match this 32Bit-setting in the "hardware-queue further down"
    (so there's usually no conversions necessary in the "final Blits to the Screen").


    Quote Originally Posted by Tanner_H View Post
    ... I believe the OP's looking for a function that takes a DC as input, and returns a Cairo surface with matching contents...?
    Well, with two small Helper-Functions (in analogy to example #1), this can be
    accomplished in a less noisy way, as shown in the example below:

    Code:
    Option Explicit
    
    Private Declare Function BitBlt& Lib "gdi32" (ByVal hDCDst&, ByVal x&, ByVal y&, ByVal dx&, ByVal dy&, ByVal hDCSrc&, ByVal xSrc&, ByVal ySrc&, ByVal dwRop&)
    
    Private Sub Form_Load() 'ensure a small rectangle on the Form, so that we have something to Blit-From
      AutoRedraw = True
      ScaleMode = vbPixels
      Line (0, 0)-(99, 99), vbGreen, BF
      DrawWidth = 4
      Line (10, 10)-(90, 90), vbRed, B
    End Sub
    
    Function BltIntoSurface(Srf As cCairoSurface, x, y, dx, dy, hDCSrc As Long, xSrc, ySrc) As cCairoContext
      If Srf.GetDC = 0 Then Err.Raise vbObjectError, , "we need a Surface of type 'Cairo.CreateWin32Surface' here"
      BitBlt Srf.GetDC, x, y, dx, dy, hDCSrc, xSrc, ySrc, vbSrcCopy
      Set BltIntoSurface = Srf.CreateContext
    End Function
    
    Sub CorrectAlpha(CC As cCairoContext)
      CC.Save
        CC.Operator = CAIRO_OPERATOR_DEST_ATOP
        CC.Paint 1, Cairo.CreateSolidPatternLng(vbBlack) 'after this call, all Alpha-Bytes are at 255
      CC.Restore 'restore the former Operator-Settings on this CairoContext
    End Sub
    
    Private Sub Form_Click()
      Dim CC As cCairoContext
      Set CC = BltIntoSurface(Cairo.CreateWin32Surface(100, 100), 0, 0, 100, 100, Me.hDC, 0, 0)
      'more GDI-calls are possible here, using the Dest-hDC, retrievable per CC.Surface.GetDC  
    
      CorrectAlpha CC '<- and this is only needed, ...
      
      '...when we plan to draw further on this Surface per Cairo
        CC.SetLineWidth 4
        CC.ARC 50, 50, 25
        CC.Operator = CAIRO_OPERATOR_DIFFERENCE '...with this operator
        CC.SetSourceColor vbYellow '<- ...and this Color (given the green background)
        CC.Stroke '...the Stroking should paint a red bordered circle as the result
      '...just comment out the CorrectAlpha-Call above, to see the difference
      
      CC.Surface.DrawToDC Me.hDC, 100, 100 'normal Blit-Output from the Surface to the Form.hDC
      Refresh
    End Sub
    Despite the code above (which allows to work with GDI against cairo-pixel-surfaces),
    I still would like to know, in which scenarios this should be needed ... (having written
    a whole lot of code and examples around cairo - and never felt a need to use the
    wrappers CreateWin32Surface-method).
    So - it's there, but apparently superfluous in practice.

    Olaf

  5. #5
    Fanatic Member
    Join Date
    Aug 2013
    Posts
    806

    Re: vbRichClient5 - DrawToDC , how to GetFromDC ?

    In my case, the most common use-case is windowless controls, when I need drawing libraries other than plain GDI.

    Making your own internal copy of the DC on every Paint event is expensive, so it's much easier to simply "wrap" your preferred image surface around the DC. (GDI+ does this, for example, with GdipCreateFromHDC, so you can paint directly to a DC using GDI+ instructions, while maintaining things like clipping extents).

    The alternative is creating a copy of the DC in your preferred surface format, painting to that copy, then copying your copy over the original... too much copying involved.

    I agree that it's unfortunate for Cairo to force the resulting surface to 24-bpp, but at least that resolves the ambiguity of GDI's messy alpha-channel handling. I too prefer the "maintain 32-bpp and fill the alpha channel with 255 as necessary" approach, and I'd be curious to know why they don't just do that, given their insistence on 32-bpp in most places throughout the library...? (Unfortunately, their source comments don't elaborate, except to say /* Assume that everything coming in as a HDC is RGB24 */)
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

  6. #6
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,930

    Re: vbRichClient5 - DrawToDC , how to GetFromDC ?

    Quote Originally Posted by Tanner_H View Post
    In my case, the most common use-case is windowless controls, when I need drawing libraries other than plain GDI.
    Do you have a properly working example for a small windowless Usercontrol, where you used a GDI+ Binding?
    (I've looked over your sources in PhotoDemon, but didn't find any such Controls to see how you did that concretely).

    Will really only need to be a simple one (e.g. rendering a transparent Png in its drawing-routine).

    Olaf

  7. #7
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,120

    Re: vbRichClient5 - DrawToDC , how to GetFromDC ?

    wrt to the OP, I normally do this via the following function (needs a reference to olelib.tlb)

    Code:
    Public Function StdPictureToByteArray(ByVal image As StdPicture) As Byte()
    Dim abData() As Byte
    Dim oPersist As IPersistStream
    Dim oStream As IStream
    Dim lSize As Long
    Dim tStat As STATSTG
    
       Set oPersist = image
       Set oStream = CreateStreamOnHGlobal(0, True)
       oPersist.Save oStream, True
       oStream.Stat tStat, STATFLAG_NONAME
       lSize = tStat.cbSize * 10000
    
       ReDim abData(0 To lSize - 1)
    
       oStream.Seek 0, STREAM_SEEK_SET
       oStream.Read abData(0), lSize
       
       StdPictureToByteArray = abData
       
       Set oStream = Nothing
    
    End Function
    Then I can call that with

    Set Srf = Cairo.CreateSurface(0, 0, , StdPictureToByteArray(YourStdPictureObject))
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  8. #8
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,120

    Re: vbRichClient5 - DrawToDC , how to GetFromDC ?

    Ooh, meant to ask...

    @Olaf: Can I do the above with RC5's cStream class? Wasn't obvious to me how...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2010
    Location
    Italy
    Posts
    516

    Re: vbRichClient5 - DrawToDC , how to GetFromDC ?

    Quote Originally Posted by Schmidt View Post

    I've used this years ago in my early experiments with cairo - but as described in the manual,
    it will be backed up (and work) *only* with a 24Bit-cairo-Pixel-surface (to avoid the Alpha-issues I described).

    I later decided, to allow only one single cairo-pixelformat in my wrapper (32Bit-BGRA),
    to keep things straight and consistent, also avoiding Padding-issues when accessing the
    underlying Bytes of a Surface directly (as shown in the BindArray-Functions in my small example #1 above).

    It's a common approach in most modern GUI-frameworks (for the Desktop at least) - and
    most graphics-cards and OS-defaults match this 32Bit-setting in the "hardware-queue further down"
    (so there's usually no conversions necessary in the "final Blits to the Screen").




    Well, with two small Helper-Functions (in analogy to example #1), this can be
    accomplished in a less noisy way, as shown in the example below:

    Code:
    Option Explicit
    
    Private Declare Function BitBlt& Lib "gdi32" (ByVal hDCDst&, ByVal x&, ByVal y&, ByVal dx&, ByVal dy&, ByVal hDCSrc&, ByVal xSrc&, ByVal ySrc&, ByVal dwRop&)
    
    Private Sub Form_Load() 'ensure a small rectangle on the Form, so that we have something to Blit-From
      AutoRedraw = True
      ScaleMode = vbPixels
      Line (0, 0)-(99, 99), vbGreen, BF
      DrawWidth = 4
      Line (10, 10)-(90, 90), vbRed, B
    End Sub
    
    Function BltIntoSurface(Srf As cCairoSurface, x, y, dx, dy, hDCSrc As Long, xSrc, ySrc) As cCairoContext
      If Srf.GetDC = 0 Then Err.Raise vbObjectError, , "we need a Surface of type 'Cairo.CreateWin32Surface' here"
      BitBlt Srf.GetDC, x, y, dx, dy, hDCSrc, xSrc, ySrc, vbSrcCopy
      Set BltIntoSurface = Srf.CreateContext
    End Function
    
    Sub CorrectAlpha(CC As cCairoContext)
      CC.Save
        CC.Operator = CAIRO_OPERATOR_DEST_ATOP
        CC.Paint 1, Cairo.CreateSolidPatternLng(vbBlack) 'after this call, all Alpha-Bytes are at 255
      CC.Restore 'restore the former Operator-Settings on this CairoContext
    End Sub
    
    Private Sub Form_Click()
      Dim CC As cCairoContext
      Set CC = BltIntoSurface(Cairo.CreateWin32Surface(100, 100), 0, 0, 100, 100, Me.hDC, 0, 0)
      'more GDI-calls are possible here, using the Dest-hDC, retrievable per CC.Surface.GetDC  
    
      CorrectAlpha CC '<- and this is only needed, ...
      
      '...when we plan to draw further on this Surface per Cairo
        CC.SetLineWidth 4
        CC.ARC 50, 50, 25
        CC.Operator = CAIRO_OPERATOR_DIFFERENCE '...with this operator
        CC.SetSourceColor vbYellow '<- ...and this Color (given the green background)
        CC.Stroke '...the Stroking should paint a red bordered circle as the result
      '...just comment out the CorrectAlpha-Call above, to see the difference
      
      CC.Surface.DrawToDC Me.hDC, 100, 100 'normal Blit-Output from the Surface to the Form.hDC
      Refresh
    End Sub
    Thank You !!!!
    this is what I needed

    My use it to add a ("cairo drawn")watermark to a (Photo)Picture and then save it.

    Don't know, maybe there is a simpler way , without vbRichClient .....
    But to do it with quality (AntiAliased Alpha lines - or Text ... ) I thought to use vbRichClient

  10. #10
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,930

    Re: vbRichClient5 - DrawToDC , how to GetFromDC ?

    Quote Originally Posted by reexre View Post
    My use it to add a ("cairo drawn")watermark to a (Photo)Picture and then save it.

    Don't know, maybe there is a simpler way , without vbRichClient .....
    There surely *is* a simpler way (using the RichClient)...
    Meaning, you could load or handle your Images Pixel-Data directly in Cairo-Surfaces
    (they allow loading of all kind of images, as well as saving to PNG or JPG or BMP, and also allow
    direct Pixel-Manipulation within them over two types of bindable Arrays, Long- and ByteArrays).

    This way, you would not need such a special "hDC-capable" cairo-surface in the first place -
    and could draw your watermark directly onto such a surface (before your saving takes place -
    the saving also possible directly from a Surface).

    Olaf

  11. #11
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,930

    Re: vbRichClient5 - DrawToDC , how to GetFromDC ?

    Quote Originally Posted by ColinE66 View Post
    Ooh, meant to ask...

    @Olaf: Can I do the above with RC5's cStream class? Wasn't obvious to me how...
    No, although internally a Systems IStream is wrapped, I currently do not expose this private variable
    to the outside of the cStream-Class (having the porting to other OSes in mind, where the internal
    implementation of cStream might look a bit different).

    But since there's Exceptions (with regards to Win-only-stuff) in other classes already,
    it'd be good to keep that enhancement about an additional Property in mind (for RC-Version-6)...

    Olaf

  12. #12
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,930

    Re: vbRichClient5 - DrawToDC , how to GetFromDC ?

    @Tanner
    In case you want to take a look...
    Just uploaded a small (cairo-based) windowless-control demo into the codebank.
    http://www.vbforums.com/showthread.p...less-Controls)

    Though each control is being backed up by a cairo-surface (in the same PixelSize)
    (but only re-allocated and re-sized in the UserControl_Resize-event).

    ScreenShot:



    Seems that GDI+ is (in theory) capable to manage that more efficiently (memory-wise), in case
    your mentioned "wrapping around a hDC" works well (in conjunction with VB6-Windowless-controls).

    But I've made good experiences with this kind of double-buffering with regards to speed,
    (saving vector-renderings when a Controls State didn't change... the RC5-Widgets work on the same principle)...

    Regards,

    Olaf
    Last edited by Schmidt; Apr 5th, 2015 at 04:56 PM.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2010
    Location
    Italy
    Posts
    516

    Re: vbRichClient5 - DrawToDC , how to GetFromDC ?

    Quote Originally Posted by Schmidt View Post
    they allow loading of all kind of images, as well as saving to PNG or JPG or BMP, and also allow
    direct Pixel-Manipulation within them over two types of bindable Arrays, Long- and ByteArrays
    Interesting!

    I suppose the Array for a 4x4 pixel SRF is of this form:

    BGRA BGRA BGRA BGRA
    BGRA BGRA BGRA BGRA
    BGRA BGRA BGRA BGRA
    BGRA BGRA BGRA BGRA

    So the Byte array of a 4x4 pixels SRF will have 4x4x4 Bytes?
    and the Long Array ?

    is there already some example/tutorial.?..
    thanks

  14. #14
    Fanatic Member
    Join Date
    Aug 2013
    Posts
    806

    Re: vbRichClient5 - DrawToDC , how to GetFromDC ?

    @reexre, sorry in advance for hijacking your thread.

    Quote Originally Posted by Schmidt View Post
    Do you have a properly working example for a small windowless Usercontrol, where you used a GDI+ Binding?
    Attached is a quick and dirty demo. Click-drag anywhere on the blue underlying form, and GDI+ will resize the demo user control, and render a semi-transparent white rectangle over the DC supplied by the Paint event.

    GDIPlus user control.zip

    Name:  GDIPlus user control.jpg
Views: 735
Size:  19.2 KB

    One of the really obnoxious things about Windows development is that you're stuck working with GDI whether you want to or not. Window messages return all kinds of GDI handles, so even if you prefer another drawing library, you eventually have to coerce stuff into GDI formats (fonts, DDBs, etc).

    Anyway, for us unfortunate souls who have to manually subclass various paint-related functions, the ability to wrap a DC with some other surface is a huge help.

    Subclassed paint events aren't the only use-case. I often wrap GDI+ around existing DCs with DIBs already selected into them. This is great for mixed GDI/GDI+ rendering (e.g. use GDI for font rendering, then GDI+ for antialiased curves), without having to move the image between surface formats. (Although for images specifically, I guess cairo already offers this, via cairo_image_surface_create_for_data.)

    But I've made good experiences with this kind of double-buffering with regards to speed,
    (saving vector-renderings when a Controls State didn't change... the RC5-Widgets work on the same principle)...
    I actually prefer the same thing - manual double-buffering - which is why I don't generally use windowless controls in my own projects. (Flickering is a real monster to deal with, especially when you want to cover all possible configurations of display modes and themes from XP through Win 10.) But I see a lot of forum users using them for whatever reason, so thought I'd mention it, along with other use-cases where "losslessly wrapping one surface around another" can be both convenient and performance-friendly.
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

  15. #15
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,120

    Re: vbRichClient5 - DrawToDC , how to GetFromDC ?

    Quote Originally Posted by Schmidt View Post

    But since there's Exceptions (with regards to Win-only-stuff) in other classes already,
    it'd be good to keep that enhancement about an additional Property in mind (for RC-Version-6)...

    Olaf
    That would be a welcome addition...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  16. #16
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,930

    Re: vbRichClient5 - DrawToDC , how to GetFromDC ?

    Quote Originally Posted by reexre View Post
    I suppose the Array for a 4x4 pixel SRF is of this form:

    BGRA BGRA BGRA BGRA
    BGRA BGRA BGRA BGRA
    BGRA BGRA BGRA BGRA
    BGRA BGRA BGRA BGRA

    So the Byte array of a 4x4 pixels SRF will have 4x4x4 Bytes?
    Yes to all...

    Quote Originally Posted by reexre View Post
    and the Long Array ?
    ...is of course "spanned" over the same amount of bytes,
    and will be organized with a (4 times lower) x-Ubound as:

    32BitValue 32BitValue 32BitValue 32BitValue
    32BitValue 32BitValue 32BitValue 32BitValue
    32BitValue 32BitValue 32BitValue 32BitValue
    32BitValue 32BitValue 32BitValue 32BitValue

    As already mentioned, Cairo-Image-Surfaces are *always* 32Bit BGRA in my wrapper,
    the Start-Pointer to their memory-allocation can be retrieved per:
    cCairoSurface.DataPtr

    and the allocated size in Bytes can be calculated (e.g. when used with CopyMemory & Co.) per:
    Srf.Width * Srf.Height * 4
    or alternatively per
    Srf.Stride * Srf.Height

    Quote Originally Posted by reexre View Post
    is there already some example/tutorial.?..
    I've just uploaded an (Edge-Detection) example, where the Array-Mapping
    (for both, ByteArrays and LongArrays) is demonstrated:
    http://www.vbforums.com/showthread.p...airo-Surfaces)

    If you have further questions about the Image-Surfaces in that access-mode,
    we can continue the discussion over there...

    Olaf

  17. #17

    Re: vbRichClient5 - DrawToDC , how to GetFromDC ?

    I am interested in this topic, thank the experts advise ...

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