i have a problem in Croping an image?
-
private void button1_Click(object sender, EventArgs e) { Rectangle cropArea = new Rectangle(20, 20, 10, 10); Pic = cropImage(bmpPicture,cropArea); bmpPicture = Pic; } public Image cropImage(Image img, Rectangle cropArea) { Bitmap bmpImage = new Bitmap(img); Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat); return (Image)(bmpCrop); } i am trying this but here is some error generated. error is : Error 1 Cannot implicitly convert type 'System.Drawing.Image' to 'System.Drawing.Bitmap'. An explicit conversion exists (are you missing a cast?) D:\dot.net.programs.using.c#\temp\scallingImage\scallingImage\Form1.cs 89 23 scallingImage
hghghgh
-
private void button1_Click(object sender, EventArgs e) { Rectangle cropArea = new Rectangle(20, 20, 10, 10); Pic = cropImage(bmpPicture,cropArea); bmpPicture = Pic; } public Image cropImage(Image img, Rectangle cropArea) { Bitmap bmpImage = new Bitmap(img); Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat); return (Image)(bmpCrop); } i am trying this but here is some error generated. error is : Error 1 Cannot implicitly convert type 'System.Drawing.Image' to 'System.Drawing.Bitmap'. An explicit conversion exists (are you missing a cast?) D:\dot.net.programs.using.c#\temp\scallingImage\scallingImage\Form1.cs 89 23 scallingImage
hghghgh
1. Use pre tags for posting code. 2. You are assigning Image variable to an instance of Bitmap class. Either return Bitmap from cropImage function or cast the result to Image.
Giorgi Dalakishvili #region signature my articles My blog[^] #endregion
-
private void button1_Click(object sender, EventArgs e) { Rectangle cropArea = new Rectangle(20, 20, 10, 10); Pic = cropImage(bmpPicture,cropArea); bmpPicture = Pic; } public Image cropImage(Image img, Rectangle cropArea) { Bitmap bmpImage = new Bitmap(img); Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat); return (Image)(bmpCrop); } i am trying this but here is some error generated. error is : Error 1 Cannot implicitly convert type 'System.Drawing.Image' to 'System.Drawing.Bitmap'. An explicit conversion exists (are you missing a cast?) D:\dot.net.programs.using.c#\temp\scallingImage\scallingImage\Form1.cs 89 23 scallingImage
hghghgh
I think Giorgi meant to state "cast the result to Bitmap" :) The error message explains the problem and a solution. It can be helpful to us if you point out the line the error occurs on as well.
maifs wrote:
return (Image)(bmpCrop);
This cast isn't necessary. Bitmap is derived from Image so the bmpCrop object is already an Image.
Mark Salsbery Microsoft MVP - Visual C++ :java: