Results 1 to 5 of 5

Thread: .NET code to crop an image, is it possible???

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Posts
    150

    .NET code to crop an image, is it possible???

    Hello,

    I have a *.tiff image.

    I am wondering if it is possible to provide a coded solution to crop a section of this *.tiff image and return the cropped section in a format that can be displayed by a browser. i.e *.jpg

    Any help is greatly appreicated

    Thanks

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: .NET code to crop an image, is it possible???

    Create a bitmap object with the right size and then create a Graphics object that uses the bitmap as its drawing surface. Use Graphics.DrawImage(...) to copy the area (that you want to keep) to the blank bitmap and then call Bitmap.Save() and specify jpeg as the type.
    I don't live here any more.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Posts
    150

    Re: .NET code to crop an image, is it possible???

    thanks

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Posts
    150

    Re: .NET code to crop an image, is it possible???

    One slight problem

    In my code I have
    ...
    Dim cropWidth = CInt(TextBox6.Text))
    Dim cropHeight =CInt(TextBox7.Text))
    Dim rect As Rectangle = New Rectangle(cropX, CropY, cropWidth, cropHeight)
    ...
    Dim imgCropped As New Bitmap(CInt(cropWidth), CInt(cropHeight))
    Dim g As Graphics = Graphics.FromImage(imgCropped)
    g.DrawImage(myBitmap, 0, 0, rect, GraphicsUnit.Pixel)


    Tho when the cropped image is created the actual bitmap width seems to be approx twice as wide and twice as long as the actual cropped section and the rest is all black (i.e only the upper left corner contains the cropped part and the rest is empty space) SEE ATTACHED IMAGE
    Is this something to do with pixels or what?, I was under the assumption that because I had set the bitmap size to that of the cropped width and height sizes that the actual cropped bitmap would be the exact same size as the cropped area?

    Any ideas on how to fix this?
    Attached Images Attached Images  
    Last edited by eakin; Oct 9th, 2006 at 09:13 AM.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Posts
    150

    Re: .NET code to crop an image, is it possible???

    Added extra information and attachment above
    Any help is greatly appreciated

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width