Click here to Skip to main content
16,022,129 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: , +
Hi, I have a small application using Visual C++, Windows Forms - VS 2015.

In C# I use the below codes to convert the Image to Byte..

System.Drawing.Image MyImg;
ImageConverter converter = new ImageConverter();
(byte[])converter.ConvertTo(MyImg, typeof(byte[]));


For Visual C++ I convert like the below, Kindly guide me to correct me, Thanks

System::Drawing::ImageConverter^ MyImgConverter = gcnew System::Drawing::ImageConverter();
				cli::array<Byte^>^ ImageControls = MyImgConverter->ConvertTo(MyImg, cli::array<Byte>());   ????? 


Thanks For The Helps Again !

What I have tried:

I try to convert the Image in Byte format.
Posted
Comments
[no name] 8-Oct-24 10:37am    
You forgot to explain what your problem is. Please use the Improve question link above, and add complete details of what is not working.
Paramu1973 8-Oct-24 12:05pm    
Thanks Richard! Always Remembering Your helps! You are the strength to my Profession! I will always keep in my mind! Great!
0x01AA 8-Oct-24 10:52am    
ChatGPT means:
using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;

Image^ MyImg; // Assuming MyImg initalized
ImageConverter^ converter = gcnew ImageConverter();
array<Byte>^ byteArray = safe_cast<array<Byte>^>(converter->ConvertTo(MyImg, array<Byte>::typeid));
Paramu1973 8-Oct-24 11:29am    
Great! Thanks! I got the answer!
0x01AA 8-Oct-24 11:35am    
Does it mean the above ChatGPT code is correct?

1 solution

I asked ChatGPT to convert the c# code to VC++....

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;

Image^ MyImg; // Assuming MyImg initalized
ImageConverter^ converter = gcnew ImageConverter();
array<Byte>^ byteArray = safe_cast<array<Byte>^>(converter->ConvertTo(MyImg, array<Byte>::typeid));


... and according to OP the code works.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900