473,386 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

extracting part of a graphic in a PictureBox to the clipboard

hi,

i need to give the user the ability to extract a rectangular area of their
choice from a graphic displayed in a picture box to the clipboard, so they
can use it elsewhere.

say the graphic has an image of a house with a door in it and the user is
interested in the door. the rectangle is selected by placing the mouse on
the upper left corner of the door, pressing down on the left mouse button,
and draging it to the lower right corner of the door and releasing the
mouse. from the time the mouse is down till when the mouse is up, a light
rectangle surrounds the selected area. the surrounding rectangle grows and
shrinks as the dragging of the mouise moves. the user indicates his choice
by releasing the mouse and letting it go up, whereupon the area selected by
the rectangle is placed upon the clipboard.

i don't have much experience with graphics but i was able to figure out part
of the solution, but i'm missing part of it.

here is what i tried

i declared 4 form level integers, miTop, miLeft, miBottom, miRight, all of
which are set to -1 when the form loads.

in the picturebox during the mouse down event, miLeft is set to e.X, and
miTop to e.Y

during the mouse move event if miTop, miLeft are not -1, miRight is set to
e.X and miBottom is set to e.Y, and the bounding rectangle is drawn with the
following code in the mouse move event

Dim ev As PaintEventArgs

pic_Paint(sender, ev)

the pic_Paint is as follows

Private Sub pic_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles pic.Paint

Dim gr As Graphics = Me.pic.CreateGraphics

dim iWidth, iHeight as integer

iWidth = miRight - miLeft

iHeight = miBottom - miTop

'MY PROBLEM IS RIGHT HERE, BECAUSE I HAVE TO REMOVE A PREVIOUS SURROUNDING
RECTANGLE (IF THERE IS ONE) BEFORE MAKING THE NEXT LARGER OR SMALLER ONE

'OTHERWISE THE RECTANGLES JUST KEEP MULTIPLYING, AND I DON'T KNOW HOW TO
REMOVE A PREVIOUS BOUNDING RECTANGLE AND RETURN THE IMAGE TO ITS

'FORMER STATE, I CAN'T JUST MAKE A RECTANGLE WITH A BACKGROUND COLOR, I NEED
TO LEAVE THE IMAGE CLEAN AS IT IS

gr.DrawRectangle(Pens.Gray, Me.miLeft, Me.miTop, iWidth, iHeight) 'this
draws the rectangle

End Sub

in the mouse up event i need to do 2 things, extract the surrounded area,
and place it on the clipboard

i don't know how to do the extraction. i can extract to a invisible
PictueBox picHidden which i would size to extracted rectangle's size and set
its SizeMode to Normal, but i don't know the code to do the extraction.

i then can place the rectangle on the clipboad with

Clipboard.SetDataObject(Me.picHIdden.Image)

in summary i don't know the code to do 2 things. 1) remove a rectangle
drawn on graphic and return the graphic to its former state without
reloading the image, 2) how to extract a rectangle from a PictureBox.Image

thanks for any code and help, or if there is better way to do what i need to
do

ray


Jan 30 '06 #1
1 2476
You may be able to use the Picturebox's Graphic Object and BitBlt to copy the
area you want to a bitmap.
--
Dennis in Houston
"ray well" wrote:
hi,

i need to give the user the ability to extract a rectangular area of their
choice from a graphic displayed in a picture box to the clipboard, so they
can use it elsewhere.

say the graphic has an image of a house with a door in it and the user is
interested in the door. the rectangle is selected by placing the mouse on
the upper left corner of the door, pressing down on the left mouse button,
and draging it to the lower right corner of the door and releasing the
mouse. from the time the mouse is down till when the mouse is up, a light
rectangle surrounds the selected area. the surrounding rectangle grows and
shrinks as the dragging of the mouise moves. the user indicates his choice
by releasing the mouse and letting it go up, whereupon the area selected by
the rectangle is placed upon the clipboard.

i don't have much experience with graphics but i was able to figure out part
of the solution, but i'm missing part of it.

here is what i tried

