Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. i have a problem in Croping an image?

i have a problem in Croping an image?

Scheduled Pinned Locked Moved C#
csharpgraphicshelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maifs
    wrote on last edited by
    #1

    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

    G M 2 Replies Last reply
    0
    • M maifs

      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

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • M maifs

        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

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        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:

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups