1
00:00:00,590 --> 00:00:05,689
High in the previous video, I showed you how to capture a full screen screenshot.

2
00:00:05,960 --> 00:00:12,050
In this video, you'll see how to capture part of the screen via Python.

3
00:00:12,890 --> 00:00:14,900
So this is the codes of the previous video.

4
00:00:15,200 --> 00:00:20,120
For this video, I'm going to create a new file name.

5
00:00:20,120 --> 00:00:21,920
It's partial that p y.

6
00:00:23,860 --> 00:00:27,250
And you need to import from emesis import.

7
00:00:28,320 --> 00:00:30,450
Emesis and tools.

8
00:00:33,430 --> 00:00:38,830
And we use a with context manager, we say with Emma says that Mrs.

9
00:00:40,330 --> 00:00:41,050
We call it.

10
00:00:41,830 --> 00:00:47,530
And so we assign the variable screen to that output.

11
00:00:49,810 --> 00:00:58,470
Then we want to specify the parts of the screen force as a variable, and this should be a dictionary.

12
00:00:59,130 --> 00:01:06,690
So this dictionary has keys and values, so pairs of keys and values.

13
00:01:07,080 --> 00:01:16,200
For example, if you say two fifty seven here, what that means is you're going to store the screenshot

14
00:01:16,200 --> 00:01:21,810
section 257 pixels from the top of the screen.

15
00:01:22,440 --> 00:01:29,760
So somewhere starting from this line and down and then you want to also specify.

16
00:01:33,990 --> 00:01:44,250
Left another key and value, let's say, 900, so that means 900 pixels from the left of the screen.

17
00:01:44,520 --> 00:01:49,230
So we have one line here and one line here.

18
00:01:49,830 --> 00:01:54,180
That means this part of the screen here will be captured.

19
00:01:55,710 --> 00:02:02,610
But then we can also specify a width as a string, of course, width.

20
00:02:03,900 --> 00:02:09,449
So how many pixels do you want to go from this border up to here?

21
00:02:09,780 --> 00:02:20,130
Let's say we want to go about 500 pixels, so that would be 500 as the width and the height would be

22
00:02:20,460 --> 00:02:22,320
perhaps 400.

23
00:02:22,680 --> 00:02:28,920
So the height of the from this, from this line, four hundred pixels down.

24
00:02:30,060 --> 00:02:36,420
So more or less, we're capturing perhaps this area in here.

25
00:02:37,620 --> 00:02:44,340
So once we have that dictionary, then we can use the screen dots grab.

26
00:02:45,270 --> 00:02:53,970
Methods, so previously we used the screen, but shot methods for part of the screen we use, grab and

27
00:02:53,970 --> 00:02:57,900
grab now gets these part as arguments.

28
00:02:58,830 --> 00:03:10,660
And this methods will return that image and then we see tools that's p to P and G.

29
00:03:11,190 --> 00:03:12,150
So that's a methods.

30
00:03:12,180 --> 00:03:22,470
And then you want to specify the image, which we get from GRAP, but we want the argy bargy property,

31
00:03:22,500 --> 00:03:25,920
which will give us the image in bytes in colour.

32
00:03:26,340 --> 00:03:30,450
So that will give us the actual image file in bytes.

33
00:03:31,510 --> 00:03:37,210
You also want to specify image size, which you can get from image that size.

34
00:03:38,320 --> 00:03:41,380
So that's the size argument, that's the actual image.

35
00:03:42,250 --> 00:03:44,300
So what size do you want to produce it?

36
00:03:44,320 --> 00:03:48,100
And finally, the outputs is equal to the path.

37
00:03:48,100 --> 00:03:55,360
What he wants to save that image, such as output, that's p and G, and we are ready to run this school.

38
00:03:55,360 --> 00:03:55,810
So.

39
00:03:57,140 --> 00:04:02,610
Right click wrong partial and serious output at PG.

40
00:04:03,650 --> 00:04:06,410
That's the screen shot area.

41
00:04:07,890 --> 00:04:17,100
So depending on your screen, how big your screen is, you could capture different areas of the screen.

42
00:04:19,649 --> 00:04:23,070
So for me, it captured the area somewhere in here.

43
00:04:23,310 --> 00:04:27,840
I can try again by putting this text here and running again.

44
00:04:29,280 --> 00:04:30,900
And see Ultimates this time.

45
00:04:31,200 --> 00:04:40,470
So you see, it's to the left or the right key here, so it's somewhere in here of the area.

46
00:04:41,560 --> 00:04:48,730
My screen resolution currently is 1920 horizontally and.

47
00:04:50,060 --> 00:04:52,180
Ten eighty vertically.

48
00:04:52,820 --> 00:04:58,580
So one, nine, nine hundred is somewhere in the middle, yeah, somewhere in here.

49
00:04:58,880 --> 00:05:05,570
900 pixels from the left and 250 from the upper corner.

50
00:05:05,570 --> 00:05:06,830
So we get this area.

51
00:05:09,310 --> 00:05:16,960
Now, if you want to know how to get the position of the cursor, so if you want to capture this area

52
00:05:16,960 --> 00:05:25,090
and you want to know what pixel that points is, then you can use PI all to gooey a third party library,

53
00:05:25,330 --> 00:05:27,880
which I'll use in the next videos.

54
00:05:28,450 --> 00:05:35,890
It allows you to control the cursor the moors so you can know what position of the cursor is currently

55
00:05:35,890 --> 00:05:36,540
python with.

56
00:05:36,550 --> 00:05:37,160
Tell you that.

57
00:05:37,360 --> 00:05:43,690
And then you can instruct Python to move the cursor on the screen where you want it to be and to do

58
00:05:43,690 --> 00:05:45,550
clicks and drags.

59
00:05:46,570 --> 00:05:54,130
You can draw on canvas if you have a sketch application where you can draw things around and you can

60
00:05:54,130 --> 00:05:56,620
click file, scanned, copy, text and paste it.

61
00:05:56,920 --> 00:06:01,240
So you can do all of that via Python, and I'll teach you how to do that in the next videos.

62
00:06:01,450 --> 00:06:02,500
So I'll see you there.

