Click here to Skip to main content
15,889,992 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
AnswerRe: Saving Bitmap image data to HGLOBAL Pin
Mark Salsbery20-Jan-10 7:01
Mark Salsbery20-Jan-10 7:01 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
alleyes20-Jan-10 7:08
professionalalleyes20-Jan-10 7:08 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
Mark Salsbery20-Jan-10 7:18
Mark Salsbery20-Jan-10 7:18 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
alleyes20-Jan-10 7:29
professionalalleyes20-Jan-10 7:29 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
Mark Salsbery20-Jan-10 7:36
Mark Salsbery20-Jan-10 7:36 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
alleyes20-Jan-10 7:48
professionalalleyes20-Jan-10 7:48 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
Mark Salsbery20-Jan-10 8:03
Mark Salsbery20-Jan-10 8:03 
GeneralRe: Saving Bitmap image data to HGLOBAL [modified] Pin
alleyes20-Jan-10 8:34
professionalalleyes20-Jan-10 8:34 
Mark Salsbery wrote:
You can't directly copy from managed to unmanaged memory.
You can use Marshal::Copy though


I fully intended using the Marshal class for copying.


Mark Salsbery wrote:
You can also wrap
the pointer in an UnmanagedMemoryStream object so you
can use any managed functionality that uses a Stream object.


Now you threw me a bit. One of the things I was considering was saving the image to a managed memory stream object. Why consider unmanaged? By calling the Save method and then specifying BMP as the image type, I do get the BITMAPHEADERINFO.

This is what I'm building upon without doing the Save to Stream technique:

System::Drawing::Rectangle imgRect =
    System::Drawing::Rectangle(0, 0,
    MyImage->Width, MyImage->Height);
System::Drawing::Imaging::BitmapData^ bmpData =
    MyImage->LockBits(imgRect,
    System::Drawing::Imaging::ImageLockMode::ReadOnly,
    System::Drawing::Imaging::PixelFormat::Format32bppRgb);
int byteCount = bmpData->Stride * MyImage->Height;
array<Byte>^ bmpBytes = gcnew array<Byte>(byteCount);
Marshal::Copy(bmpData->Scan0, bmpBytes, 0, byteCount);
MyImage->UnlockBits(bmpData);


Once I have the image in an array shouldn't I be copying it to the HGLOBAL? Or should the destination be the HGLOBAL and forget about the array?

modified on Wednesday, January 20, 2010 2:42 PM

GeneralRe: Saving Bitmap image data to HGLOBAL Pin
alleyes20-Jan-10 9:17
professionalalleyes20-Jan-10 9:17 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
Mark Salsbery20-Jan-10 9:42
Mark Salsbery20-Jan-10 9:42 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
alleyes20-Jan-10 9:58
professionalalleyes20-Jan-10 9:58 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
Mark Salsbery20-Jan-10 10:07
Mark Salsbery20-Jan-10 10:07 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
alleyes20-Jan-10 10:09
professionalalleyes20-Jan-10 10:09 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
Mark Salsbery20-Jan-10 10:20
Mark Salsbery20-Jan-10 10:20 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
alleyes20-Jan-10 10:31
professionalalleyes20-Jan-10 10:31 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
alleyes20-Jan-10 10:45
professionalalleyes20-Jan-10 10:45 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
Mark Salsbery20-Jan-10 11:33
Mark Salsbery20-Jan-10 11:33 
GeneralRe: Saving Bitmap image data to HGLOBAL [modified] Pin
alleyes21-Jan-10 2:15
professionalalleyes21-Jan-10 2:15 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
Mark Salsbery21-Jan-10 5:19
Mark Salsbery21-Jan-10 5:19 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
alleyes21-Jan-10 5:33
professionalalleyes21-Jan-10 5:33 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
Mark Salsbery21-Jan-10 5:42
Mark Salsbery21-Jan-10 5:42 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
alleyes21-Jan-10 5:54
professionalalleyes21-Jan-10 5:54 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
Mark Salsbery21-Jan-10 6:05
Mark Salsbery21-Jan-10 6:05 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
Mark Salsbery21-Jan-10 6:19
Mark Salsbery21-Jan-10 6:19 
GeneralRe: Saving Bitmap image data to HGLOBAL Pin
alleyes21-Jan-10 9:20
professionalalleyes21-Jan-10 9:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.