DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Mon, 16 Jul 2007 20:32:15 -0000,    posted on: microsoft.public.dotnet.framework.compactframework        back       

Thread Index
  1    Rick
          2    Minerva Jones et


Image Flicker   
I've created a simple control that loads an image, and allows a user
to "Pan" this image.  If the image is too large for the screen, the
user is able to drag the image around the screen in order to see the
parts of the image otherwise off the screen.  I'm getting an
incredible amount of flicker in the image when repainting it and I'd
love for some to look over the code below and see if there's something
I can do eliminate the flicker.

Rick

Public Class PanningImage
	Private m_Image As Bitmap
	Private m_LastPoint As Point
	Private m_StartPoint As Point
	Private m_Current As Point

	Public Property Image() As Bitmap
		Get
			Return m_Image
		End Get
		Set(ByVal value As Bitmap)
			m_Image = value
			m_Current.X = 0
			m_Current.Y = 0
			Me.Invalidate()
		End Set
	End Property

	Public Sub New()

		' This call is required by the Windows Form Designer.
		InitializeComponent()

		' Add any initialization after the InitializeComponent() call.
		m_Image = New Bitmap(20, 20)
		m_LastPoint = New Point(0, 0)
		m_Current = New Point(0, 0)
		m_StartPoint = New Point(0, 0)
	End Sub


    Protected Overrides Sub OnPaint(ByVal pe As
System.Windows.Forms.PaintEventArgs)
		Dim rect As New Rectangle
		Dim left As Integer
		Dim top As Integer

		top = m_Current.Y
		left = m_Current.X

		pe.Graphics.Clear(Me.BackColor)
		pe.Graphics.DrawImage(m_Image, left, top)


	End Sub


	Protected Overrides Sub OnPaintBackground(ByVal e As
System.Windows.Forms.PaintEventArgs)

	End Sub


	Private Sub PanningImage_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
		m_StartPoint.X = e.X
		m_StartPoint.Y = e.Y
		m_LastPoint.X = m_Current.X
		m_LastPoint.Y = m_Current.Y
	End Sub


	Private Sub PanningImage_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
		If e.Button = Windows.Forms.MouseButtons.Left Then

			Dim xDistance As Integer = m_StartPoint.X - e.X
			Dim yDistance As Integer = m_StartPoint.Y - e.Y
			Me.m_Current.X = m_LastPoint.X - xDistance
			Me.m_Current.Y = m_LastPoint.Y - yDistance

			If Math.Abs(xDistance) > 3 And Math.Abs(yDistance) > 3 Then
				Me.Invalidate()
			End If
		End If
	End Sub
End Class
Date:Mon, 16 Jul 2007 20:32:15 -0000   Author:  

Re: Image Flicker   
On Mon, 16 Jul 2007 20:32:15 -0000, Rick 
wrote:


>I've created a simple control that loads an image, and allows a user
>to "Pan" this image.  If the image is too large for the screen, the
>user is able to drag the image around the screen in order to see the
>parts of the image otherwise off the screen.  I'm getting an
>incredible amount of flicker in the image when repainting it and I'd
>love for some to look over the code below and see if there's something
>I can do eliminate the flicker.


Use offscreen buffering, or double buffering as it's often called.

I've amended your OnPaint, but I don't do VB, so syntactically it'll
be wrong, but you'll get the idea:


Protected Overrides Sub OnPaint(ByVal pe As
System.Windows.Forms.PaintEventArgs)

	Dim rect As New Rectangle
	Dim left As Integer
	Dim top As Integer

	top = m_Current.Y
	left = m_Current.X

	Dim bmpOffscreen As New Bitmap (ClientSize.Width,
ClientSize.Height)
	Dim gfxOffscreen As Graphics.FromImage (bmpOffscreen)

	// Do all drawing to the offscreen version
	gfxOffscreen.Clear(Me.BackColor)
	gfxOffscreen.DrawImage(m_Image, left, top)

	// Then at the last step, copy the offscreen to the onscreen
	// in one go. Therefore the intermediate steps aren't seen
	pe.Graphics.DrawImage(bmpOffscreen, 0, 0)

	// Tidy up these properly
	gfxOffscreen.Dispose()
	bmpOffscreen.Dispose()

End Sub
Date:Wed, 18 Jul 2007 11:44:34 +0100   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us