Solved

Cropping Image to Make Thumbnail Using Rectangle Object

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

776 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