找回密码
 立即注册

QQ登录

只需一步,快速开始

AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2015-12-25 11:35:00
11#
回复 10楼gaobowen的帖子

您好, 给您的帮助文档中的示例代码是用户手动截取屏幕的区域进行截屏。
但实际上也可以通过全自动的方式进行。您说得对,关键就在scEngine.CaptureArea(scAreaOptions, scInformation)这一句。
主要是第一个参数:scAreaOptions。
这个参数设置了需要截取的区域信息,示例中scAreaOptions = ScreenCaptureEngine.DefaultCaptureAreaOptions;使用的是默认的设置,请注意看下面的绿色注释掉的内容:
// NOTE: To fill the structure manually, you can write:
   // Cursor drawCursor = Cursors.Cross;
   // scAreaOptions.AreaType = ScreenCaptureAreaType.Rectangle;
   // scAreaOptions.DrawCursor = drawCursor;
   // scAreaOptions.DrawLineColor = Color.Red;
   // scAreaOptions.DrawLineStyle = ScreenCaptureAreaLineStyle.Solid;
   // scAreaOptions.EllipseHeight = 0;
   // scAreaOptions.EllipseWidth = 0;
   // scAreaOptions.FillBackgroundColor = Color.Black;
   // scAreaOptions.FillForegroundColor = Color.White;
   // scAreaOptions.FillPattern = ScreenCaptureAreaFillPattern.Solid;
   // scAreaOptions.Flags = ScreenCaptureAreaFlags.ShowInfoWindow;
   // scAreaOptions.InfoWindowBounds = new Rectangle(ScreenCaptureAreaOptions.LeftInfoWindowPosition, ScreenCaptureAreaOptions.TopInfoWindowPosition, ScreenCaptureAreaOptions.MediumInfoWindowSize, ScreenCaptureAreaOptions.MediumInfoWindowSize);
   // scAreaOptions.TextBackgroundColor = Color.White;
   // scAreaOptions.TextForegroundColor = Color.Black;
   // scAreaOptions.Zoom = ScreenCaptureAreaZoom.Normal;
