Im currently making a basic paint program in vc++.net that uses win32 API and GDI+. Im currently writing a save function. I created the sve file dialog(SaveFile) and the picturebox that gets saved (pictureBox1). Here is the code:
...
private: System::Void btnSave_Click(System::Object * sender, System::EventArgs * e)
{
if (SaveFile->ShowDialog() == DialogResult::OK)
{
CImage myImage = pictureBox1->Image; //line 229
myImage.Save(SaveFile->get_FileName,ImageFormat::Bmp); //line 330
}
}
...
When i try to compile the code i get this errror:
c:\Projects\Rectangle\Form1.h(229) : error C2440: 'initializing' : cannot convert from 'System::Drawing::Image __gc *' to 'ATL::CImage'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Projects\Rectangle\Form1.h(230) : error C2664: 'HRESULT ATL::CImage::Save(IStream *,const GUID &) throw() const' : cannot convert parameter 1 from 'System::String __gc *(void)' to 'IStream *'
There is no context in which this conversion is possible
Does anyone have any idea of what is going on?I dont=). If you do, please help a newb out
Thanks again,
Tim
Vanaj
July 27th, 2004, 06:41 PM
Can you post the code for c:\Projects\Rectangle\Form1.h(229) and c:\Projects\Rectangle\Form1.h(230)
CPPMe
July 27th, 2004, 06:58 PM
just changed it, look at commenting on source
Vanaj
July 27th, 2004, 07:03 PM
just changed it, look at commenting on source
I dont see line 229 or 230 of Form1.H in your code.
OK..now how is Image defined in pictureBox1 ?
OK..now how is get_FileName defined in SaveFileDialog ?
Vanaj
July 27th, 2004, 10:06 PM
c:\Projects\Rectangle\Form1.h(229) : error C2440: 'initializing' : cannot convert from 'System::Drawing::Image __gc *' to 'ATL::CImage'
No constructor could take the source type, or constructor overload resolution was ambiguous
pictureBox1->ImageIs returning the following typeSystem::Drawing::Image __gc *But CImage myImage =Is looking for the typeATL::CImage
c:\Projects\Rectangle\Form1.h(230) : error C2664: 'HRESULT ATL::CImage::Save(IStream *,const GUID &) throw() const' : cannot convert parameter 1 from 'System::String __gc *(void)' to 'IStream *'
There is no context in which this conversion is possible
SaveFile->get_FileName Is returning the following typeSystem::String __gc *(void)ButmyImage.Save()is looking for the following types of param passed to it.HRESULT Save(IStream* pStream,REFGUID guidFileType)
HRESULT Save(LPCTSTR pszFileName,REFGUID guidFileType= GUID_NULL)
Looks like some converting or casting is needed prior to assignments or function calls. I'm sure someone here can supply you with this info.Maybe if one of the Moderators move this to VC++ .NET you might get a better response.
CPPMe
July 28th, 2004, 12:04 AM
After much trial and error, i came up with the following code:
It builds fine, and starts fine, however, when i try to save, a little dialog box, titled "Rectangles"(the name of my app) and says: "An unhandled exception has occured..." after i select the details thing, i get the following error :
************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
at System.Drawing.Image.Save(String filename, ImageFormat format)
at Rectangle1.Form1.btnSave_Click(Object sender, EventArgs e) in c:\projects\rectangle\form1.h:line 230
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Vanaj
July 28th, 2004, 12:11 AM
if (SaveFile->ShowDialog() == DialogResult::OK)
{
CString fileName = SaveFile->FileName->ToString();
pictureBox1->get_Image()->Save(fileName);
}
Does the Saved filename have an extention of a valid image name. (jpg or bmp)
CPPMe
July 28th, 2004, 12:46 AM
I just changed the pictureBox1->get_Image()->Save(fileName); to Save(fileName,ImageFormat::Bmp);
But, i still get that same stupid error!!!!!,
c:\Projects\Rectangle\Form1.h(243) : error C2440: 'initializing' : cannot convert from 'overloaded-function' to 'ATL::CImage'
No constructor could take the source type, or constructor overload resolution was ambiguous
I think it has something to do with the var type, i think im gonna need some kind of conversion, but I dont know for sure
THANKS AGAIN THANKS THANKS THANKS
Vanaj
July 28th, 2004, 03:35 AM
OK now try the function I put in my code. get_Image and getImage are not the same functions and do not return the same thing, as best as I can undersatnd the limited MSDN doc's on this subject.
namespace Rectangle1
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Threading;
using namespace System::IO;
using namespace System::Drawing::Imaging;
int startX;
int startY;
int dMode = 0;
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
I figured out something, i had ...get_Image;, changed it to ..get_Image;.
Now i have a more clear error:
c:\Projects\Rectangle\Form1.h(233) : error C2440: 'initializing' : cannot convert from 'System::Drawing::Image __gc *' to 'ATL::CImage'
No constructor could take the source type, or constructor overload resolution was ambiguous
Line 233:
CImage myImage = pictureBox1->get_Image();
Vanaj
July 28th, 2004, 04:04 AM
Got a bad case of Teflon Brain...can't think anymore. I'll look somemore tomorrow.
CPPMe
July 28th, 2004, 04:06 AM
THANKS soooo sooo much,
Im gonna stay up tonight figuring out, ill post if i do.
Thanks again,
Tim
Yves M
July 28th, 2004, 07:38 AM
[ moved the thread to a more appropriate forum ]
CPPMe
July 28th, 2004, 01:43 PM
A.) How?
B.) What forum is the 'appropriate' forum?
Vanaj
July 28th, 2004, 01:55 PM
Move to the VC++ .NET forum, I asked Yves M to look at the post and see if it should be moved as there was little to no responses in the other forum. I thought there might be a better chance of getting a faster correct answer in the .NET forum than just the plain VC++ forum. I was just trying to get you some faster/better help. :blush:
CPPMe
July 28th, 2004, 02:14 PM
How do you move a thread?
Vanaj
July 28th, 2004, 02:35 PM
Can only be done by a Moderator, that is why I asked Yves M to take a look and have him make the call on the move.
CPPMe
July 28th, 2004, 02:37 PM
Thanx! =D
TYVM!
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.