HighTechTalks DotNet Forums  

Double buffering with Metafiles

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss Double buffering with Metafiles in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Nick
 
Posts: n/a

Default Double buffering with Metafiles - 09-21-2005 , 09:15 AM






Hi there,

I have a little problem with double buffering. I can easily implement a
buffering routine to prevent flicker but unfortunately this requires
rasterizing any meta files that I am drawing. For example, firstly I would
create a bitmap object of the correct size then acquire the graphics
context, when drawing the metafile into the bitmap it becomes rasterized,
and this process introduces some artifcating on certain metafiles. I can
completely remove this artifacting by drawing directly into the graphics
object, but this is not double buffered correctly, even with the style set
on the control.

Any ideas on how I would do this one? Thanks loads in advance!!

--
Nick Pateman

---------------------------------------------------------------
Please do not reply directly to me, but the entire newsgroup.
Any views expressed above are my own
Without predjudice



Reply With Quote
  #2  
Old   
Michael Phillips, Jr.
 
Posts: n/a

Default Re: Double buffering with Metafiles - 09-21-2005 , 11:35 AM






You could create a memory context(HDC)
that is compatible with your device and then
create a Graphics object from that hdc.

Use DrawImage to draw the metafile to the memory
device context and then use BitBlt to transfer the
metafile from memory to the screen.

This is the same method for double buffering a bitmap.

Converting the metafile to a bitmap first and double buffering
the bitmap is overkill.




"Nick" <nospam (AT) altavente (DOT) com> wrote

Quote:
Hi again,

Here is an example with code for my problem. The flickering doesnt
really notice so much on this example as there is very little else going
on in the application. Would that mean that automatic double buffering
only works under light load? Anyway, the main problem (artifacting) can
be seen quite clearly in this example, when downsizing an EMF into a
bitmap object some nasty stuff appears!

Nick.

"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:%238YpvbrvFHA.3860 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi there,

I have a little problem with double buffering. I can easily implement
a
buffering routine to prevent flicker but unfortunately this requires
rasterizing any meta files that I am drawing. For example, firstly I
would
create a bitmap object of the correct size then acquire the graphics
context, when drawing the metafile into the bitmap it becomes rasterized,
and this process introduces some artifcating on certain metafiles. I can
completely remove this artifacting by drawing directly into the graphics
object, but this is not double buffered correctly, even with the style
set
on the control.

Any ideas on how I would do this one? Thanks loads in advance!!

--
Nick Pateman

---------------------------------------------------------------
Please do not reply directly to me, but the entire newsgroup.
Any views expressed above are my own
Without predjudice








Reply With Quote
  #3  
Old   
Nick
 
Posts: n/a

Default Re: Double buffering with Metafiles - 09-21-2005 , 02:03 PM



Hi Michael,

Thanks, I shall try this tommorrow...

Nick.

"Michael Phillips, Jr." <mphillips53 (AT) nospam (DOT) jun0.c0m> wrote

Quote:
You could create a memory context(HDC)
that is compatible with your device and then
create a Graphics object from that hdc.

Use DrawImage to draw the metafile to the memory
device context and then use BitBlt to transfer the
metafile from memory to the screen.

This is the same method for double buffering a bitmap.

Converting the metafile to a bitmap first and double buffering
the bitmap is overkill.




"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:uKdQS0rvFHA.460 (AT) TK2MSFTNGP15 (DOT) phx.gbl...
Hi again,

Here is an example with code for my problem. The flickering doesnt
really notice so much on this example as there is very little else going
on in the application. Would that mean that automatic double buffering
only works under light load? Anyway, the main problem (artifacting) can
be seen quite clearly in this example, when downsizing an EMF into a
bitmap object some nasty stuff appears!

Nick.

"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:%238YpvbrvFHA.3860 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi there,

I have a little problem with double buffering. I can easily
implement a
buffering routine to prevent flicker but unfortunately this requires
rasterizing any meta files that I am drawing. For example, firstly I
would
create a bitmap object of the correct size then acquire the graphics
context, when drawing the metafile into the bitmap it becomes
rasterized,
and this process introduces some artifcating on certain metafiles. I
can
completely remove this artifacting by drawing directly into the graphics
object, but this is not double buffered correctly, even with the style
set
on the control.

Any ideas on how I would do this one? Thanks loads in advance!!

--
Nick Pateman

---------------------------------------------------------------
Please do not reply directly to me, but the entire newsgroup.
Any views expressed above are my own
Without predjudice










Reply With Quote
  #4  
Old   
Nick
 
Posts: n/a

Default Re: Double buffering with Metafiles - 09-22-2005 , 04:20 AM



Hi Michael,

Im doing as suggested but unfortunately nothing appears, I'm just
getting a black area, this is my code,


