p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Visual Basic 2010 Programmer's Reference (http://p2p.wrox.com/forumdisplay.php?f=551)
-   -   Cloning section of a bitmap image (http://p2p.wrox.com/showthread.php?t=85785)

Gary108 November 23rd, 2011 05:07 AM

Cloning section of a bitmap image

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.

Rod Stephens November 23rd, 2011 11:07 AM

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

All times are GMT -4. The time now is 10:45 PM.

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