.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
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.
Re: .NET code to crop an image, is it possible???
1 Attachment(s)
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?
Re: .NET code to crop an image, is it possible???
Added extra information and attachment above
Any help is greatly appreciated