• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 370
  • Last Modified:

Cropping Image to Make Thumbnail Using Rectangle Object

I am writing a program to manage an online image gallery and would like to include thumbnail creation.

I would like the user to be able to select a region of a JPG by dragging a 100 x 100 pixel rectangle object around within a picturebox.

I would then like to be able to take the area of the image that lies within the bounds of the rectangle and save it as its own JPG.

I've not done any work with image manipulation in VB before, and I am just looking for input or advice on making this happen. It seems like it should be easy enough, but I don't know where to start.
 
Thanks!
0
Sceler85
Asked:
Sceler85
  • 2
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
What version VB.net you working with?

What size are the source images?  Do they need to be able to see the whole thing at once?...or should it be scrollable?

Is the rectangle sizeable?...anything UP TO 100x100?...or should it be FIXED at 100x100?
0
 
Sceler85Author Commented:
I'm working with VB 2008.

Source Images will be around 800 X 600. I'm really looking to support variable dimensions over 100 X 100.

The 100 X 100 size is fixed. Ideally, I would like to open an additional form displaying the whole image, and allow the user to move around a rectangle to select the thumbnail. Thinking about it now, I can code the draggable rectangle pretty easily, so I really just need to know how to take the area of the JPG under the rectangle and convert it to it's own JPG.

I'm not completely opposed to defining the thumbnail by scrollbars as a last resort.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Ok...lemme know if you end up needing help implementing the actual selection part.

Once you have a "source" rectangle, you would just something like:
(assuming your source image is in PictureBox1)
        Dim sourceRC As New Rectangle(New Point(34, 101), New Size(100, 100))
        Dim bmp As New Bitmap(sourceRC.Width, sourceRC.Height)
        Dim G As Graphics = Graphics.FromImage(bmp)
        G.DrawImage(PictureBox1.Image, 0, 0, sourceRC, GraphicsUnit.Pixel)
        G.Dispose()
        bmp.Save("c:\someFile.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
 
        ' for demonstration purposes:
        PictureBox2.Image = bmp

Open in new window

0
 
Sceler85Author Commented:
Awesome! Thanks for your help!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now