Solved

Cropping Image to Make Thumbnail Using Rectangle Object

Posted on 2009-05-19
4
350 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studio 2013 Shortcut (VB) 4 34
Help with Query not working in client's PC 1 35
Tool Box 2 34
Anyway to make "All" the default in the dropdown? 6 34
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

919 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

14 Experts available now in Live!

Get 1:1 Help Now