Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
clone(Bitmap,format) Compiler say there is no overload that takes 2 arguments

Microsoft docs describes the method ( with 2 arguments) for net frameworks 1.2 to 4.7.2

(Bitmap.Clone Method (System.Drawing) | Microsoft Docs[^])

I am using framework 4.5 and visual studio 2012 Express

I have searched the internet but have not found any reference to such a problem

what am i missing?

What I have tried:

I haven't been able to find any way to force the compiler to accept the method call
Posted
Updated 1-Nov-18 1:21am
Comments
Richard MacCutchan 31-Oct-18 10:07am    
Please edit your question and show the actual code, and the actual error message.

Also it would help if you formatted your code blocks properly. And please do not add updates as solutions, edit your question to add updates, and use the Reply buttons to respond to answers.

You're missing some parenthesis.

newImage = ((Bitmap)image).Clone(sRec,PixelFormat.Format16bppArgb1555);


In your original code

"(Bitmap)image.Clone"

You are calling the Clone method on whatever type image is, you're not calling it on image cast to Bitmap. By adding the parenthesis you are calling Clone on the result of casting image to Bitmap.
 
Share this answer
 
Comments
MartinXLord 31-Oct-18 13:39pm    
thanks for your comments

image is read from file "image = new Bitmap(openFileDialog1.FileName);"
2 lines before the clone

The cast is there because image.Clone returns an object

I amended the line to:-

newImage = (Bitmap)(image.Clone(sRec,PixelFormat.Format16bppArgb1555));

same compiler error message!

but:-

newImage = (Bitmap)(image.Clone());

is accepted!
Edit


the source line is:-

newImage = (Bitmap)image.Clone(sRec,PixelFormat.Format16bppArgb1555);

newImage is defined in the class Form1 : Form by:-

"Bitmap newImage = null;"

The compiler message was:-

'Error:
No overload for method "Clone" takes 2 arguments'
 
Share this answer
 
Comments
Richard MacCutchan 31-Oct-18 12:34pm    
And what is image defined as? A much more important piece of information.
Richard Deeming 2-Nov-18 11:46am    
If you want to update your question, click the green "Improve question" link and edit your question.

DO NOT post your update as a "solution".
I have now tested this with Visual Studio 2017

Compiles OK - no error message
 
Share this answer
 
Comments
Richard Deeming 2-Nov-18 11:47am    
Yet another non-solution posted as a "solution" - and this time, you've even accepted it as the "answer" to your question!
MartinXLord 4-Nov-18 8:03am    
Apologies for my misdeeds - it is some years since I posted a query!

As for the "answer" it is an answer to the problem of getting the code to work and make further progress on the project.

But I agree that it is not the answer to the question as posed.

Thanks for spending your time on this.

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