Wrox Programmer Forums
|
BOOK: Visual Basic 2010 Programmer's Reference
This is the forum to discuss the Wrox book Visual Basic 2010 Programmer's Reference by Rod Stephens; ISBN: 9780470499832
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2010 Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 23rd, 2011, 05:07 AM
Authorized User
 
Join Date: Nov 2011
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Smile Cloning section of a bitmap image

Hello,

I am really new to programming in Visual Basic 2010. I would like to know how to write the code so I can automatically clone a specified rectangular section of a given bitmap image and place the new image in a specified picture box.

For example, I have an image called kite.bmp and I want to clone a section consisting of the pixels 0 to 100 on the X axis and 0 to 100 on the Y axis and I want to place the new image in pictureBox1.

In my particular application this process would be done thousands of times per image, cloning a different specified section each time. Although I could use an imaging editing program like PhotoShop to do this on an individual basis, it would clearly be impractical to manually run this process so many times. That is why I need to write the code to run the process automatically. In affect would be breaking down the entire Bitmap image, one section at a time, into individual pictures.

If I can understand how to do one, I think I can write the code for them all. I have been stumped by this for days and it seems that it should be fairly straight forward. I anyone can help me I would greatly appreciate it.

Last edited by Gary108; November 23rd, 2011 at 11:10 AM.. Reason: Mispelled words and to make it easier to understand.
 
Old November 23rd, 2011, 11:07 AM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

This isn't too bad. Here are the steps.
  1. Create a new Bitmap that's the right size to hold the piece you are copying.
  2. Create a Graphics object to work with the new Bitmap.
  3. Use the Graphics object's DrawImage method to draw the part of the image you want into the new Bitmap.
See this example:
Copy part of an image into a new PictureBox in Visual Basic .NET
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
The Following User Says Thank You to Rod Stephens For This Useful Post:
Gary108 (November 23rd, 2011)





Similar Threads
Thread Thread Starter Forum Replies Last Post
invalid cross thread acces exception on creating a new bitmap image abhishekkashyap27 C# 4.0 aka C# 2010 General Discussion 11 August 6th, 2011 01:15 PM
New Image (Bitmap) instance or not? jacob C# 2005 0 April 4th, 2006 04:12 AM
Cloning a XmlTextReader billy_bob_the_3rd XML 0 March 28th, 2006 06:42 PM
Placing Image in Header Section Of Crystal Report B.V.Madhav BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 0 May 9th, 2005 02:44 AM
Read bitmap image? RichardRose C# 3 October 9th, 2004 11:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.