Solved

Cropping Image to Make Thumbnail Using Rectangle Object

Posted on 2009-05-19
4
340 Views
Last Modified: 2013-11-26
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
Comment
Question by:Sceler85
  • 2
  • 2
4 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24427356
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
 
LVL 1

Author Comment

by:Sceler85
ID: 24433206
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
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 24433768
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
 
LVL 1

Author Closing Comment

by:Sceler85
ID: 31583253
Awesome! Thanks for your help!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now