473,791 Members | 3,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Lockbits vs BitBlt

_DD
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?
Jan 12 '07 #1
3 8839
The two principles are totally different.

BitBlit and incidentally DrawImage is for copying an image in memory to
the graphics object. Either a graphics device such as a screen or a
second in-memory graphics object.

LockBits enables direct access to the image byte array without the need
to go through the less efficient bitmap image APIs. Access in this way
is fast and unsubtle.

Where LockBits even approaches the philosophy of BitBlit is when a
direct image to image copy operation is needed. In this case LockBits
may be used to access both memory buffers and data transferred from one
to the other. Any form of clever image processing in this transfer
begins to approach the inefficiency of DrawImage if any processing is
done on the image data.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

_DD wrote:
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?
Jan 12 '07 #2
_DD
On Fri, 12 Jan 2007 07:09:44 +0100, "Bob Powell [MVP]"
<bob@_spamkille r_bobpowell.net wrote:
>The two principles are totally different.

BitBlit and incidentally DrawImage is for copying an image in memory to
the graphics object. Either a graphics device such as a screen or a
second in-memory graphics object.

LockBits enables direct access to the image byte array without the need
to go through the less efficient bitmap image APIs. Access in this way
is fast and unsubtle.
I didn't explain the intent very well. A closer analogy would have
been 'DibSection + BitBlt' vs 'LockBits + DrawImageUnscal ed.'
I'm thinking about revisiting an app that I worked on ages ago in olde
C++ (seems way too long ago).
>Where LockBits even approaches the philosophy of BitBlit is when a
direct image to image copy operation is needed. In this case LockBits
may be used to access both memory buffers and data transferred from one
to the other.
That's about it. The app basically builds a screen behind the scenes
by stamping graphics images into ram, cookie-cutter style. Envision
something like an schematic cad system with preset resistor and
capacitor symbols in monochrome bit patterns. Not an animation, per
se, but I need to do a complete BitBlt on a large window.

If memory serves, I was using DibSections and/or a 'magic'
undocumented ROP, 0xE20746, which does the cookie cutter thing quite
efficiently (Not sure why that was not documented).

In the interim, I've written some C# code where I had to do something
vaguely like that. I ended up using Lockbits to access ram and stamp
the pattern, then DrawImageUnscal ed() to blt it.

I've heard that to get sufficient speed that C# programmers are still
Interop'ing older Dibsection/BitBlt calls. Can LockBits get close to
that speed? Maybe I should just be thinking DirectX, but this is
almost like a schematic cad program, not a game.

[re Lockbits]
Any form of clever image processing in this transfer
begins to approach the inefficiency of DrawImage if any processing is
done on the image data.
You got me there. I thought that would be the fast part.
Jan 12 '07 #3
_DD
On Fri, 12 Jan 2007 00:27:02 -0800, TheMadHatter
<Th**********@d iscussions.micr osoft.comwrote:
>using LockBits and unsafe code:
Is it suppose to actualy lock the data in memory???????

I found out the bitter way that it is safer to create the
bitmap data, pin it, and wrap the bitmap class around it.
That way it was ptr safe. LockBits alone isnt "safe".

What the lockBits for then?????
Is it simular to lock(someObj) ???????
It will be interesting to hear what Bob says about that, but I thought
LockBits was supposed to do something like what you described above.
However, I do have an app that uses LockBits where the display
flatlines once in a while. I had NOT attributed that to LockBits or
memory reallocation, but it's so sporadic that it's tough to trace
(does not happen under the debugger).

Do you have places where you know that Lockbits has failed to keep ram
from being moved?

Jan 12 '07 #4

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

Similar topics

2
2465
by: DraguVaso | last post by:
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,
5
16996
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: dstGr = args.graphics; srcGr = Graphics.FromImage( bitmap ); dstHdc = dstGr.GetHdc(); srcHdc = srcGr.GetHdc(); BitBlt( dstHdc, x, y, width, height, srcHdc, 0, 0, rop ); What am I doing wrong? A complete demo program follows.
0
1940
by: Learner Net via .NET 247 | last post by:
(Type your message here) What I am trying to do is create a bit map image from scatch using the managed C++ LockBits method. I want to display the bit map as a result of a button click. I have tried several alternative approaches but can't get it to work. I show some typical coding below as an example. Please excuse the errors as I am new to .NET and relatively new to C++ in general. Any help would be greatly appreciated. private:...
7
2436
by: VB Programmer | last post by:
I am using the BitBlt operation to capture various controls into jpegs. It's almost like a screen capture, but of just the control. (This is a VB.NET application.) Because of BitBlt limitations I know that the application has to always be on top. The problem: I am running this application on a Windows Server 2003 PC. The server is in another state (North Carolina). I am in Florida. I access the server over Termincal Server /Remote...
1
2177
by: RT | last post by:
It was mentioned here that LockBits can sometimes be vulnerable to the GC. Though the implication of docs that I've seen regarding LockBits would imply that it is immune to the GC, I do have an app where a custom control seems to lose its buffer and starts displaying random data. Of course that couldn't be a bug in my code. <g (it does seem to wait a while, and it happens at random). Seriously, has anyone heard of this? Any way to guard...
2
3854
by: =?Utf-8?B?VGhlTWFkSGF0dGVy?= | last post by:
I dont know if I missed something in documentation, but I was having a problem with "Bitmap.LockBits" and was wondering if anyone else has discovered it too. According to everyones examples including some of the MVP's website examples, one could use unmanaged code to manipulate a bitmap by casting the IntPtr from the Bitmap.LockBits to say an (int*). The problem I found is that the bitmap would rarely
6
7507
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 small, compilable and runnable program that shows the
1
3164
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 form into a picture box. - To do this, I bitblt using the device contexts of the form and a bitmap object. - After blitting, the bitmap image is always blank. I don't understand what
0
1809
by: crankeboy | last post by:
Hi Folks, My setup: Visual Studio Express 2008, VC++, .NET, BitBlt Here is a summary of the problem: - I am trying to copy a bitmap of my main form into a picture box. - To do this, I bitblt using the device contexts of the form and a bitmap object. - After blitting, the bitmap image is always blank. I don't understand what I'm doing wrong here. Here is my relevant code:
0
10427
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10155
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5431
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.