473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

cropping an image to size...?

hi there,

i'm uploading to my photo gallery and this is what i'm after..

When user uploads image, i automatically create a 75x75 thumbnail, however
using the GetThumbnailImage function drops the quality and distorts it, so
what i would like to do is:

resize the original image to:
Width: 75px
Heigh: relative size to image

then any additional size outside the bounds of 75x75 to be cropped so i get
a non-distorted thumbnail image.

This is the code i have so far...any help appreciated,
-----------------------------------------------------------------
Sub ResizeImage(ByVal s As IO.Stream, ByVal outputFilename As String)
Dim oImage As System.Drawing.Image =
System.Drawing.Image.FromStream(s)

Dim newWidth, newHeight As Integer
newWidth=75
newHeight=75

'''here i'd like to resize the original image first to width=75,
height = relative to width resize, then crop off any unneeded bits of the
image outside the 75x75 bounds.

Dim bmpOut As New Bitmap(newWidth, newHeight)
Dim g As Graphics = Graphics.FromImage(bmpOut)
g.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQua lityBicubic
g.FillRectangle(Brushes.White, 0, 0, newWidth, newHeight)
g.DrawImage(oImage, 0, 0, newWidth, newHeight)
oImage.Dispose()

bmpOut.Save(outputFilename, System.Drawing.Imaging.ImageFormat.Jpeg)
g.Dispose()
g = Nothing
bmpOut.Dispose()
bmpOut = Nothing
oImage.Dispose()
oImage = Nothing
End Sub
-----------------------------------------------------------------
thanks,
Paul.
Apr 25 '06 #1
2 1823
Check out this article:
http://www.codeproject.com/csharp/imageresize.asp
--
Eirik Eldorsen
Apr 25 '06 #2
thanks, looks like just what i was after.

regards,
Paul

"Eirik Eldorsen" <ku*******@hotmail.com> wrote in message
news:ur**************@TK2MSFTNGP05.phx.gbl...
Check out this article:
http://www.codeproject.com/csharp/imageresize.asp
--
Eirik Eldorsen

Apr 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ralph Freshour | last post by:
Is there anyway to crop .jpg images so that they are all of the same width and height? I use the following math to calculate the correct aspect ratio: width / height == aspect ratio so if I...
1
by: Duncan Smith | last post by:
Hello, Can anyone advise me how to crop an EPS image generated by dislin. I can't figure out how to crop the image before generating it. Using PIL to crop the generated image I get an IOError...
3
by: Paul E Collins | last post by:
I need to load a bitmap image, crop it, and save it. By cropping, I don't mean resizing - I mean reducing it to a fixed size area. Image img = Bitmap.FromFile("in.bmp"); // what goes here?...
0
by: AmerS | last post by:
hi, I have been trying to generate image patches for a training set but have not succeded yet. The only method i tried is cropping areas of the image and store the cropped images or patches as an...
2
by: kumari | last post by:
Hi, I am facing a problem with generation of thumbnail images in php. The requirement is as follows: the client would provide the image url, description, and content through a page. and the...
0
by: lalithabhamidi | last post by:
Hai i am using GDIplus and working on VC++ 6.0.Please can u help me on Removing red eye and cropping an Image.I immediately need ur help. Thanks in advance for ur help.
1
by: jpuopolo | last post by:
All: I looked around and could not find a simple yet complete example of cropping an image in C#. I had the problem of needing to shave off the bottom-most 18 lines of a directory full of...
1
by: MUHAMMAD RAFIQUE | last post by:
1-How to crop a image in Visual Basic 2- How to save the in the same Jpg file after Cropping
3
by: mcfly1204 | last post by:
I have a photo cropping tool in place that fits my needs, with one exception. When a user uploads a high res. photo, it does not fit on the screen. I have a zoom feature that allows the image to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.