(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>