Resolved How to use .PaintPicture in VB.NET?

love_lyn99

Member
Joined
Sep 2, 2022
Messages
16
Programming Experience
Beginner
Im working on my assignment, camera, and i dont know how to use the .PaintPicture or something. im stuck.
what i like is to get the image inside the rectangleshape1 (fix size) of VideoSourcePlayer1 and paste the image to picturebox2. (i hope you get it, im bad at explaining things)
please see attached sample for your reference.

Thank you!
 

Attachments

  • Untitled1.png
    Untitled1.png
    188.5 KB · Views: 1

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,779
Location
Sydney, Australia
Programming Experience
10+
i dont know how to use the .PaintPicture or something.
What is "the .PaintPicture"? You seem to be referring to something specific without explaining what it is.
im bad at explaining things
Try harder. Saying you're bad at explaining doesn't get you off the hook. It's not for us to do the work to interpret your bad explanation. Try using more words, instead of as few as possible. Explain, step-by-step, exactly what you're trying to accomplish, exactly how you're trying to accomplish it and exactly what happens when you try. Assume that too many words is better than not enough.
 

love_lyn99

Member
Joined
Sep 2, 2022
Messages
16
Programming Experience
Beginner
What is "the .PaintPicture"? You seem to be referring to something specific without explaining what it is.

Try harder. Saying you're bad at explaining doesn't get you off the hook. It's not for us to do the work to interpret your bad explanation. Try using more words, instead of as few as possible. Explain, step-by-step, exactly what you're trying to accomplish, exactly how you're trying to accomplish it and exactly what happens when you try. Assume that too many words is better than not enough.
about the .PaintPicture. its a code from vb6. (im recreating this work from vb6.
skip to 5:39 ) i think its for bitmap image, and they said it doesnt exist in vb.net, so i've looked for alternatives : DrawImage(), but i dont know how to use it or implement it in my work. Im lacking to understand majority of codes/functions because i just started programming last month.

What i want is:

Im using Aforge.Video.DirectShow as Videosource

VideoSourcePlayer1.VideoSource

if VideoSourcePlayer1_MouseDown a RectagleShape1 will show and follow the mouse pointer when dragged (which is done, i think), and if VideoSourcePlayer1_MouseUp, the system will capture the image inside the rectangle and display it in PictureBox2. (im stuck in this part.)

Im willing to share my current work if requested. thank you!
 

Attachments

  • Untitled1.png
    Untitled1.png
    188.5 KB · Views: 1

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,617
Location
Norway
Programming Experience
10+
Things you could look into is Control.DrawToBitmap and Graphics.CopyFromScreen.
If the control you are using supports it DrawToBitmap should return the whole image it currently displays, then you can copy part of it according to selection.
CopyFromScreen will allow you to copy any part of the screen as it is currently displayed.
 

love_lyn99

Member
Joined
Sep 2, 2022
Messages
16
Programming Experience
Beginner
Things you could look into is Control.DrawToBitmap and Graphics.CopyFromScreen.
If the control you are using supports it DrawToBitmap should return the whole image it currently displays, then you can copy part of it according to selection.
CopyFromScreen will allow you to copy any part of the screen as it is currently displayed.
Hi! i've researched and tried to use the .DrawToBitmap, and i think this is what ive been looking for, omg. but i have a problem. it wont display the capture image in PictureBox2.
here's the code i use:
------
Dim img As Bitmap = New Bitmap(RectangleShape1.Width, RectangleShape1.Height)
PictureBox2.DrawToBitmap(img, New Rectangle(0, 0, RectangleShape1.Width, RectangleShape1.Height))
------
my problem is i dont know the equivalent code for : PictureBox2.Picture = PictureBox2.Image : from vb6.

ive tried: PictureBox2.Image = img : but it's not working.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,779
Location
Sydney, Australia
Programming Experience
10+
Why would you be drawing PictureBox2 to an Image and then displaying that Image in the same PictureBox2? Surely you should be drawing from one place and displaying somewhere else.

Also, never just say that something doesn't work. That could mean anything. Explain EXACTLY what happens and EXACTLY how that differs from your expectations.
 

love_lyn99

Member
Joined
Sep 2, 2022
Messages
16
Programming Experience
Beginner
Why would you be drawing PictureBox2 to an Image and then displaying that Image in the same PictureBox2? Surely you should be drawing from one place and displaying somewhere else.

Also, never just say that something doesn't work. That could mean anything. Explain EXACTLY what happens and EXACTLY how that differs from your expectations.
hi. sorry. its VideoSourcePlayer1.DrawToBitmap(img, New Rectangle(0, 0, RectangleShape1.Width, RectangleShape1.Height)).

ok, first, i have to know how do i capture image within the RectangleShape1, and thanks to mr JohN for the idea he gave.
in my understanding. this code: "Annex A" will only get the Width and Height of the RectangleShape1, and not include the location of the RectangleShape1. (i knew it because when i try to use this code: img.save("c:\sample.png") : to just view the result, the captured/saved image was top right corner of the VideoSourcePlayer1). and i think maybe its because of (0,0, ,) in (img, New Rectangle(0, 0, RectangleShape1.Width, RectangleShape1.Height)). idk, so i tried replacing it with different value and tried using the : RectangleShape1.left, RectangleShape1.top : code but i cant get it right. sometimes the result was black or off the source. what should i do?

Annex A ------
Dim img As Bitmap = New Bitmap(RectangleShape1.Width, RectangleShape1.Height)
VideoSourcePlayer1.DrawToBitmap(img, New Rectangle(0, 0, RectangleShape1.Width, RectangleShape1.Height))
-----

second is, how do i post or display the the captured image in PictureBox2? should i use the save and load method? like save the image first, then load it in the PictureBox2? but i'd like to avoid it if possible, because i want to add file name of my choice after the captured image is displayed in PictureBox2.

ive tried : PictureBox2.Image = img : but got no result.
 
Top Bottom