473,320 Members | 1,955 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,320 software developers and data experts.

GDI+, BitBlt instead of DrawImage

Hi there

I'm trying to use BitBlt function instead od DrawImage beacuse I need speed
in my app. I have one Bitmap (bmp) that is loaded from file and I use it in
OnPaint for drawing. Currently I use this code, but it does not work (it
draws only black). What am I missing ?!

public int LoadImage (string strFileName)
{
// load bitmap
bmp=new Bitmap (strFileName);
this.CreateGraphics().DrawImage (bmp,0,0);
}

private void EasyFormCtrl_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
if (bmp!=null)
{
Graphics g2 = Graphics.FromImage(bmp);
IntPtr dc1 = e.Graphics.GetHdc();
IntPtr dc2 = g2.GetHdc();

BitBlt(dc1, e.ClipRectangle.Left, e.ClipRectangle.Top,
e.ClipRectangle.Width, e.ClipRectangle.Height,
dc2, e.ClipRectangle.Left, e.ClipRectangle.Top, 0x00CC0020);
//SRCCOPY (DWORD)0x00CC0020 dest = source

e.Graphics.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);

// -> this code works ok, but it is slow !!!
// GraphicsUnit units = GraphicsUnit.Pixel;
// e.Graphics.DrawImage (bmp, e.ClipRectangle, e.ClipRectangle, units);
// <-
}
}
Best regards,
Ivan
Nov 15 '05 #1
1 10017
Perhaps the Graphics context that you load the bitmap into from file, is
not the same graphics context you get from the PaintEventArgs.

"Ivan" <no******@today.com> wrote in message
news:bs**********@fegnews.vip.hr...
Hi there

I'm trying to use BitBlt function instead od DrawImage beacuse I need speed in my app. I have one Bitmap (bmp) that is loaded from file and I use it in OnPaint for drawing. Currently I use this code, but it does not work (it
draws only black). What am I missing ?!

public int LoadImage (string strFileName)
{
// load bitmap
bmp=new Bitmap (strFileName);
this.CreateGraphics().DrawImage (bmp,0,0);
}

private void EasyFormCtrl_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
if (bmp!=null)
{
Graphics g2 = Graphics.FromImage(bmp);
IntPtr dc1 = e.Graphics.GetHdc();
IntPtr dc2 = g2.GetHdc();

BitBlt(dc1, e.ClipRectangle.Left, e.ClipRectangle.Top,
e.ClipRectangle.Width, e.ClipRectangle.Height,
dc2, e.ClipRectangle.Left, e.ClipRectangle.Top, 0x00CC0020);
//SRCCOPY (DWORD)0x00CC0020 dest = source

e.Graphics.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);

// -> this code works ok, but it is slow !!!
// GraphicsUnit units = GraphicsUnit.Pixel;
// e.Graphics.DrawImage (bmp, e.ClipRectangle, e.ClipRectangle, units);
// <-
}
}
Best regards,
Ivan

Nov 15 '05 #2

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

Similar topics

5
by: JackS | last post by:
I am trying to use GDI32 bitblt to write a bitmap to a control's window, but all I get is an empty rectangle of some rop-dependent color. In short, I use the following logic in a paint event handler:...
4
by: pixel | last post by:
hi GDI ExtFloodFill doesn't "see" GDI+ colors ..ToArgb() doesn't work at all any suggestions br pixel
5
by: Pohihihi | last post by:
I am getting a generic GDI+ error on following code. Basically it is trying to capture screen image and save in a file. Is there a way to find more details on this error? Thanks for the help. ...
10
by: Jim Hubbard | last post by:
Can you use VB.Net to set a system-wide hook to intercept all GDI calls from GDI to the system's hardware? I want to intercept all GDI instructions sent to the system's hardware layer. As I...
12
by: iwdu15 | last post by:
hi, i created a paint program for my c++ class using a global GraphicsPath variable. i the, in the onpaint method, draw the line the users draws with the mouse. simple. the only problem is that...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
3
by: _DD | last post by:
I've heard that fast bitblt functions still need to resort to calling older Bitblt vs interop. Has this changed? Will GDI+ Lockbits come close to the speed of GDI BitBlt?
6
by: Martijn Mulder | last post by:
/* BitBlt.cs C# code using P/Invoke I have good reasons to use P/Invoke to get access to the Win32 API function BitBlt(). But I have trouble understanding the workings of it. Below is a...
1
by: =?Utf-8?B?Y3JhbmtlX2JveQ==?= | last post by:
Hi Folks, I'm not sure where this post belongs since I'm using managed vc.net, but the issue is around GDI BitBlt. Here is a summary of the problem: - I am trying to copy a bitmap of my main...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.