PC Review


Reply
Thread Tools Rate Thread

display an image with BitBlt (in Paint-method)

 
 
DraguVaso
Guest
Posts: n/a
 
      28th Jul 2005
Hi,

In the override of the Paint-method of a DataGridTextBoxColumn I want to
show an image with BitBlt, to see what I can gain there on performance.
The problem is: It doesn't show me the image in the DataGrid-Cell's, but a
black background...

Does anybody has any idea what I am doing wrong?

Thanks a lot in advance,

Pieter


Declare Auto Function BitBlt Lib "GDI32.DLL" ( _
ByVal hdcDest As IntPtr, _
ByVal nXDest As Integer, _
ByVal nYDest As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Integer, _
ByVal hdcSrc As IntPtr, _
ByVal nXSrc As Integer, _
ByVal nYSrc As Integer, _
ByVal dwRop As Int32) As Boolean
Private Const SRCCOPY As Integer = &HCC0020

Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal
bounds As Rectangle, ByVal source As CurrencyManager, ByVal rowNum As
Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal
alignToRight As Boolean)
Dim rectB As New Rectangle
rectB = bounds
rectB.Width = rectB.Width + 1
Dim g3 As Graphics
g3 = Graphics.FromImage(fe.BackgroundImage)
'fe.BackgroundImage is a bitmap I read from a stream (PixelFormat =
Format32bppPArgb)
Dim HDC1 As IntPtr = g.GetHdc
Dim HDC2 As IntPtr = g3.GetHdc
Me.BitBlt(HDC1, 0, 0, rectB.Width, rectB.Height, HDC2, 0, 0,
SRCCOPY)
g.ReleaseHdc(HDC1)
g3.ReleaseHdc(HDC2)
....


 
Reply With Quote
 
 
 
 
James Westgate
Guest
Posts: n/a
 
      28th Jul 2005
Hi,

You need to create a compatible device context. See my post on the 19th of
July under Graphics.DrawIMage uses More memory

James

--
Create interactive diagrams and flowcharts with ERM Diagram at
http://www.crainiate.net

Take the ERM Tour at http://www.flowchartcontrol.com


"DraguVaso" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> In the override of the Paint-method of a DataGridTextBoxColumn I want to
> show an image with BitBlt, to see what I can gain there on performance.
> The problem is: It doesn't show me the image in the DataGrid-Cell's, but a
> black background...
>
> Does anybody has any idea what I am doing wrong?
>
> Thanks a lot in advance,
>
> Pieter
>
>
> Declare Auto Function BitBlt Lib "GDI32.DLL" ( _
> ByVal hdcDest As IntPtr, _
> ByVal nXDest As Integer, _
> ByVal nYDest As Integer, _
> ByVal nWidth As Integer, _
> ByVal nHeight As Integer, _
> ByVal hdcSrc As IntPtr, _
> ByVal nXSrc As Integer, _
> ByVal nYSrc As Integer, _
> ByVal dwRop As Int32) As Boolean
> Private Const SRCCOPY As Integer = &HCC0020
>
> Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal
> bounds As Rectangle, ByVal source As CurrencyManager, ByVal rowNum As
> Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal
> alignToRight As Boolean)
> Dim rectB As New Rectangle
> rectB = bounds
> rectB.Width = rectB.Width + 1
> Dim g3 As Graphics
> g3 = Graphics.FromImage(fe.BackgroundImage)
> 'fe.BackgroundImage is a bitmap I read from a stream (PixelFormat =
> Format32bppPArgb)
> Dim HDC1 As IntPtr = g.GetHdc
> Dim HDC2 As IntPtr = g3.GetHdc
> Me.BitBlt(HDC1, 0, 0, rectB.Width, rectB.Height, HDC2, 0,
> 0,
> SRCCOPY)
> g.ReleaseHdc(HDC1)
> g3.ReleaseHdc(HDC2)
> ...
>
>



 
Reply With Quote
 
=?Utf-8?B?RGVubmlz?=
Guest
Posts: n/a
 
      29th Jul 2005
Here's some code I use to copy part of a bitmap image to the ClipRectangle
passed for repainting. Note that v_BackImage is my background bitmap I
defined as a private variable in my overall class.

