473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

display an image with BitBlt (in Paint-method)

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)
....
Jul 28 '05 #1
2 2411
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" <pi**********@hotmail.com> wrote in message
news:eM**************@tk2msftngp13.phx.gbl...
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)
...

Jul 28 '05 #2
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" <pi**********@hotmail.com> wrote in message
news:eM**************@tk2msftngp13.phx.gbl...
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)
...


Jul 29 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Philipp Lenssen | last post by:
I created Search.CSS which grabs Google results (using the Web API), displays as XHTML1.0 Strict + CSS, and recently also adds Thumbnails....
0
by: Qindong Zhang | last post by:
My asp.net application send image to web browser. The browser begin to display image before download finished. (In Slow Network). How can I force brower to display image after the image downloaded? ...
1
by: Tan | last post by:
Hi I am desperate for any help with display image in Gridview I have a gridview contain surname , forename ..... and image. I could not display image as my database store the column image as...
3
by: harish | last post by:
Hi friends I am facing problem as follow I can't display image from SQL Database to Picture box Control. Here are the codes that I am writing Dim arrPicture() As Byte = _
2
by: David | last post by:
I am trying to get an image to appear on all Mondays within the calendar control. I also want that image to be a link. How can I do this?
3
by: den 2005 | last post by:
Hi everyone, Here is code working on..Trying to insert record with a column with Image or VarBinary datatype in sql database from a existing jpeg image file, then retrieve this image from...
3
by: Ladislav Andel | last post by:
Hi, I'm trying to display image through my cgi script in HTML page via <img src="image.cgi"> Can you give me an example, please? What should be in the cgi script to display it? Here is what...
7
by: alexseow | last post by:
Query.asp <%@ LANGUAGE="VBSCRIPT" %> <!-- #include file="../../includes/dbconn.asp"--> <% dim MyRs, sqlstr, MyConn Response.Expires = 0 Response.Buffer = TRUE Response.Clear
5
by: faizalahmd | last post by:
How to display image in image control , which is retrieved from the data base . using c# in asp.net regards, FAIZAL AHMED.H
0
by: dbdb | last post by:
hi, i work with ms. access 2003 i want to display image from a folder to the report. i have read thread in http://bytes.com/topic/access/answers/191611-pictures-access-reports but that's...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.