473,804 Members | 3,019 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MC LockBits method

(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: System::Void btn1_Click(Syst em::Object * sender, System::EventAr gs * e)
{
//Create Grphics object
Graphics * gr = CreateGraphics( );

//Create a bit map
System::Drawing ::Bitmap * B = new System::Drawing ::Bitmap(500,50 0);

//Create a Clone
System::Drawing ::Rectangle rect(0,0,500,50 0);
System::Drawing ::Bitmap * bitmap = B-> System::Drawing ::Bitmap::Clone
(rect,System::D rawing::Imaging ::PixelFormat:: Format32bppArgb );
//Create a BitmapData object (bitmapData), and then use LockBits/UnlockBits to save pixel information
System::Drawing ::Imaging::Bitm apData * bitmapData = new System::Drawing ::Imaging::Bitm apData;

bitmap->System::Drawin g::Bitmap::Lock Bits(rect, System::Drawing ::Imaging::Imag eLockMode::Read Write, System::Drawing ::Imaging::Pixe lFormat::Format 32bppArgb);

Int32 p[,]= new Int32[500,500];

for (int y=0; y<500; ++y) {
for(int x=0; x < 500; ++x) {

p[y,x] = 0xff00ffff;

}
}

bitmapData->set_Width(500) ;
bitmapData->set_Height(500 );
bitmapData->set_Stride(4*5 00);
bitmapData->set_PixelForma t(System::Drawi ng::Imaging::Pi xelFormat::Form at32bppArgb);
bitmapData->set_Scan0((Sys tem::IntPtr)&p) ;
bitmapData->set_Reserved(N ULL);

bitmap->UnlockBits(bit mapData);

gr->DrawImage(bitm ap,20,80);
gr->Dispose();

}
--------------------------------
From: Learner Net

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>fjvQsseDMkS tSn3nnbGrWA==</Id>
Nov 17 '05 #1
0 1940

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

Similar topics

11
3630
by: Dave Rahardja | last post by:
OK, so I've gotten into a philosophical disagreement with my colleague at work. He is a proponent of the Template Method pattern, i.e.: class foo { public: void bar() { do_bar(); } protected: virtual void do_bar() {} };
5
15380
by: Chris | last post by:
Hi I have a scenario where I've created another AppDomain to dynamically load a DLL(s) into. In this newly loaded DLL I want to call a static method on a class. The problem arise is that I have the same class/static method definition statictly linked to my EXE and when I call InvokeMember(...), even though I got the Type from the new AppDomain, it calls the static method that I am staticly linked to and not the static method in the dynamicly...
4
2908
by: daniel.w.gelder | last post by:
I wrote a template class that takes a function prototype and lets you store and call a C-level function, like this: inline string SampleFunction(int, bool) {..} functor<string (int, bool)> myFunctor = SampleFunction; string result = myFunctor(7, true); Works great thanks to the help from this group. Here's the guts so far for two-arity:
7
1754
by: greenflame | last post by:
I am trying to make a matrix object. I have given it some properites. I am trying to add a method. When I call the method by Test.showDims(...) I want to only enter one input, that is the method by which to do it. As you can see from the object definition that it corresponds to a function that takes two inputs. When I try to run the script it does nothing. So what is wrong and how do I fix it? Here is the script. function...
5
3446
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
0
1376
by: Iwanow | last post by:
Hello! I'm using Bitmap->LockBits method to copy its pixels into an array according to example found on http://msdn2.microsoft.com/en-us/library/5ey6h79d.aspx . Now I need to use pixels' brightness. How do I get such info? I guess that requires some special PixelFormat argument. Thanks in in advance for all hints.
3
8840
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?
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
3855
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
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9575
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10320
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10073
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7609
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
6846
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
5513
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...
1
4288
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
3
2981
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.