Private Sub me_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim hdcControl As IntPtr = e.Graphics.GetHdc
Dim hdcBitmapDC As IntPtr = gph.GetHdc
Dim hdcBitmapHandle As IntPtr = v_BackImage.GetHbitmap 'This takes
up 85% of time
SelectObject(hdcBitmapDC, hdcBitmapHandle)
BitBlt(hdcControl, e.ClipRectangle.X, e.ClipRectangle.Y,
e.ClipRectangle.Width, e.ClipRectangle.Height, hdcBitmapDC,
e.ClipRectangle.X, e.ClipRectangle.Y, &HCC0020)
DeleteObject(hdcBitmapHandle)
gph.ReleaseHdc(hdcBitmapDC)
e.Graphics.ReleaseHdc(hdcControl)
exit sub

'**** Explaination of above *********
' BitBlt copies the graphic data to a Device Context. A Device
Context is a data structure maintained by GDI. A device context is
'associated with a particular display device, such as a printer or
video display. For a video display, a device context is usually
'associated with a particular window on the display, but it can also
be an offscreen display.

'What you do, is create a Device Context and then associate a Bitmap
with the Device Context ( with SelectObject ). Then you
' draw to the Device Context ( using BitBlt ) to alter the Bitmap.
You can't use GDI functions to directly draw to a bitmap.

'After using a Device Context, you need to clean stuff up ( release
and delete ) or else the device context stays locked and
' other attempts to draw again will fail. Also not cleaning up will
result in memory leaks.
--
Dennis in Houston


"James Westgate" wrote:

> Hi,
>
> You need to create a compatible device context. See my post on the 19th of
> July under Graphics.DrawIMage uses More memory
>
> James
>
> --
> Create interactive diagrams and flowcharts with ERM Diagram at
> http://www.crainiate.net
>
> Take the ERM Tour at http://www.flowchartcontrol.com
>
>
> "DraguVaso" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi,
> >
> > In the override of the Paint-method of a DataGridTextBoxColumn I want to
> > show an image with BitBlt, to see what I can gain there on performance.
> > The problem is: It doesn't show me the image in the DataGrid-Cell's, but a
> > black background...
> >
> > Does anybody has any idea what I am doing wrong?
> >
> > Thanks a lot in advance,
> >
> > Pieter
> >
> >
> > Declare Auto Function BitBlt Lib "GDI32.DLL" ( _
> > ByVal hdcDest As IntPtr, _
> > ByVal nXDest As Integer, _
> > ByVal nYDest As Integer, _
> > ByVal nWidth As Integer, _
> > ByVal nHeight As Integer, _
> > ByVal hdcSrc As IntPtr, _
> > ByVal nXSrc As Integer, _
> > ByVal nYSrc As Integer, _
> > ByVal dwRop As Int32) As Boolean
> > Private Const SRCCOPY As Integer = &HCC0020
> >
> > Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal
> > bounds As Rectangle, ByVal source As CurrencyManager, ByVal rowNum As
> > Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal
> > alignToRight As Boolean)
> > Dim rectB As New Rectangle
> > rectB = bounds
> > rectB.Width = rectB.Width + 1
> > Dim g3 As Graphics
> > g3 = Graphics.FromImage(fe.BackgroundImage)
> > 'fe.BackgroundImage is a bitmap I read from a stream (PixelFormat =
> > Format32bppPArgb)
> > Dim HDC1 As IntPtr = g.GetHdc
> > Dim HDC2 As IntPtr = g3.GetHdc
> > Me.BitBlt(HDC1, 0, 0, rectB.Width, rectB.Height, HDC2, 0,
> > 0,
> > SRCCOPY)
> > g.ReleaseHdc(HDC1)
> > g3.ReleaseHdc(HDC2)
> > ...
> >
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what s wrong with my BitBlt XOR method ? ΢ÈíÐÂÎÅ×é Microsoft C# .NET 1 10th Jul 2011 02:17 PM
display an image with BitBlt (in Paint-method) DraguVaso Microsoft Dot NET 2 29th Jul 2005 02:40 AM
display an image with BitBlt (in Paint-method) DraguVaso Microsoft VB .NET 2 29th Jul 2005 02:40 AM
Bitmap: how fill with image before call to BitBlt()? =?Utf-8?B?bm9sZWFuZGVy?= Microsoft VC .NET 3 27th Jun 2005 04:36 PM
question paint method Franck Microsoft C# .NET 4 8th Aug 2003 12:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:35 PM.