Buffered Graphics Class
Buffered Graphics Class
Buffered Graphics Class
Buffered Graphics Class
Buffered Graphics Class
Buffered Graphics Class Buffered Graphics Class Buffered Graphics Class Buffered Graphics Class Buffered Graphics Class Buffered Graphics Class Buffered Graphics Class Buffered Graphics Class
Buffered Graphics Class Buffered Graphics Class
Buffered Graphics Class
Go Back  Xtreme Visual Basic Talk > > > Buffered Graphics Class


Reply
 
Thread Tools Display Modes
  #21  
Old 02-22-2013, 10:00 PM
CodeCruncher CodeCruncher is offline
Junior Contributor
 
Join Date: Jul 2006
Posts: 355
Default


Just trying to work out what I need to substitute in here...

Code:
        Dim destRect As New Rectangle(0, 0, ctrl.ClientRectangle.Width, ctrl.ClientRectangle.Height) 'The destination is always the full client area
        Dim srcRect As New Rectangle(dx, 0, ctrl.ClientRectangle.Width, ctrl.ClientRectangle.Height) 'The source X "scrolls" to pick the area to transfer
        bgfx.Graphics.DrawImage(ScrapBmp, destRect, srcRect, GraphicsUnit.Pixel) 'Draw the scrolled portion of the Bitmap to our BufferedGraphics
        bgfx.Render()  'Render it to the screen
I figure I dont need one of destRect or srcRect as I'm not moving the image at this point.

But just trying to work out what I put in "Image" in place of ScrapBmp if I dont want to use it.
Reply With Quote
  #22  
Old 02-22-2013, 10:32 PM
passel's Avatar
passelBuffered Graphics Class passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Interestingly, I finished installing 2012 and the example ran fine regardless of whether I declared the parameter as byVal or byRef.

What are you trying to draw in the backbuffer? Whatever you are trying to draw is what you would draw using the bgfx.Graphics object to do the drawing.

And I meant to mention it before, but if you are going to use an existing control with the BufferedGraphics object as your backbuffer, I probably would not use a picturebox.
A picturebox is already doubled buffered by default so you are adding a second level of backbuffering.
You could do away with using the BufferedGraphics class altogether and just use the graphics object passed in the paint event to draw on the picturebox's provided back buffer and let the control flip it to the screen when you exit the paint event.

In the MSDN article you linked to talking about double buffering, that is what they suggest. The reason for using the BufferedGraphics class is when you want to handle the backbuffering yourself and bypass the Paint event when rendering that buffer directly to the screen. This will save several milliseconds per "flip" over having the control handling the double buffer and screen refresh.

Since the BufferedGraphics object is giving you the back buffer and a high speed transfer from back buffer to screen through the render method, you would want either your own control class, where you can set the style options to avoid the paint event overhead, or use a control, like a panel, that will not be double buffered by default.

Since we're drawing to the screen directly most of the time, bypassing the paint event, the Picturebox isn't slowing us down the majority of the time, but why use it if we don't want to use the double buffering it includes.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #23  
Old 02-22-2013, 11:08 PM
CodeCruncher CodeCruncher is offline
Junior Contributor
 
Join Date: Jul 2006
Posts: 355
Default

Ok lets see if I can put this into words without causing confusion (including me).

The main reason I was trying to avoid using the paint event, is I am loading an image file, which loads several objects to the screen. I am also rescaling those objects so they fit within a given screen percentage of a groupbox or picturebox. i.e. if the screen height is 100 I dont want any of the objects to exceed 70 in length and the same for the width.

I can do away with the picture box as the picturebox is the same size as the client area of the groupbox, so that is one layer I can easily peel back.

But it was suggested that I could do all the rescaling I needed in memory first before painting it only once. In much the same way you load a full bitmap and then move it to a given coordinate with only painting it once.

The example worked fine in a seperate new project the issue with the error message was only when I tried to morph the code into my current project, but changing to ByVal or nothing in the case of 2012 it worked without throwing that error about narrowing.

BTW while I was trying to reconnect to the internet I discovered I don't need any of those lines I asked about the image is already in the buffer and it only needs "bgfx.Render()" to get it out. I realised it was only because you were trying to jocky the position of the bitmap before you displayed it that the additonal code was required.

Edit:
I remember why I wanted the picturebox now I was trying to not fill all the way out to the groupbox and have a boarder around the image to look tidier. Could probably alter the groupbox to not fill all the way to the edges if I could be bothered, but for now a picturebox is much easier.

Also I like you trick of anchoring to all four sides to resize easily.

Last edited by CodeCruncher; 02-22-2013 at 11:28 PM.
Reply With Quote
  #24  
Old 02-23-2013, 12:19 AM
passel's Avatar
passelBuffered Graphics Class passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

I'm just saying you can use a panel in place of the picturebox since you don't need the picturebox's double buffering.

For instance the example code works just fine with the following code in the form.
Code:
Option Explicit On

Public Class Form1

  Dim t1 As GenBufferedGraphics

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    t1 = New GenBufferedGraphics(Panel1)
  End Sub
End Class
And in this case, panel1 is place inside panel2, so panel2 can provide an extra border around panel1 (which also has a border that is not overdrawn by the code as it draws in the client rectangle which doesn't include the border).

p.s. It seems if you're loading and scaling images, that is a capability already built into the picturebox control so letting the control do the work might be acceptable. It's already doublebuffered so shouldn't flash. If you set the SizeMode to "Zoom" and load an image in the picturebox the image will scale proportionally as you change the size of the picturebox, no code required. Just position and size the picturebox to the desired size of your images.
Attached Images
File Type: png Panel_in_panel.png (11.1 KB, 5 views)
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 02-23-2013 at 12:37 AM.
Reply With Quote
  #25  
Old 02-23-2013, 10:46 PM
CodeCruncher CodeCruncher is offline
Junior Contributor
 
Join Date: Jul 2006
Posts: 355
Default

I've changed to panels instead of pictureboxes... Was going to try explain in words what I am trying to do but pictures are much easier.

When this section is working properly it should be able to take any size image from 1mm to 10m and draw it to a set display ratio.

But there are several resizes that need to take place, the first is the regular start state to maximised and back, with any manual resize required. Which might be possible through Zoom, but the second resize requires a calculation of the total image size top, bottom,left, right boarders, and then calculated again a set percentage of the client width and height.

But I'm guessing the pictures will make more sense...

I have the code mostly working with the exception of the image will not load at startup, but I will come back to that later. Thanks for the help I will return to the main build thread to tackle the next section of code.
Attached Images
File Type: jpg Size1.jpg (268.2 KB, 8 views)
File Type: jpg Size2.jpg (253.2 KB, 7 views)
File Type: jpg Size3.jpg (200.8 KB, 7 views)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Buffered Graphics Class
Buffered Graphics Class
Buffered Graphics Class Buffered Graphics Class
Buffered Graphics Class
Buffered Graphics Class
Buffered Graphics Class Buffered Graphics Class Buffered Graphics Class Buffered Graphics Class Buffered Graphics Class Buffered Graphics Class Buffered Graphics Class
Buffered Graphics Class
Buffered Graphics Class
 
Buffered Graphics Class
Buffered Graphics Class
 
-->