473,657 Members | 2,556 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 GetThumbnailIma ge 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(ByV al s As IO.Stream, ByVal outputFilename As String)
Dim oImage As System.Drawing. Image =
System.Drawing. Image.FromStrea m(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.FromIm age(bmpOut)
g.Interpolation Mode =
System.Drawing. Drawing2D.Inter polationMode.Hi ghQualityBicubi c
g.FillRectangle (Brushes.White, 0, 0, newWidth, newHeight)
g.DrawImage(oIm age, 0, 0, newWidth, newHeight)
oImage.Dispose( )

bmpOut.Save(out putFilename, System.Drawing. Imaging.ImageFo rmat.Jpeg)
g.Dispose()
g = Nothing
bmpOut.Dispose( )
bmpOut = Nothing
oImage.Dispose( )
oImage = Nothing
End Sub
-----------------------------------------------------------------
thanks,
Paul.
Apr 25 '06 #1
2 1832
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*******@hotm ail.com> wrote in message
news:ur******** ******@TK2MSFTN GP05.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
2279
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 need a 268 w x 176 h I do this: target width 268 / aspect ration == correct height
1
1933
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 (apparently because I'm using Windows). I could use other file formats, but I'm not too keen on the results I'm getting from using e.g. .tif. Basically I need to copy (publication quality) images created in dislin and paste them into word...
3
11297
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? img.Save("out.bmp"); img.Dispose();
0
1948
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 array of bytes. The problem is, same patch gets stored thoughout the array, meaning its cropping the same area in the loop and the rectangle is not moving, could some one explain to me why, Thank You. heres the code: MemoryStream stream = new...
2
1781
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 same information will be stored in database. While displaying all images i should take that url. and read it byte by byte and pass to a curl function where in it crops and echos.. the cropped version of image.
0
1194
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
5665
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 images. The following code does this. I hope that this serves as a concise yet complete example of how to tackle cropping an image. --- Note that inputDireName and outputDirName have been set in the class
1
1699
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
2902
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 fit on the screen, but then the user is cropping the downsized image and not the original. I would like to find a way to have the cropped area on the original image correspond with the cropped area on the zoomed image. Any thoughts? I have...
0
8827
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7333
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6167
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1620
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.