Private Declare Function CreateCompatibleDC Lib "gdi32" Alias
"CreateCompatibleDC" (ByVal iHDC As IntPtr) As IntPtr
Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal iHWND
As IntPtr) As IntPtr
Private Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal
iHWND As IntPtr, ByVal iHDC As IntPtr) As Integer
Private Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal
iDestDC As IntPtr, ByVal iDestX As Integer, ByVal iDestY As Integer, ByVal
iDestWidth As Integer, ByVal iDestHeight As Integer, ByVal iSrcDC As IntPtr,
ByVal iSrcX As Integer, ByVal iSrcY As Integer, ByVal iOp As Integer) As
Integer

Private Const SRCCOPY As Long = &HCC0020

Private pImgMetaFile As Image = Nothing
Private cIPrBufferHDC As IntPtr = IntPtr.Zero
Private cGraBuffer As Graphics = Nothing

Private Sub setup()
pImgMetaFile = Image.FromFile(Application.ExecutablePath.Substrin g(0,
Application.ExecutablePath.LastIndexOf("\") + 1) & "test.emf")

'//Create a compatible DC
Dim pIPrMyDC As IntPtr = GetDC(picBuffered.Handle)
cIPrBufferHDC = CreateCompatibleDC(pIPrMyDC)
Call ReleaseDC(Me.Handle, pIPrMyDC)

'//Acquire a graphics object
cGraBuffer = Graphics.FromHdc(cIPrBufferHDC)
End Sub

Private Sub picBuffered_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles picBuffered.Paint
Call cGraBuffer.Clear(Me.BackColor)
Call cGraBuffer.DrawImage(pImgMetaFile, 0, 0, picBuffered.Width,
picBuffered.Height)
Dim pIntCurY As Integer
For pIntCurY = 0 To picBuffered.Height Step 10
Call cGraBuffer.DrawString("Double buffered...", Me.Font, New
SolidBrush(Color.Black), 0, pIntCurY)
Next

Dim pIPrDestHDC As IntPtr = e.Graphics.GetHdc()
Call BitBlt(pIPrDestHDC, 0, 0, picBuffered.Width, picBuffered.Height,
cIPrBufferHDC, 0, 0, SRCCOPY).ToString()
Call e.Graphics.ReleaseHdc(pIPrDestHDC)
End Sub

I've done this using a normal picturebox to draw onto, rather than the
object I had created in the other example. Nothing is being drawn though?

When setting up...

1. Getting the DC from the picture box
2. Creating a comparible DC from the DC acquired in step 1
3. Releasing the DC acquired in step 1
4. Creating a graphics object from the DC created in step 2

When drawing...

1. Drawing to the graphics object acquired in Step 4 when setting up
2. Getting the DC of the picture box
3. Blitting the DC created in step 2 when setting up to the DC acquired
in step 2
4. Releasing the DC acquired in step 2

I've had problems with BitBlt in the past with it not actually drawing
anything, is my declaration correct??

Nick.

"Michael Phillips, Jr." <mphillips53 (AT) nospam (DOT) jun0.c0m> wrote

Quote:
You could create a memory context(HDC)
that is compatible with your device and then
create a Graphics object from that hdc.

Use DrawImage to draw the metafile to the memory
device context and then use BitBlt to transfer the
metafile from memory to the screen.

This is the same method for double buffering a bitmap.

Converting the metafile to a bitmap first and double buffering
the bitmap is overkill.




"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:uKdQS0rvFHA.460 (AT) TK2MSFTNGP15 (DOT) phx.gbl...
Hi again,

Here is an example with code for my problem. The flickering doesnt
really notice so much on this example as there is very little else going
on in the application. Would that mean that automatic double buffering
only works under light load? Anyway, the main problem (artifacting) can
be seen quite clearly in this example, when downsizing an EMF into a
bitmap object some nasty stuff appears!

Nick.

"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:%238YpvbrvFHA.3860 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi there,

I have a little problem with double buffering. I can easily
implement a
buffering routine to prevent flicker but unfortunately this requires
rasterizing any meta files that I am drawing. For example, firstly I
would
create a bitmap object of the correct size then acquire the graphics
context, when drawing the metafile into the bitmap it becomes
rasterized,
and this process introduces some artifcating on certain metafiles. I
can
completely remove this artifacting by drawing directly into the graphics
object, but this is not double buffered correctly, even with the style
set
on the control.

Any ideas on how I would do this one? Thanks loads in advance!!

--
Nick Pateman

---------------------------------------------------------------
Please do not reply directly to me, but the entire newsgroup.
Any views expressed above are my own
Without predjudice










Reply With Quote
  #5  
Old   
Nick
 
Posts: n/a

Default Re: Double buffering with Metafiles - 09-22-2005 , 04:30 AM



Where I mentioned a black area appearing in the last past ignore that, it's
the backcolor of the control. I can get a red rectangle to flicker during
resizing if I use the FillRect API...

"Nick" <nospam (AT) altavente (DOT) com> wrote

Quote:
Hi Michael,

Im doing as suggested but unfortunately nothing appears, I'm just
getting a black area, this is my code,


Private Declare Function CreateCompatibleDC Lib "gdi32" Alias
"CreateCompatibleDC" (ByVal iHDC As IntPtr) As IntPtr
Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal iHWND
As IntPtr) As IntPtr
Private Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC"
(ByVal iHWND As IntPtr, ByVal iHDC As IntPtr) As Integer
Private Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal
iDestDC As IntPtr, ByVal iDestX As Integer, ByVal iDestY As Integer, ByVal
iDestWidth As Integer, ByVal iDestHeight As Integer, ByVal iSrcDC As
IntPtr, ByVal iSrcX As Integer, ByVal iSrcY As Integer, ByVal iOp As
Integer) As Integer

Private Const SRCCOPY As Long = &HCC0020

Private pImgMetaFile As Image = Nothing
Private cIPrBufferHDC As IntPtr = IntPtr.Zero
Private cGraBuffer As Graphics = Nothing

Private Sub setup()
pImgMetaFile = Image.FromFile(Application.ExecutablePath.Substrin g(0,
Application.ExecutablePath.LastIndexOf("\") + 1) & "test.emf")

'//Create a compatible DC
Dim pIPrMyDC As IntPtr = GetDC(picBuffered.Handle)
cIPrBufferHDC = CreateCompatibleDC(pIPrMyDC)
Call ReleaseDC(Me.Handle, pIPrMyDC)

'//Acquire a graphics object
cGraBuffer = Graphics.FromHdc(cIPrBufferHDC)
End Sub

Private Sub picBuffered_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles picBuffered.Paint
Call cGraBuffer.Clear(Me.BackColor)
Call cGraBuffer.DrawImage(pImgMetaFile, 0, 0, picBuffered.Width,
picBuffered.Height)
Dim pIntCurY As Integer
For pIntCurY = 0 To picBuffered.Height Step 10
Call cGraBuffer.DrawString("Double buffered...", Me.Font, New
SolidBrush(Color.Black), 0, pIntCurY)
Next

Dim pIPrDestHDC As IntPtr = e.Graphics.GetHdc()
Call BitBlt(pIPrDestHDC, 0, 0, picBuffered.Width, picBuffered.Height,
cIPrBufferHDC, 0, 0, SRCCOPY).ToString()
Call e.Graphics.ReleaseHdc(pIPrDestHDC)
End Sub

I've done this using a normal picturebox to draw onto, rather than the
object I had created in the other example. Nothing is being drawn though?

When setting up...

1. Getting the DC from the picture box
2. Creating a comparible DC from the DC acquired in step 1
3. Releasing the DC acquired in step 1
4. Creating a graphics object from the DC created in step 2

When drawing...

1. Drawing to the graphics object acquired in Step 4 when setting up
2. Getting the DC of the picture box
3. Blitting the DC created in step 2 when setting up to the DC acquired
in step 2
4. Releasing the DC acquired in step 2

I've had problems with BitBlt in the past with it not actually drawing
anything, is my declaration correct??

Nick.

"Michael Phillips, Jr." <mphillips53 (AT) nospam (DOT) jun0.c0m> wrote in message
news:%2311oEqsvFHA.3764 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
You could create a memory context(HDC)
that is compatible with your device and then
create a Graphics object from that hdc.

Use DrawImage to draw the metafile to the memory
device context and then use BitBlt to transfer the
metafile from memory to the screen.

This is the same method for double buffering a bitmap.

Converting the metafile to a bitmap first and double buffering
the bitmap is overkill.




"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:uKdQS0rvFHA.460 (AT) TK2MSFTNGP15 (DOT) phx.gbl...
Hi again,

Here is an example with code for my problem. The flickering doesnt
really notice so much on this example as there is very little else going
on in the application. Would that mean that automatic double buffering
only works under light load? Anyway, the main problem (artifacting) can
be seen quite clearly in this example, when downsizing an EMF into a
bitmap object some nasty stuff appears!

Nick.

"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:%238YpvbrvFHA.3860 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi there,

I have a little problem with double buffering. I can easily
implement a
buffering routine to prevent flicker but unfortunately this requires
rasterizing any meta files that I am drawing. For example, firstly I
would
create a bitmap object of the correct size then acquire the graphics
context, when drawing the metafile into the bitmap it becomes
rasterized,
and this process introduces some artifcating on certain metafiles. I
can
completely remove this artifacting by drawing directly into the
graphics
object, but this is not double buffered correctly, even with the style
set
on the control.

Any ideas on how I would do this one? Thanks loads in advance!!

--
Nick Pateman

---------------------------------------------------------------
Please do not reply directly to me, but the entire newsgroup.
Any views expressed above are my own
Without predjudice












Reply With Quote
  #6  
Old   
Nick
 
Posts: n/a

Default Re: Double buffering with Metafiles - 09-22-2005 , 04:35 AM



.... I can get the "flickering rectangle" to "fixate" by calling the graphics
objects GetHDC method rather than the API, so I can draw fine to it with
everything except BitBlt.

Nick.

"Nick" <nospam (AT) altavente (DOT) com> wrote

Quote:
Where I mentioned a black area appearing in the last past ignore that,
it's the backcolor of the control. I can get a red rectangle to flicker
during resizing if I use the FillRect API...

"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:eadAnb1vFHA.2292 (AT) TK2MSFTNGP12 (DOT) phx.gbl...
Hi Michael,

Im doing as suggested but unfortunately nothing appears, I'm just
getting a black area, this is my code,


Private Declare Function CreateCompatibleDC Lib "gdi32" Alias
"CreateCompatibleDC" (ByVal iHDC As IntPtr) As IntPtr
Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal iHWND
As IntPtr) As IntPtr
Private Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC"
(ByVal iHWND As IntPtr, ByVal iHDC As IntPtr) As Integer
Private Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal
iDestDC As IntPtr, ByVal iDestX As Integer, ByVal iDestY As Integer,
ByVal iDestWidth As Integer, ByVal iDestHeight As Integer, ByVal iSrcDC
As IntPtr, ByVal iSrcX As Integer, ByVal iSrcY As Integer, ByVal iOp As
Integer) As Integer

Private Const SRCCOPY As Long = &HCC0020

Private pImgMetaFile As Image = Nothing
Private cIPrBufferHDC As IntPtr = IntPtr.Zero
Private cGraBuffer As Graphics = Nothing

Private Sub setup()
pImgMetaFile = Image.FromFile(Application.ExecutablePath.Substrin g(0,
Application.ExecutablePath.LastIndexOf("\") + 1) & "test.emf")

'//Create a compatible DC
Dim pIPrMyDC As IntPtr = GetDC(picBuffered.Handle)
cIPrBufferHDC = CreateCompatibleDC(pIPrMyDC)
Call ReleaseDC(Me.Handle, pIPrMyDC)

'//Acquire a graphics object
cGraBuffer = Graphics.FromHdc(cIPrBufferHDC)
End Sub

Private Sub picBuffered_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles picBuffered.Paint
Call cGraBuffer.Clear(Me.BackColor)
Call cGraBuffer.DrawImage(pImgMetaFile, 0, 0, picBuffered.Width,
picBuffered.Height)
Dim pIntCurY As Integer
For pIntCurY = 0 To picBuffered.Height Step 10
Call cGraBuffer.DrawString("Double buffered...", Me.Font, New
SolidBrush(Color.Black), 0, pIntCurY)
Next

Dim pIPrDestHDC As IntPtr = e.Graphics.GetHdc()
Call BitBlt(pIPrDestHDC, 0, 0, picBuffered.Width, picBuffered.Height,
cIPrBufferHDC, 0, 0, SRCCOPY).ToString()
Call e.Graphics.ReleaseHdc(pIPrDestHDC)
End Sub

I've done this using a normal picturebox to draw onto, rather than the
object I had created in the other example. Nothing is being drawn
though?

When setting up...

1. Getting the DC from the picture box
2. Creating a comparible DC from the DC acquired in step 1
3. Releasing the DC acquired in step 1
4. Creating a graphics object from the DC created in step 2

When drawing...

1. Drawing to the graphics object acquired in Step 4 when setting up
2. Getting the DC of the picture box
3. Blitting the DC created in step 2 when setting up to the DC
acquired in step 2
4. Releasing the DC acquired in step 2

I've had problems with BitBlt in the past with it not actually drawing
anything, is my declaration correct??

Nick.

"Michael Phillips, Jr." <mphillips53 (AT) nospam (DOT) jun0.c0m> wrote in message
news:%2311oEqsvFHA.3764 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
You could create a memory context(HDC)
that is compatible with your device and then
create a Graphics object from that hdc.

Use DrawImage to draw the metafile to the memory
device context and then use BitBlt to transfer the
metafile from memory to the screen.

This is the same method for double buffering a bitmap.

Converting the metafile to a bitmap first and double buffering
the bitmap is overkill.




"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:uKdQS0rvFHA.460 (AT) TK2MSFTNGP15 (DOT) phx.gbl...
Hi again,

Here is an example with code for my problem. The flickering doesnt
really notice so much on this example as there is very little else
going on in the application. Would that mean that automatic double
buffering only works under light load? Anyway, the main problem
(artifacting) can be seen quite clearly in this example, when
downsizing an EMF into a bitmap object some nasty stuff appears!

Nick.

"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:%238YpvbrvFHA.3860 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi there,

I have a little problem with double buffering. I can easily
implement a
buffering routine to prevent flicker but unfortunately this requires
rasterizing any meta files that I am drawing. For example, firstly I
would
create a bitmap object of the correct size then acquire the graphics
context, when drawing the metafile into the bitmap it becomes
rasterized,
and this process introduces some artifcating on certain metafiles. I
can
completely remove this artifacting by drawing directly into the
graphics
object, but this is not double buffered correctly, even with the style
set
on the control.

Any ideas on how I would do this one? Thanks loads in advance!!

--
Nick Pateman

---------------------------------------------------------------
Please do not reply directly to me, but the entire newsgroup.
Any views expressed above are my own
Without predjudice














Reply With Quote
  #7  
Old   
Nick
 
Posts: n/a

Default Re: Double buffering with Metafiles - 09-22-2005 , 05:21 AM



Hi again,

I presume that the reason nothing is appearing is because I have not
called CreateCompatibleBitmap()? I've just tried it with that and although
the image is not appearing correctly, I'm getting something appearing.

So that basically leads me back to were I started, if I need to create a
bitmap object object for this buffer then how was my previous method
overkill? I understand that DrawImage of GDI is faster because it uses
hardware acceleration but in principal the GDI method is exactly the same.

Is it actually possible to perform double buffering with Metafiles in
..NET?

Nick.

"Nick" <nospam (AT) altavente (DOT) com> wrote

Quote:
... I can get the "flickering rectangle" to "fixate" by calling the
graphics objects GetHDC method rather than the API, so I can draw fine to
it with everything except BitBlt.

Nick.

"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:ellsRh1vFHA.596 (AT) TK2MSFTNGP12 (DOT) phx.gbl...
Where I mentioned a black area appearing in the last past ignore that,
it's the backcolor of the control. I can get a red rectangle to flicker
during resizing if I use the FillRect API...

"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:eadAnb1vFHA.2292 (AT) TK2MSFTNGP12 (DOT) phx.gbl...
Hi Michael,

Im doing as suggested but unfortunately nothing appears, I'm just
getting a black area, this is my code,


Private Declare Function CreateCompatibleDC Lib "gdi32" Alias
"CreateCompatibleDC" (ByVal iHDC As IntPtr) As IntPtr
Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal
iHWND As IntPtr) As IntPtr
Private Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC"
(ByVal iHWND As IntPtr, ByVal iHDC As IntPtr) As Integer
Private Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal
iDestDC As IntPtr, ByVal iDestX As Integer, ByVal iDestY As Integer,
ByVal iDestWidth As Integer, ByVal iDestHeight As Integer, ByVal iSrcDC
As IntPtr, ByVal iSrcX As Integer, ByVal iSrcY As Integer, ByVal iOp As
Integer) As Integer

Private Const SRCCOPY As Long = &HCC0020

Private pImgMetaFile As Image = Nothing
Private cIPrBufferHDC As IntPtr = IntPtr.Zero
Private cGraBuffer As Graphics = Nothing

Private Sub setup()
pImgMetaFile = Image.FromFile(Application.ExecutablePath.Substrin g(0,
Application.ExecutablePath.LastIndexOf("\") + 1) & "test.emf")

'//Create a compatible DC
Dim pIPrMyDC As IntPtr = GetDC(picBuffered.Handle)
cIPrBufferHDC = CreateCompatibleDC(pIPrMyDC)
Call ReleaseDC(Me.Handle, pIPrMyDC)

'//Acquire a graphics object
cGraBuffer = Graphics.FromHdc(cIPrBufferHDC)
End Sub

Private Sub picBuffered_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles picBuffered.Paint
Call cGraBuffer.Clear(Me.BackColor)
Call cGraBuffer.DrawImage(pImgMetaFile, 0, 0, picBuffered.Width,
picBuffered.Height)
Dim pIntCurY As Integer
For pIntCurY = 0 To picBuffered.Height Step 10
Call cGraBuffer.DrawString("Double buffered...", Me.Font, New
SolidBrush(Color.Black), 0, pIntCurY)
Next

Dim pIPrDestHDC As IntPtr = e.Graphics.GetHdc()
Call BitBlt(pIPrDestHDC, 0, 0, picBuffered.Width, picBuffered.Height,
cIPrBufferHDC, 0, 0, SRCCOPY).ToString()
Call e.Graphics.ReleaseHdc(pIPrDestHDC)
End Sub

I've done this using a normal picturebox to draw onto, rather than
the object I had created in the other example. Nothing is being drawn
though?

When setting up...

1. Getting the DC from the picture box
2. Creating a comparible DC from the DC acquired in step 1
3. Releasing the DC acquired in step 1
4. Creating a graphics object from the DC created in step 2

When drawing...

1. Drawing to the graphics object acquired in Step 4 when setting up
2. Getting the DC of the picture box
3. Blitting the DC created in step 2 when setting up to the DC
acquired in step 2
4. Releasing the DC acquired in step 2

I've had problems with BitBlt in the past with it not actually
drawing anything, is my declaration correct??

Nick.

"Michael Phillips, Jr." <mphillips53 (AT) nospam (DOT) jun0.c0m> wrote in message
news:%2311oEqsvFHA.3764 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
You could create a memory context(HDC)
that is compatible with your device and then
create a Graphics object from that hdc.

Use DrawImage to draw the metafile to the memory
device context and then use BitBlt to transfer the
metafile from memory to the screen.

This is the same method for double buffering a bitmap.

Converting the metafile to a bitmap first and double buffering
the bitmap is overkill.




"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:uKdQS0rvFHA.460 (AT) TK2MSFTNGP15 (DOT) phx.gbl...
Hi again,

Here is an example with code for my problem. The flickering doesnt
really notice so much on this example as there is very little else
going on in the application. Would that mean that automatic double
buffering only works under light load? Anyway, the main problem
(artifacting) can be seen quite clearly in this example, when
downsizing an EMF into a bitmap object some nasty stuff appears!

Nick.

"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:%238YpvbrvFHA.3860 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi there,

I have a little problem with double buffering. I can easily
implement a
buffering routine to prevent flicker but unfortunately this requires
rasterizing any meta files that I am drawing. For example, firstly I
would
create a bitmap object of the correct size then acquire the graphics
context, when drawing the metafile into the bitmap it becomes
rasterized,
and this process introduces some artifcating on certain metafiles. I
can
completely remove this artifacting by drawing directly into the
graphics
object, but this is not double buffered correctly, even with the
style set
on the control.

Any ideas on how I would do this one? Thanks loads in advance!!

--
Nick Pateman

---------------------------------------------------------------
Please do not reply directly to me, but the entire newsgroup.
Any views expressed above are my own
Without predjudice
















Reply With Quote
  #8  
Old   
Nick
 
Posts: n/a

Default Re: Double buffering with Metafiles - 09-22-2005 , 05:35 AM



Ignore me, this is doing my head in, I'm not even sure I know what I'm
asking now. Double buffering has been performed correctly as the
artifacting has disappeared which is what my original problem was! Thanks
for your help!!

For other peoples reference you need to use CreateCompatibleBitmap after you
call CreateCompatibleDC. Thanks again and sorry for rambling!

Nick.

"Nick" <nospam (AT) altavente (DOT) com> wrote

Quote:
Hi again,

I presume that the reason nothing is appearing is because I have not
called CreateCompatibleBitmap()? I've just tried it with that and
although the image is not appearing correctly, I'm getting something
appearing.

So that basically leads me back to were I started, if I need to create
a bitmap object object for this buffer then how was my previous method
overkill? I understand that DrawImage of GDI is faster because it uses
hardware acceleration but in principal the GDI method is exactly the same.

Is it actually possible to perform double buffering with Metafiles in
.NET?

Nick.

"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:OB7XCk1vFHA.2864 (AT) TK2MSFTNGP10 (DOT) phx.gbl...
... I can get the "flickering rectangle" to "fixate" by calling the
graphics objects GetHDC method rather than the API, so I can draw fine to
it with everything except BitBlt.

Nick.

"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:ellsRh1vFHA.596 (AT) TK2MSFTNGP12 (DOT) phx.gbl...
Where I mentioned a black area appearing in the last past ignore that,
it's the backcolor of the control. I can get a red rectangle to flicker
during resizing if I use the FillRect API...

"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:eadAnb1vFHA.2292 (AT) TK2MSFTNGP12 (DOT) phx.gbl...
Hi Michael,

Im doing as suggested but unfortunately nothing appears, I'm just
getting a black area, this is my code,


Private Declare Function CreateCompatibleDC Lib "gdi32" Alias
"CreateCompatibleDC" (ByVal iHDC As IntPtr) As IntPtr
Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal
iHWND As IntPtr) As IntPtr
Private Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC"
(ByVal iHWND As IntPtr, ByVal iHDC As IntPtr) As Integer
Private Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal
iDestDC As IntPtr, ByVal iDestX As Integer, ByVal iDestY As Integer,
ByVal iDestWidth As Integer, ByVal iDestHeight As Integer, ByVal iSrcDC
As IntPtr, ByVal iSrcX As Integer, ByVal iSrcY As Integer, ByVal iOp As
Integer) As Integer

Private Const SRCCOPY As Long = &HCC0020

Private pImgMetaFile As Image = Nothing
Private cIPrBufferHDC As IntPtr = IntPtr.Zero
Private cGraBuffer As Graphics = Nothing

Private Sub setup()
pImgMetaFile =
Image.FromFile(Application.ExecutablePath.Substrin g(0,
Application.ExecutablePath.LastIndexOf("\") + 1) & "test.emf")

'//Create a compatible DC
Dim pIPrMyDC As IntPtr = GetDC(picBuffered.Handle)
cIPrBufferHDC = CreateCompatibleDC(pIPrMyDC)
Call ReleaseDC(Me.Handle, pIPrMyDC)

'//Acquire a graphics object
cGraBuffer = Graphics.FromHdc(cIPrBufferHDC)
End Sub

Private Sub picBuffered_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles picBuffered.Paint
Call cGraBuffer.Clear(Me.BackColor)
Call cGraBuffer.DrawImage(pImgMetaFile, 0, 0, picBuffered.Width,
picBuffered.Height)
Dim pIntCurY As Integer
For pIntCurY = 0 To picBuffered.Height Step 10
Call cGraBuffer.DrawString("Double buffered...", Me.Font, New
SolidBrush(Color.Black), 0, pIntCurY)
Next

Dim pIPrDestHDC As IntPtr = e.Graphics.GetHdc()
Call BitBlt(pIPrDestHDC, 0, 0, picBuffered.Width,
picBuffered.Height, cIPrBufferHDC, 0, 0, SRCCOPY).ToString()
Call e.Graphics.ReleaseHdc(pIPrDestHDC)
End Sub

I've done this using a normal picturebox to draw onto, rather than
the object I had created in the other example. Nothing is being drawn
though?

When setting up...

1. Getting the DC from the picture box
2. Creating a comparible DC from the DC acquired in step 1
3. Releasing the DC acquired in step 1
4. Creating a graphics object from the DC created in step 2

When drawing...

1. Drawing to the graphics object acquired in Step 4 when setting up
2. Getting the DC of the picture box
3. Blitting the DC created in step 2 when setting up to the DC
acquired in step 2
4. Releasing the DC acquired in step 2

I've had problems with BitBlt in the past with it not actually
drawing anything, is my declaration correct??

Nick.

"Michael Phillips, Jr." <mphillips53 (AT) nospam (DOT) jun0.c0m> wrote in message
news:%2311oEqsvFHA.3764 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
You could create a memory context(HDC)
that is compatible with your device and then
create a Graphics object from that hdc.

Use DrawImage to draw the metafile to the memory
device context and then use BitBlt to transfer the
metafile from memory to the screen.

This is the same method for double buffering a bitmap.

Converting the metafile to a bitmap first and double buffering
the bitmap is overkill.




"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:uKdQS0rvFHA.460 (AT) TK2MSFTNGP15 (DOT) phx.gbl...
Hi again,

Here is an example with code for my problem. The flickering
doesnt really notice so much on this example as there is very little
else going on in the application. Would that mean that automatic
double buffering only works under light load? Anyway, the main
problem (artifacting) can be seen quite clearly in this example, when
downsizing an EMF into a bitmap object some nasty stuff appears!

Nick.

"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:%238YpvbrvFHA.3860 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi there,

I have a little problem with double buffering. I can easily
implement a
buffering routine to prevent flicker but unfortunately this requires
rasterizing any meta files that I am drawing. For example, firstly
I would
create a bitmap object of the correct size then acquire the graphics
context, when drawing the metafile into the bitmap it becomes
rasterized,
and this process introduces some artifcating on certain metafiles.
I can
completely remove this artifacting by drawing directly into the
graphics
object, but this is not double buffered correctly, even with the
style set
on the control.

Any ideas on how I would do this one? Thanks loads in advance!!

--
Nick Pateman

---------------------------------------------------------------
Please do not reply directly to me, but the entire newsgroup.
Any views expressed above are my own
Without predjudice


















Reply With Quote
  #9  
Old   
Nick
 
Posts: n/a

Default Re: Double buffering with Metafiles - 09-22-2005 , 05:35 AM



Ignore me, this is doing my head in, I'm not even sure I know what I'm
asking now. Double buffering has been performed correctly as the
artifacting has disappeared which is what my original problem was! Thanks
for your help!!

For other peoples reference you need to use CreateCompatibleBitmap after you
call CreateCompatibleDC. Thanks again and sorry for rambling!

Nick.

"Nick" <nospam (AT) altavente (DOT) com> wrote

Quote:
Hi again,

I presume that the reason nothing is appearing is because I have not
called CreateCompatibleBitmap()? I've just tried it with that and
although the image is not appearing correctly, I'm getting something
appearing.

So that basically leads me back to were I started, if I need to create
a bitmap object object for this buffer then how was my previous method
overkill? I understand that DrawImage of GDI is faster because it uses
hardware acceleration but in principal the GDI method is exactly the same.

Is it actually possible to perform double buffering with Metafiles in
.NET?

Nick.

"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:OB7XCk1vFHA.2864 (AT) TK2MSFTNGP10 (DOT) phx.gbl...
... I can get the "flickering rectangle" to "fixate" by calling the
graphics objects GetHDC method rather than the API, so I can draw fine to
it with everything except BitBlt.

Nick.

"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:ellsRh1vFHA.596 (AT) TK2MSFTNGP12 (DOT) phx.gbl...
Where I mentioned a black area appearing in the last past ignore that,
it's the backcolor of the control. I can get a red rectangle to flicker
during resizing if I use the FillRect API...

"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:eadAnb1vFHA.2292 (AT) TK2MSFTNGP12 (DOT) phx.gbl...
Hi Michael,

Im doing as suggested but unfortunately nothing appears, I'm just
getting a black area, this is my code,


Private Declare Function CreateCompatibleDC Lib "gdi32" Alias
"CreateCompatibleDC" (ByVal iHDC As IntPtr) As IntPtr
Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal
iHWND As IntPtr) As IntPtr
Private Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC"
(ByVal iHWND As IntPtr, ByVal iHDC As IntPtr) As Integer
Private Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal
iDestDC As IntPtr, ByVal iDestX As Integer, ByVal iDestY As Integer,
ByVal iDestWidth As Integer, ByVal iDestHeight As Integer, ByVal iSrcDC
As IntPtr, ByVal iSrcX As Integer, ByVal iSrcY As Integer, ByVal iOp As
Integer) As Integer

Private Const SRCCOPY As Long = &HCC0020

Private pImgMetaFile As Image = Nothing
Private cIPrBufferHDC As IntPtr = IntPtr.Zero
Private cGraBuffer As Graphics = Nothing

Private Sub setup()
pImgMetaFile =
Image.FromFile(Application.ExecutablePath.Substrin g(0,
Application.ExecutablePath.LastIndexOf("\") + 1) & "test.emf")

'//Create a compatible DC
Dim pIPrMyDC As IntPtr = GetDC(picBuffered.Handle)
cIPrBufferHDC = CreateCompatibleDC(pIPrMyDC)
Call ReleaseDC(Me.Handle, pIPrMyDC)

'//Acquire a graphics object
cGraBuffer = Graphics.FromHdc(cIPrBufferHDC)
End Sub

Private Sub picBuffered_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles picBuffered.Paint
Call cGraBuffer.Clear(Me.BackColor)
Call cGraBuffer.DrawImage(pImgMetaFile, 0, 0, picBuffered.Width,
picBuffered.Height)
Dim pIntCurY As Integer
For pIntCurY = 0 To picBuffered.Height Step 10
Call cGraBuffer.DrawString("Double buffered...", Me.Font, New
SolidBrush(Color.Black), 0, pIntCurY)
Next

Dim pIPrDestHDC As IntPtr = e.Graphics.GetHdc()
Call BitBlt(pIPrDestHDC, 0, 0, picBuffered.Width,
picBuffered.Height, cIPrBufferHDC, 0, 0, SRCCOPY).ToString()
Call e.Graphics.ReleaseHdc(pIPrDestHDC)
End Sub

I've done this using a normal picturebox to draw onto, rather than
the object I had created in the other example. Nothing is being drawn
though?

When setting up...

1. Getting the DC from the picture box
2. Creating a comparible DC from the DC acquired in step 1
3. Releasing the DC acquired in step 1
4. Creating a graphics object from the DC created in step 2

When drawing...

1. Drawing to the graphics object acquired in Step 4 when setting up
2. Getting the DC of the picture box
3. Blitting the DC created in step 2 when setting up to the DC
acquired in step 2
4. Releasing the DC acquired in step 2

I've had problems with BitBlt in the past with it not actually
drawing anything, is my declaration correct??

Nick.

"Michael Phillips, Jr." <mphillips53 (AT) nospam (DOT) jun0.c0m> wrote in message
news:%2311oEqsvFHA.3764 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
You could create a memory context(HDC)
that is compatible with your device and then
create a Graphics object from that hdc.

Use DrawImage to draw the metafile to the memory
device context and then use BitBlt to transfer the
metafile from memory to the screen.

This is the same method for double buffering a bitmap.

Converting the metafile to a bitmap first and double buffering
the bitmap is overkill.




"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:uKdQS0rvFHA.460 (AT) TK2MSFTNGP15 (DOT) phx.gbl...
Hi again,

Here is an example with code for my problem. The flickering
doesnt really notice so much on this example as there is very little
else going on in the application. Would that mean that automatic
double buffering only works under light load? Anyway, the main
problem (artifacting) can be seen quite clearly in this example, when
downsizing an EMF into a bitmap object some nasty stuff appears!

Nick.

"Nick" <nospam (AT) altavente (DOT) com> wrote in message
news:%238YpvbrvFHA.3860 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi there,

I have a little problem with double buffering. I can easily
implement a
buffering routine to prevent flicker but unfortunately this requires
rasterizing any meta files that I am drawing. For example, firstly
I would
create a bitmap object of the correct size then acquire the graphics
context, when drawing the metafile into the bitmap it becomes
rasterized,
and this process introduces some artifcating on certain metafiles.
I can
completely remove this artifacting by drawing directly into the
graphics
object, but this is not double buffered correctly, even with the
style set
on the control.

Any ideas on how I would do this one? Thanks loads in advance!!

--
Nick Pateman

---------------------------------------------------------------
Please do not reply directly to me, but the entire newsgroup.
Any views expressed above are my own
Without predjudice


















Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.