i declared 4 form level integers, miTop, miLeft, miBottom, miRight, all of
which are set to -1 when the form loads.

in the picturebox during the mouse down event, miLeft is set to e.X, and
miTop to e.Y

during the mouse move event if miTop, miLeft are not -1, miRight is set to
e.X and miBottom is set to e.Y, and the bounding rectangle is drawn with the
following code in the mouse move event

Dim ev As PaintEventArgs

pic_Paint(sender, ev)

the pic_Paint is as follows

Private Sub pic_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles pic.Paint

Dim gr As Graphics = Me.pic.CreateGraphics

dim iWidth, iHeight as integer

iWidth = miRight - miLeft

iHeight = miBottom - miTop

'MY PROBLEM IS RIGHT HERE, BECAUSE I HAVE TO REMOVE A PREVIOUS SURROUNDING
RECTANGLE (IF THERE IS ONE) BEFORE MAKING THE NEXT LARGER OR SMALLER ONE

'OTHERWISE THE RECTANGLES JUST KEEP MULTIPLYING, AND I DON'T KNOW HOW TO
REMOVE A PREVIOUS BOUNDING RECTANGLE AND RETURN THE IMAGE TO ITS

'FORMER STATE, I CAN'T JUST MAKE A RECTANGLE WITH A BACKGROUND COLOR, I NEED
TO LEAVE THE IMAGE CLEAN AS IT IS

gr.DrawRectangle(Pens.Gray, Me.miLeft, Me.miTop, iWidth, iHeight) 'this
draws the rectangle

End Sub

in the mouse up event i need to do 2 things, extract the surrounded area,
and place it on the clipboard

i don't know how to do the extraction. i can extract to a invisible
PictueBox picHidden which i would size to extracted rectangle's size and set
its SizeMode to Normal, but i don't know the code to do the extraction.

i then can place the rectangle on the clipboad with

Clipboard.SetDataObject(Me.picHIdden.Image)

in summary i don't know the code to do 2 things. 1) remove a rectangle
drawn on graphic and return the graphic to its former state without
reloading the image, 2) how to extract a rectangle from a PictureBox.Image

thanks for any code and help, or if there is better way to do what i need to
do

ray


Jan 31 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Stan | last post by:
In the old days of VB6, an Excel chart image could be pasted into a picture box with Clipboard using the following commands. xlApp.ActiveChart.ChartArea.Copy Picture1.Picture =...
5
by: TC | last post by:
Hello, Here is what I'm trying to do: -- Make sure both MS Excel and MS Word are running -- Create an Excel chart -- Save the Excel file -- Copy the Excel chart onto the clipboard using Ctrl...
2
by: Bob Henry | last post by:
Hello, This ought to be easy, but I can't figure it out. In VisualBasic.Net 2003, I've drawn graphics using drawline etc... to a picturebox. I now want to copy this to the clipboard. I think...
1
by: B. Cline | last post by:
Hi, I need to write a conversion routine to split pictures out of about 10000 word documents. (Actually the text is converted to RTF, the pictures should be converted to jpg). I thought I...
1
by: ray well | last post by:
i need to extract a rectangular area from a graphic image displayed in a PictureBox, to another PictureBox. how can i do that? i would appreciate a piece of code if possible. thanks, ray
0
by: mhospodarsky | last post by:
Hi-- I am using VB.Net 2002 for this app. I am working with Tiff and jpeg images. I have a picturebox set up that I use to view the images. I have the picture box inside of a scrollable...
8
by: Brian Ward | last post by:
I am looking for a simple way to set the image transparency in a PictureBox. I have a moving PictureBox containing a graphic image .. moving by incrementing its Left property. The background...
3
by: Joca | last post by:
I've made a private sub that creates a graphic (using drawrectangle, string, line and stuff like that) inside a picturebox, so i wouldnt place it right on top of the form itself and also beeing able...
7
by: winzone | last post by:
I used system.drawing.graphic in C# to draw the Rectangle and Ellipse in PictureBox. In my PC and other my buddy PC show the drawing graphic and color. But my customer PC doesn't show the drawing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.