这一段就是当您想使用自定义区域时需要设置的属性。
其中最关键的位置区域设定是这一句:scAreaOptions.InfoWindowBounds
您可以通过设置来指定具体的需要截取的窗口大小。
之后将这个scAreaOptions传递给scEngine.CaptureArea方法即可。中间不需要显示任何窗口,就可以实现直接截图。
以上,谢谢。
回复 使用道具 举报
gaobowen
中级会员   /  发表于:2015-12-28 09:03:00
12#
您好,感谢您详细的回答。
我按照您的说法,把以上注释掉的代码都放开,并且给InfoWindowBounds这个方法赋了值。(1,全部放开。2,只放开此方法。这2种都试了)
但是程序走到scEngine.CaptureArea(scAreaOptions, scInformation这一句后,没有走后面的代码,而是直接跳出了。查了半天,不知道是什么原因?
麻烦您了!代码如下:
Dim scAreaOptions As ScreenCaptureAreaOptions

Dim drawCursor As Cursor
drawCursor = Cursors.Cross
scAreaOptions.AreaType = ScreenCaptureAreaType.Rectangle
scAreaOptions.DrawCursor = drawCursor
scAreaOptions.DrawLineColor = Color.Red
scAreaOptions.DrawLineStyle = ScreenCaptureAreaLineStyle.Dash
scAreaOptions.EllipseHeight = 100
scAreaOptions.EllipseWidth = 100
scAreaOptions.FillBackgroundColor = Color.Black
scAreaOptions.FillForegroundColor = Color.White
scAreaOptions.FillPattern = ScreenCaptureAreaFillPattern.Solid
scAreaOptions.Flags = ScreenCaptureAreaFlags.ShowInfoWindow
scAreaOptions.InfoWindowBounds = New Rectangle(10, 10, 10, 10)
scAreaOptions.TextBackgroundColor = Color.White
scAreaOptions.TextForegroundColor = Color.Black
scAreaOptions.Zoom = ScreenCaptureAreaZoom.Normal

Dim scInformation As ScreenCaptureInformation = Nothing
Dim image As RasterImage
image = scEngine.CaptureArea(scAreaOptions, scInformation)  ‘走到这一句,程序直接跳出了,没有执行后面的代码

RasterImageViewer2.Image = image
回复 使用道具 举报
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2015-12-28 10:20:00
13#
回复 12楼gaobowen的帖子

您好,
您能否将您的示例程序发上来,我帮您看看。
回复 使用道具 举报
gaobowen
中级会员   /  发表于:2015-12-28 10:49:00
14#
下面就是我示例程序。麻烦您了。
Imports Leadtools
Imports Leadtools.Codecs
Imports System.IO
Imports Leadtools.WinForms
Imports Leadtools.ImageProcessing
Imports Leadtools.ScreenCapture

Public Class Form1
    Private codecs As RasterCodecs
    Public G_RASTER_CODECS As RasterCodecs
    Private engine As ScreenCaptureEngine
    WithEvents scEngine As ScreenCaptureEngine

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        On Error GoTo Err_jp

        Dim dlg As New OpenFileDialog
        dlg.Filter = "file|*.*"
        If (dlg.ShowDialog(Me) = DialogResult.OK) Then
            RasterImageViewer1.Image = codecs.Load(dlg.FileName)

            'Capture
            ScreenCaptureEngine.Startup()
            scEngine = New ScreenCaptureEngine()

            Dim scAreaOptions As ScreenCaptureAreaOptions
            Dim drawCursor As Cursor
            drawCursor = Cursors.Cross
            scAreaOptions.AreaType = ScreenCaptureAreaType.Rectangle
            scAreaOptions.DrawCursor = drawCursor
            scAreaOptions.DrawLineColor = Color.Red
            scAreaOptions.DrawLineStyle = ScreenCaptureAreaLineStyle.Dash
            scAreaOptions.EllipseHeight = 100
            scAreaOptions.EllipseWidth = 100
            scAreaOptions.FillBackgroundColor = Color.Black
            scAreaOptions.FillForegroundColor = Color.Black
            scAreaOptions.FillPattern = ScreenCaptureAreaFillPattern.Solid
            scAreaOptions.Flags = ScreenCaptureAreaFlags.ShowInfoWindow
            scAreaOptions.InfoWindowBounds = New Rectangle(10, 10, 10, 10)
            scAreaOptions.TextBackgroundColor = Color.Black
            scAreaOptions.TextForegroundColor = Color.Black
            scAreaOptions.Zoom = ScreenCaptureAreaZoom.Normal

            Dim scInformation As ScreenCaptureInformation = Nothing

            Dim image As RasterImage
            image = scEngine.CaptureArea(scAreaOptions, scInformation)

            RasterImageViewer2.Image = image

            If (scEngine.IsCaptureActive) Then
                scEngine.StopCapture()
            End If

            image.Dispose()
            ScreenCaptureEngine.Shutdown()

        End If

        Exit Sub

Err_jp:
      
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        codecs = New RasterCodecs
    End Sub

End Class
回复 使用道具 举报
sxyweiren
中级会员   /  发表于:2015-12-28 15:01:00
15#
回复 14楼gaobowen的帖子

Capture用API截屏会稍微简单些。。
其实就是一个从屏幕截取图片的功能。
回复 使用道具 举报
gaobowen
中级会员   /  发表于:2016-1-5 11:11:00
16#
回复 13楼AvoCaDolol的帖子

您好,有关CaptureArea自动截屏的问题,您那边有什么结果吗?谢谢!
我已把我这边改过的代码上传。
以上,谢谢!
回复 使用道具 举报
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2016-1-5 16:14:00
17#
回复 16楼gaobowen的帖子

您好,您的问题已经发送给厂商,目前没有收到回复。非常抱歉。
请您耐心等待,我这边收到回复会第一时间给您回帖。
谢谢。
回复 使用道具 举报
gaobowen
中级会员   /  发表于:2016-1-5 16:24:00
18#
回复 17楼AvoCaDolol的帖子

您好,非常感谢。麻烦您了!
回复 使用道具 举报
AvoCaDolol活字格认证 Wyn认证
社区贡献组   /  发表于:2016-1-8 10:47:00
19#
回复 18楼gaobowen的帖子

您好, 厂商今早回复,原文如下:
If the customer wants to be able to implement this without any user interaction (as it seems from your prior email), I believe the only way to accomplish this would be to capture the entire screen using the ScreenCaptureEngine.CaptureFullScreen() method and then cropping or copying the specific area. The CaptureArea() method would seem to fit this, but calling this method automatically invokes a process by which the SDK awaits the user clicking with the mouse to define the area. There's no way to specify the specific area to capture. Because the CaptureArea() feature allows the user to capture many different types of shapes, there's no good way to pass the specific points to complete the capture. It's also possible this limitation is in place to assure a proper shape is used so the capture can be completed.

If the customer is okay with this method of capturing, there is a robust example in the documentation that shows the different structures used. It also shows how these can be manually filled in and the dialogs removed. They can replace the CaptureArea() method with CaptureFullScreen() followed by using the CropCommand class or CopyRectangleCommand class to get the specific area desired. The documentation example can be found here:
https://www.leadtools.com/help/l ... ncaptureengine.html
==============================================================================================================
大意是说,目前没有一个方法能够让您指定一个特定的区域进行自动的截屏,因为CaptureArea这个方法是让用户画一个区域进行截取,必须等待用户点击热键或者鼠标按键,所以无法做到。
Support提供了一个思路,就是截取整个屏幕,然后通过CropCommand或者CopyRectangleCommand这两个命令来截取您想要的区域。

我这边做过测试是可以实现的,我做了一个小例子,固定截取屏幕的左下角。
效果如下图:

核心代码在button2 Click事件中:
        Dim scAreaOptions As ScreenCaptureAreaOptions
        scAreaOptions = ScreenCaptureEngine.DefaultCaptureAreaOptions

        Dim scOptions As ScreenCaptureOptions
        scOptions = New ScreenCaptureOptions
        ‘ 将截图热键设置为空,就会直接触发截图结束
        scOptions.Hotkey = Keys.None

        Dim scInformation As ScreenCaptureInformation = Nothing

        scEngine.CaptureOptions = scOptions
        Dim image As RasterImage
        ' 截图方式为全屏
        image = scEngine.CaptureFullScreen(scInformation)

        scEngine.StopCapture()

        'image.Dispose()
        ScreenCaptureEngine.Shutdown()
最后挂载scEngine.CaptureInformation截图结束事件,在这个事件中取到截图图像,并对其做裁剪处理:
    Public Sub scEngine_CaptureInformation(ByVal sender As Object, ByVal e As ScreenCaptureInformationEventArgs) Handles scEngine.CaptureInformation
        ' 拿到截图结果
        RasterImageViewer2.Image = e.Image
        Dim cmd As CopyRectangleCommand = New CopyRectangleCommand()
        cmd.CreateFlags = RasterMemoryFlags.Conventional
        ' 创建一个区域,屏幕左下角到整个图片的10分之一处
        cmd.Rectangle = New LeadRect(0, _
                                     0, _
                                     RasterImageViewer2.Image.Width / 10, _
                                     RasterImageViewer2.Image.Height / 10)
        cmd.Run(RasterImageViewer2.Image)
        ' 将裁剪结果显示在左边
        RasterImageViewer1.Image = cmd.DestinationImage
        ' everything worked fine
        e.Cancel = False
    End Sub

我将我的源程序附在这里,您可以下载解压查看。

以上,谢谢。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
gaobowen
中级会员   /  发表于:2016-1-11 10:06:00
20#
回复 19楼AvoCaDolol的帖子

您好,非常感谢您详细的回答。
您给的思路我大概了解了。并且按照您给的例子,自己也试了试。目前还有1个疑问想再麻烦您给看看:
在下面这个方法中,为什么是从左下角开始呢?可以从左上角开始算坐标吗?
cmd.Rectangle = New LeadRect(0, _
                                     0, _
                                     RasterImageViewer2.Image.Width / 10, _
                                     RasterImageViewer2.Image.Height / 10)
以上,谢谢!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部