精华内容
下载资源
问答
  • Java实现屏幕抓屏

    2020-08-10 19:39:56
    绍Java实现屏幕抓屏
  • 屏幕抓屏

    千次阅读 2005-12-31 15:26:00
    如何通过鼠标,选取一部分屏幕图像,在把它保存下来???_________________________________________________可以这样,用一个无边框窗体铺满整个屏幕并置顶,用bitblt函数把桌面抓成图片显示在这个窗体上这样看...

    如何通过鼠标,选取一部分屏幕图像,在把它保存下来???
    _________________________________________________

    可以这样,
    用一个无边框窗体铺满整个屏幕并置顶,用bitblt函数把桌面抓成图片显示在这个窗体上
    这样看起来就是把屏幕静止了
    你用鼠标在这个窗体上画框取mousedown时的xy值与mouseup时的XY值
    用窗体的paintpicture方法画到另一个不可见picturebox里再用savepicture方法保存就可以了
    保存后记得把窗体卸掉

    ‘====================
    注意,先抓图再全屏置顶

    http://www.zg77hk.com/bbs/viewthread.php?tid=8773&fpage=1&highlight=%2Bzyg01234
    我写的用控件实现的
    _____________________________________________________________________

    我用类似影子的方法也实现了,不过没有用哪个柯达控件,而是用shape和label组合实现。
    Option Explicit

    Private Const MOUSEEVENTF_LEFTDOWN As Long = &H2
    Private Declare Function PtInRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long
    Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Long) As Long
    Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
    Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function EmptyClipboard Lib "user32" () As Long
    Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
    Private Declare Function CloseClipboard Lib "user32" () As Long
    Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
    Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long


    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
     End Type

    Private Type POINTAPI
            x As Long
            y As Long
    End Type


    Dim OriginalX As Single   '区域起点X坐标
    Dim OriginalY As Single   '区域起点的Y坐标
    Dim NewX As Single
    Dim NewY As Single
    Dim Status As String      '当前状态(正在选择区域或者拖动区域)
    Dim rc As RECT            '区域的范围
    Dim ptInPic As Boolean     '鼠标是否位于pic上


    Private Sub Form_Load()
        Dim SourceDC As Long
        AutoRedraw = True
        Me.WindowState = 2
        Screen.MousePointer = vbCrosshair      ' 将光标改为十字型
        SourceDC = CreateDC("DISPLAY", 0, 0, 0)
        BitBlt Me.hdc, 0, 0, Screen.Width / 15, Screen.Height / 15, SourceDC, 0, 0, &HCC0020  '拷贝当前桌面到窗体
        Status = "draw"   '绘图状态
        SetTitle 1        '设置提示的内容
    End Sub


    Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyEscape Then Unload Me
    End Sub


    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
        If Status = "draw" Then          '如果是抓取状态
            Shape1.Visible = True
            Shape1.Width = 0
            Shape1.Height = 0
            OriginalX = x
            OriginalY = y          '起点坐标
            Shape1.Left = OriginalX
            Shape1.Top = OriginalY
            Call SetTitle(1)
        Else                           '移动状态
            rc.Left = Shape1.Left
            rc.Right = Shape1.Left + Shape1.Width
            rc.Top = Shape1.Top
            rc.Bottom = Shape1.Top + Shape1.Height
            If PtInRect(rc, x, y) Then     '如果按下的点位于区域内
                NewX = x
                NewY = y                   '则移动区域
            Else                           '否则重新画一个区域
                Shape1.Width = 0
                Shape1.Height = 0
                OriginalX = x
                OriginalY = y
                Shape1.Left = OriginalX
                Shape1.Top = OriginalY
                Status = "draw"            '状态恢复到抓取
                Call SetTitle(2)
            End If
        End If
    End Sub


    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
        Dim Info As String
        If Button = 1 Then
            Shape1.Visible = False
            LblPos.Visible = False
            If Status = "draw" Then            '如果是绘图状态
                If x > OriginalX And y > OriginalY Then           '根据鼠标位置调整shape1的大小和位置
                    Shape1.Move OriginalX, OriginalY, x - OriginalX, y - OriginalY
                ElseIf x < OriginalX And y > OriginalY Then
                   Shape1.Move x, OriginalY, OriginalX - x, y - OriginalY
                ElseIf x > OriginalX And y < OriginalY Then
                    Shape1.Move OriginalX, y, x - OriginalX, OriginalY - y
                ElseIf x < OriginalX And y < OriginalY Then
                    Shape1.Move x, y, OriginalX - x, OriginalY - y
                End If
                Info = Shape1.Width & "x" & Shape1.Height             '显示当前区域的大小
                LblPos.Move Shape1.Left + Shape1.Width / 2 - TextWidth(Info) / 2, Shape1.Top + Shape1.Height / 2 - TextHeight(Info) / 2
                LblPos.Caption = Info
                Screen.MousePointer = vbCrosshair
            Else                            '如果是移动状态
                Screen.MousePointer = 5
                Shape1.Left = OriginalX - (NewX - x)
                Shape1.Top = OriginalY - (NewY - y)
                If Shape1.Left < 0 Then Shape1.Left = 0   '使区域不超过屏幕
                If Shape1.Top < 0 Then Shape1.Top = 0
                If Shape1.Left + Shape1.Width > Screen.Width / 15 Then Shape1.Left = Screen.Width / 15 - Shape1.Width
                If Shape1.Top + Shape1.Height > Screen.Height / 15 Then Shape1.Top = Screen.Height / 15 - Shape1.Height
                LblPos.Move Shape1.Left + Shape1.Width / 2 - TextWidth(LblPos.Caption) / 2, Shape1.Top + Shape1.Height / 2 - TextHeight(LblPos.Caption) / 2
            End If
            Shape1.Visible = True
            LblPos.Visible = True
        End If
    End Sub

    Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
        If Button = 1 Then
         Call SetTitle(3)
            If Status = "draw" Then
                Status = "move"
            End If
            OriginalX = Shape1.Left   '更新OriginalX,因为选择区域时可能会出现shape的right点大于left点
            OriginalY = Shape1.Top
        Else
            Unload Me          '右键退出
        End If
    End Sub

    Private Sub Form_DblClick()            '双击拷贝区域图象到剪贴板
      If PtInRect(rc, NewX, NewY) Then     '看是否在区域内
          Picture1.Visible = False
          DoEvents
          ScrnCap Shape1.Left, Shape1.Top, Shape1.Left + Shape1.Width, Shape1.Top + Shape1.Height
          Unload Me
      End If
    End Sub


    Private Sub LblPos_Click()
        SetCursorPos Shape1.Left + 1, Shape1.Top + 1
        mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0   '模拟左键按下
        Call Form_DblClick
    End Sub

    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
     If ptInPic = 1 Or Picture1.Left = Me.ScaleLeft Then         '改变提示框的位置
            With Picture1
                .Move Me.ScaleWidth - .Width, .Top, .Width, .Height
            End With
            ptInPic = 2
        Else
            ptInPic = 1
            With Picture1
                .Move Me.ScaleLeft, .Top, .Width, .Height
            End With
        End If
    End Sub


    ' 释放内存空间
    Private Sub Form_Unload(Cancel As Integer)
        Set frmSnap = Nothing
    End Sub


    Public Sub SetTitle(index As Integer)
        Select Case index
          Case 1
            lblInfo(0).Caption = "*    按住鼠标左键不放选择" & vbCrLf & "      截图的范围."
            lblInfo(1).Caption = "*    按ESC键退出."
            lblInfo(2).Caption = ""
          Case 2
            lblInfo(0).Caption = "*    松开鼠标左键确定截图" & vbCrLf & "      的范围."
            lblInfo(1).Caption = "*    按ESC键退出."
            lblInfo(2).Caption = ""
          Case 3
            lblInfo(0).Caption = "*    用鼠标左键调整截图的" & vbCrLf & "      位置."
            lblInfo(1).Caption = "*    双击选取区域保存图片."
            lblInfo(2).Caption = "*    按ESC键退出."
        End Select
    End Sub

    ' 拷贝选定方框区域的屏幕图像到剪贴板
    Public Sub ScrnCap(Left As Long, Top As Long, Right As Long, Bottom As Long)
        Shape1.Visible = False               '不需要拷贝shape
        LblPos.Visible = False
        DoEvents
        Dim rWidth As Long
        Dim rHeight As Long
        Dim SourceDC As Long
        Dim DestDC As Long
        Dim BHandle As Long
        Dim Wnd As Long
        Dim DHandle As Long
        rWidth = Right - Left
        rHeight = Bottom - Top
        SourceDC = CreateDC("DISPLAY", 0, 0, 0)
        DestDC = CreateCompatibleDC(SourceDC)
        BHandle = CreateCompatibleBitmap(SourceDC, rWidth, rHeight)
        SelectObject DestDC, BHandle
        BitBlt DestDC, 0, 0, rWidth, rHeight, SourceDC, Left, Top, &HCC0020
        Wnd = GetDesktopWindow
        OpenClipboard Wnd
        EmptyClipboard
        SetClipboardData 2, BHandle
        CloseClipboard
        DeleteDC DestDC
        ReleaseDC DHandle, SourceDC
    End Sub

    http://221.8.30.109/vb/zt.rar
    请再次下载

    展开全文
  • VB屏幕抓屏源码.rar

    2019-07-10 11:14:27
    VB屏幕抓屏源码,俗称“屏幕间谍”,程序可以自动捕捉整个屏幕 保存图片在C盘,也可以仅捕捉当前窗口图像 保存图片在C盘。
  • 实现java屏幕抓屏的方法Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最大的.开发者专业社群。以下是小编为大家...

    实现java屏幕抓屏的方法

    Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最大的.开发者专业社群。以下是小编为大家搜索整理的实现java屏幕抓屏的方法,欢迎大家阅读!更多精彩内容请及时关注我们应届毕业生考试网!

    import java.awt.Dimension;

    import java.awt.Rectangle;

    import java.awt.Robot;

    import java.awt.Toolkit;

    import java.awt.image.BufferedImage;

    import java.io.File;

    import javax.imageio.ImageIO;

    public class GuiCamera

    {

    private String fileName; //文件的前缀

    private String defaultName = "GuiCamera";

    static int serialNum=0;

    private String imageFormat; //图像文件的格式

    private String defaultImageFormat="png";

    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

    public GuiCamera() {

    fileName = defaultName;

    imageFormat=defaultImageFormat;

    }

    public GuiCamera(String s,String format) {

    fileName = s;

    imageFormat=format;

    }

    【实现java屏幕抓屏的方法】相关文章:

    展开全文
  • 一个屏幕抓屏的例子

    2009-07-27 11:36:00
     {自定义抓屏函数,DrawCur表示抓鼠标图像与否}  { Private declarations }  public  { Public declarations }  end;  var  Form1: TForm1;  MyStream: TMemorystream;{内存流对象}  implementation...

     给你一个例子:  
       
      服务端程序  
       
      unit   Unit1;  
      interface  
      uses  
      Windows,   Messages,   SysUtils,   Classes,   Graphics,   Controls,   Forms,   Dialogs,   JPEG,ExtCtrls,   ScktComp;  
      type  
      TForm1   =   class(TForm)  
      ServerSocket1:   TServerSocket;  
      procedure   ServerSocket1ClientRead(Sender:   TObject;Socket:   TCustomWinSocket);  
      procedure   FormCreate(Sender:   TObject);  
      procedure   FormClose(Sender:   TObject;   var   Action:   TCloseAction);  
      private  
      procedure   Cjt_GetScreen(var   Mybmp:   TBitmap;   DrawCur:   Boolean);  
      {自定义抓屏函数,DrawCur表示抓鼠标图像与否}  
      {   Private   declarations   }  
      public  
      {   Public   declarations   }  
      end;  
      var  
      Form1:   TForm1;  
      MyStream:   TMemorystream;{内存流对象}    
      implementation  
      {$R   *.DFM}  
      procedure   TForm1.Cjt_GetScreen(var   Mybmp:   TBitmap;   DrawCur:   Boolean);  
      var  
      Cursorx,   Cursory:   integer;  
      dc:   hdc;  
      Mycan:   Tcanvas;  
      R:   TRect;  
      DrawPos:   TPoint;  
      MyCursor:   TIcon;  
      hld:   hwnd;  
      Threadld:   dword;  
      mp:   tpoint;  
      pIconInfo:   TIconInfo;  
      begin  
      Mybmp   :=   Tbitmap.Create;   {建立BMPMAP   }  
      Mycan   :=   TCanvas.Create;   {屏幕截取}  
      dc   :=   GetWindowDC(0);  
      try  
      Mycan.Handle   :=   dc;  
      R   :=   Rect(0,   0,   screen.Width,   screen.Height);  
      Mybmp.Width   :=   R.Right;  
      Mybmp.Height   :=   R.Bottom;  
      Mybmp.Canvas.CopyRect(R,   Mycan,   R);  
      finally  
      releaseDC(0,   DC);  
      end;  
      Mycan.Handle   :=   0;  
      Mycan.Free;  
      if   DrawCur   then   {画上鼠标图象}  
      begin  
      GetCursorPos(DrawPos);  
      MyCursor   :=   TIcon.Create;  
      getcursorpos(mp);  
      hld   :=   WindowFromPoint(mp);  
      Threadld   :=   GetWindowThreadProcessId(hld,   nil);  
      AttachThreadInput(GetCurrentThreadId,   Threadld,   True);  
      MyCursor.Handle   :=   Getcursor();  
      AttachThreadInput(GetCurrentThreadId,   threadld,   False);  
      GetIconInfo(Mycursor.Handle,   pIconInfo);  
      cursorx   :=   DrawPos.x   -   round(pIconInfo.xHotspot);  
      cursory   :=   DrawPos.y   -   round(pIconInfo.yHotspot);  
      Mybmp.Canvas.Draw(cursorx,   cursory,   MyCursor);   {画上鼠标}  
      DeleteObject(pIconInfo.hbmColor);{GetIconInfo   使用时创建了两个bitmap对象.   需要手工释放这两个对象}  
      DeleteObject(pIconInfo.hbmMask);{否则,调用他后,他会创建一个bitmap,多次调用会产生多个,直至资源耗尽}  
      Mycursor.ReleaseHandle;   {释放数组内存}  
      MyCursor.Free;   {释放鼠标指针}  
      end;    
      end;  
      procedure   TForm1.FormCreate(Sender:   TObject);  
      begin  
      ServerSocket1.Port   :=   3000;   {端口}  
      ServerSocket1.Open;   {Socket开始侦听}  
      end;  
      procedure   TForm1.FormClose(Sender:   TObject;   var   Action:   TCloseAction);  
      begin  
      if   ServerSocket1.Active   then   ServerSocket1.Close;   {关闭Socket}  
      end;  
      procedure   TForm1.ServerSocket1ClientRead(Sender:   TObject;  
      Socket:   TCustomWinSocket);  
      var  
      S,   S1:   string;  
      MyBmp:   TBitmap;  
      Myjpg:   TJpegimage;  
      begin  
      S   :=   Socket.ReceiveText;  
      if   S   =   'cap'   then   {客户端发出抓屏幕指令}  
      begin  
      try  
      MyStream   :=   TMemorystream.Create;{建立内存流}  
      MyBmp   :=   TBitmap.Create;  
      Myjpg   :=   TJpegimage.Create;  
      Cjt_GetScreen(MyBmp,   True);   {True表示抓鼠标图像}  
      Myjpg.Assign(MyBmp);   {将BMP图象转成JPG格式,便于在互联网上传输}  
      Myjpg.CompressionQuality   :=   10;   {JPG文件压缩百分比设置,数字越大图像越清晰,但数据也越大}  
      Myjpg.SaveToStream(MyStream);   {将JPG图象写入流中}  
      Myjpg.free;  
      MyStream.Position   :=   0;{注意:必须添加此句}  
      s1   :=   inttostr(MyStream.size);{流的大小}  
      Socket.sendtext(s1);   {发送流大小}  
      finally  
      MyBmp.free;  
      end;  
      end;  
      if   s   =   'ready'   then   {客户端已准备好接收图象}  
      begin  
      MyStream.Position   :=   0;  
      Socket.SendStream(MyStream);   {将流发送出去}  
      end;  
      end;  
      end.  

     

    上面是服务端,下面我们来写客户端程序。  
       
      新建一个工程,添加Socket控件ClientSocket、图像显示控件Image、一个   Panel   、一个Edit、两个   Button和一个状态栏控件StatusBar1。注意:把Edit1和两个   Button放在Panel1上面。ClientSocket的属性跟ServerSocket差不多,不过多了一个Address属性,表示要连接的服务端IP地址。填上IP地址后点“连接”将与服务端程序建立连接,如果成功就可以进行通讯了。点击“抓屏”将发送字符给服务端。因为程序用到了JPEG图像单元,所以要在Uses中添加Jpeg.  
      全部代码如下:  
      unit   Unit2{客户端};  
      interface  
      uses  
      Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls,ScktComp,ExtCtrls,Jpeg,   ComCtrls;  
      type  
      TForm1   =   class(TForm)  
      ClientSocket1:   TClientSocket;  
      Image1:   TImage;  
      StatusBar1:   TStatusBar;  
      Panel1:   TPanel;  
      Edit1:   TEdit;  
      Button1:   TButton;  
      Button2:   TButton;  
      procedure   Button1Click(Sender:   TObject);  
      procedure   ClientSocket1Connect(Sender:   TObject;  
      Socket:   TCustomWinSocket);  
      procedure   Button2Click(Sender:   TObject);  
      procedure   ClientSocket1Error(Sender:   TObject;   Socket:   TCustomWinSocket;  
      ErrorEvent:   TErrorEvent;   var   ErrorCode:   Integer);  
      procedure   ClientSocket1Read(Sender:   TObject;   Socket:   TCustomWinSocket);  
      procedure   FormCreate(Sender:   TObject);  
      procedure   FormClose(Sender:   TObject;   var   Action:   TCloseAction);  
      procedure   ClientSocket1Disconnect(Sender:   TObject;  
      Socket:   TCustomWinSocket);  
      private  
      {   Private   declarations   }  
      public  
      {   Public   declarations   }  
      end;  
      var  
      Form1:   TForm1;  
      MySize:   Longint;  
      MyStream:   TMemorystream;{内存流对象}  
      implementation  
      {$R   *.DFM}  
      procedure   TForm1.FormCreate(Sender:   TObject);  
      begin  
      {--------   下面为设置窗口控件的外观属性   -------------   }  
      {注意:把Button1、Button2和Edit1放在Panel1上面}  
      Edit1.Text   :=   '127.0.0.1';  
      Button1.Caption   :=   '连接主机';  
      Button2.Caption   :=   '抓屏幕';  
      Button2.Enabled   :=   false;  
      Panel1.Align   :=   alTop;  
      Image1.Align   :=   alClient;  
      Image1.Stretch   :=   True;  
      StatusBar1.Align:=alBottom;  
      StatusBar1.SimplePanel   :=   True;  
      {-----------------------------------------------   }  
      MyStream   :=   TMemorystream.Create;   {建立内存流对象}  
      MySize   :=   0;   {初始化}  
      end;  
      procedure   TForm1.Button1Click(Sender:   TObject);  
      begin  
      if   not   ClientSocket1.Active   then  
      begin  
      ClientSocket1.Address   :=   Edit1.Text;   {远程IP地址}  
      ClientSocket1.Port   :=   3000;   {Socket端口}  
      ClientSocket1.Open;   {建立连接}  
      end;  
      end;  
      procedure   TForm1.Button2Click(Sender:   TObject);  
      begin  
      Clientsocket1.Socket.SendText('cap');   {发送指令通知服务端抓取屏幕图象}  
      Button2.Enabled   :=   False;  
      end;  
      procedure   TForm1.ClientSocket1Connect(Sender:   TObject;  
      Socket:   TCustomWinSocket);  
      begin  
      StatusBar1.SimpleText   :=   '与主机'   +   ClientSocket1.Address   +   '成功建立连接!';  
      Button2.Enabled   :=   True;  
      end;  
      procedure   TForm1.ClientSocket1Error(Sender:   TObject;  
      Socket:   TCustomWinSocket;   ErrorEvent:   TErrorEvent;  
      var   ErrorCode:   Integer);  
      begin  
      Errorcode   :=   0;   {不弹出出错窗口}  
      StatusBar1.SimpleText   :=   '无法与主机'   +   ClientSocket1.Address   +   '建立连接!';  
      end;  
      procedure   TForm1.ClientSocket1Disconnect(Sender:   TObject;  
      Socket:   TCustomWinSocket);  
      begin  
      StatusBar1.SimpleText   :=   '与主机'   +   ClientSocket1.Address   +   '断开连接!';  
      Button2.Enabled   :=   False;  
      end;  
      procedure   TForm1.ClientSocket1Read(Sender:   TObject;  
      Socket:   TCustomWinSocket);  
      var  
      MyBuffer:   array[0..10000]   of   byte;   {设置接收缓冲区}  
      MyReceviceLength:   integer;  
      S:   string;  
      MyBmp:   TBitmap;  
      MyJpg:   TJpegimage;  
      begin  
      StatusBar1.SimpleText   :=   '正在接收数据......';  
      if   MySize   =   0   then   {MySize为服务端发送的字节数,如果为0表示为尚未开始图象接收}  
      begin  
      S   :=   Socket.ReceiveText;  
      MySize   :=   Strtoint(S);   {设置需接收的字节数}  
      Clientsocket1.Socket.SendText('ready');   {发指令通知服务端开始发送图象}  
      end  
      else  
      begin   {以下为图象数据接收部分}  
      MyReceviceLength   :=   socket.ReceiveLength;   {读出包长度}  
      StatusBar1.SimpleText   :=   '正在接收数据,数据大小为:'   +   inttostr(MySize);  
      Socket.ReceiveBuf(MyBuffer,   MyReceviceLength);   {接收数据包并读入缓冲区内}  
      MyStream.Write(MyBuffer,   MyReceviceLength);   {将数据写入流中}  
      if   MyStream.Size   >=   MySize   then   {如果流长度大于需接收的字节数,则接收完毕}  
      begin  
      MyStream.Position   :=   0;  
      MyBmp   :=   tbitmap.Create;  
      MyJpg   :=   tjpegimage.Create;  
      try  
      MyJpg.LoadFromStream(MyStream);   {将流中的数据读至JPG图像对象中}  
      MyBmp.Assign(MyJpg);   {将JPG转为BMP}  
      StatusBar1.SimpleText   :=   '正在显示图像';  
      Image1.Picture.Bitmap.Assign(MyBmp);   {分配给image1元件   }  
      finally   {以下为清除工作   }  
      MyBmp.free;  
      MyJpg.free;  
      Button2.Enabled   :=   true;  
      {   Socket.SendText('cap');添加此句即可连续抓屏   }  
      MyStream.Clear;  
      MySize   :=   0;  
      end;  
      end;  
      end;  
      end;  
      procedure   TForm1.FormClose(Sender:   TObject;   var   Action:   TCloseAction);  
      begin  
      MyStream.Free;   {释放内存流对象}  
      if   ClientSocket1.Active   then   ClientSocket1.Close;   {关闭Socket连接}  
      end;  
      end.  
       
          程序原理:运行服务端开始侦听,再运行客户端,输入服务端IP地址建立连接,然后发一个字符通知服务端抓屏幕。服务端调用自定义函数Cjt_GetScreen抓取屏幕存为BMP,把BMP转换成JPG,把JPG写入内存流中,然后把流发送给客户端。客户端接收到流后做相反操作,将流转换为JPG再转换为BMP然后显示出来。  

    展开全文
  •  封装各种抓屏操作的类   ///     public   class  CatchScreen   ... {   /**/ ///     ///  获得屏幕指定区域    ///     ///    name="left">   ///    name="top">   ///    name=...
    using System;
    using System.Runtime.InteropServices;
    using System.Drawing;

    namespace SystemTools
    {
        [StructLayout(LayoutKind.Sequential)]
        
    public struct RECT
        
    {
            
    public int left, top, right, bottom;
        }


        
    /// <summary>
        
    /// 封装API的类
        
    /// </summary>

        public class APIs
        
    {
            [DllImport(
    "user32.dll")]
            
    public static extern bool GetCursorPos(ref Point lpPoint);
            [DllImport(
    "user32.dll")]
            
    public static extern int WindowFormPoint(Point lpPoint);
            [DllImport(
    "user32.dll")]
            
    public static extern IntPtr GetDesktopWindow();
            [DllImport(
    "user32.dll")]
            
    public static extern int GetForegroundWindow();
            [DllImport(
    "user32.dll")]
            
    public static extern int GetWindowRect(int hwnd, ref RECT rc);
            [DllImport(
    "user32.dll")]
            
    public static extern int GetWindowDC(int hwnd);
            [DllImport(
    "Gdi32.dll")]
            
    public static extern bool Bitblt(
                IntPtr hdcDest, 
    // 目标设备的句柄
                int nXDest, // 目标对象的左上角的X坐标
                int nYDest, // 目标对象的左上角的X坐标
                int nWidth, // 目标对象的矩形的宽度
                int nHeight, // 目标对象的矩形的长度
                IntPtr hdcSrc, // 源设备的句柄
                int nXSrc, // 源对象的左上角的X坐标
                int nYSrc, // 源对象的左上角的X坐标
                System.Int32 dwRop // 光栅的操作值
                );
            [DllImportAttribute(
    "gdi32.dll")]
            
    public static extern IntPtr CreateDC(
            
    string lpszDriver, // 驱动名称
            string lpszDevice, // 设备名称
            string lpszOutput, // 无用,可以设定位"NULL"
            IntPtr lpInitData // 任意的打印机数据
            );

        }

    }

     
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Drawing.Imaging;

    namespace SystemTools
    {
        
    /// <summary>
        
    /// 封装各种抓屏操作的类
        
    /// </summary>

        public class CatchScreen
        
    {
            
    /// <summary>
            
    /// 获得屏幕指定区域 
            
    /// </summary>
            
    /// <param name="left"></param>
            
    /// <param name="top"></param>
            
    /// <param name="width"></param>
            
    /// <param name="height"></param>
            
    /// <returns></returns>

            public Bitmap getScreen(int left, int top, int width, int height)
            
    {
                IntPtr dc1 
    = APIs.CreateDC("DISPLAY"nullnull, (IntPtr)null);
                Graphics newGraphics 
    = Graphics.FromHdc(dc1);
                Bitmap img 
    = new Bitmap(width, height, newGraphics);
                Graphics thisGraphics 
    = Graphics.FromImage(img);
                IntPtr dc2 
    = thisGraphics.GetHdc();
                IntPtr dc3 
    = newGraphics.GetHdc();
                APIs.Bitblt(dc2, 
    00, width, height, dc3, left, top, 13369376);
                thisGraphics.ReleaseHdc(dc2);
                newGraphics.ReleaseHdc(dc3);
                
    return img;
            }


            
    /// <summary>
            
    /// 获得全屏
            
    /// </summary>
            
    /// <returns></returns>

            public Bitmap getFullScreen()
            
    {
                
    return getScreen(00, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            }


            
    /// <summary>
            
    /// 抓取句柄所指窗口
            
    /// </summary>
            
    /// <param name="hwnd"></param>
            
    /// <returns></returns>

            public Bitmap getScreenFromHandle(int hwnd)
            
    {
                RECT rc 
    = new RECT();
                APIs.GetWindowRect(hwnd, 
    ref rc);
                
    return getScreen(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
            }


            
    /// <summary>
            
    /// 抓取活动窗口
            
    /// </summary>
            
    /// <returns></returns>

            public Bitmap getScreenFromActiveWindow()
            
    {
                
    int handle = APIs.GetForegroundWindow();
                
    return getScreenFromHandle(handle);
            }


            
    //保存成各种格式
            public string savepic(Bitmap bmp)
            
    {
                SaveFileDialog saveDialog 
    = new SaveFileDialog();
                saveDialog.Filter 
    = "位图文件 (*.bmp)|*.bmp|jpg文件 (*.jpg)|*.jpg|gif文件 (*.gif)|*.gif|tiff文件 (*.tiff)|*.tiff|"+
                
    "emf文件 (*.emf)|*.emf|图标文件 (*.ico)|*.ico|wmf文件 (*.wmf)|*.wmf|png文件 (*.png)|*.png";
                saveDialog.DefaultExt
    ="*.bmp";
                
    if(saveDialog.ShowDialog() == DialogResult.OK)
                
    {
                
    string ext = saveDialog.FileName.Substring(saveDialog.FileName.Length-4,4);
                
    switch( ext)
                

                
    case ".bmp":
                bmp.Save(saveDialog.FileName,ImageFormat.Bmp);
                
    break
                
    case ".gif"
                bmp.Save(saveDialog.FileName,ImageFormat.Gif);
                
    break;
                
    case ".jpg"
                bmp.Save(saveDialog.FileName,ImageFormat.Jpeg);
                
    break;
                
    case ".emf":
                bmp.Save(saveDialog.FileName,ImageFormat.Emf);
                
    break
                
    case ".ico"
                bmp.Save(saveDialog.FileName,ImageFormat.Icon);
                
    break;
                
    case ".wmf"
                bmp.Save(saveDialog.FileName,ImageFormat.Wmf);
                
    break;
                
    case ".png"
                bmp.Save(saveDialog.FileName,ImageFormat.Png);
                
    break;
                
    case ".tiff"
                bmp.Save(saveDialog.FileName,ImageFormat.Tiff);
                
    break;
                
    default :
                
    return "";
                }
     
                
    return saveDialog.FileName;
                }

                
    return "";
            }

        }

    }



    Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=2252958


    <script src="http://localhost:82/PromoteIcon.aspx?id=2252958" type="text/javascript"></script> [收藏到我的网摘]   [发送Trackback]  编程浪子涛发表于 2008年04月05日 11:47:48
    href="http://blog.csdn.net/MadeInJack/Services/Pingback.aspx" rel="pingback" /> <script type="text/javascript">function hide(){showComment();}</script>



     
    展开全文
  •  封装各种抓屏操作的类   ///     public   class  CatchScreen   ... {   /**/ ///     ///  获得屏幕指定区域    ///     ///    name="left">   ///    name="top">   ///    name=...
  • DELPHI屏幕截图抓屏工具源代码.rarDELPHI屏幕截图抓屏工具源代码.rarDELPHI屏幕截图抓屏工具源代码.rarDELPHI屏幕截图抓屏工具源代码.rar
  • c#屏幕截屏、抓屏

    2020-02-05 15:47:37
    这时,用传统的代码抓屏时就会出现显示区域不全的问题。 原因在于当前显示器的“屏幕分辨率当前物理大小”和屏幕显示大小不一致,对应的获取方法分别如下: /// <summary> /// 获取真实设置的桌面分辨率...
  • 这个是GDI的多屏幕扩展抓屏,下面这篇文章讲的是DXGI,欢迎下载https://blog.csdn.net/xjb2006/article/details/107079312
  • 谁说抓图只能用QQ、用打印屏幕,PHP也能做到,本文主要介绍PHP抓屏函数实现屏幕快照的方法
  • VC++截图程序,可以抓取当前屏幕,完成按下键盘的“PringScreenSysRq“键的功能。不同的是,这个程序还可以在抓取框中滚动抓取来的屏幕,可将其直接保存为BMP位图文件。
  • VC屏幕捕获,也就是抓屏、截图程序,当点击抓屏后,会自动打开画图程序,并将已抓到的图片显示在画图程序内,你可以借助画图程序将其保存,另外,程序也设计了拖动鼠标进行区域截图的功能,不过不是很好用,可能还...
  • 抓屏

    2007-08-18 09:07:00
    目录: l 导言l 用GID函数抓屏l 用DirectX方式抓屏l 用Windows Media API抓屏 导言 有时候我们需要编程抓取整个屏幕上的内容,下面我将介绍抓屏是如何实现的。典型地,我们可以用GID和DirectX来完成,另外一...
  • vc 抓屏程序,截取当前屏幕核心代码,为了操作和显示方便,这里为其增加了一套窗体,你只需在启动程序后在窗体的空白处点击右键,即可将当前屏幕的内容截取下来,并显示在窗体中,与QQ抓图十分相似,但要像QQ截图...
  • VC++截图程序,可以抓取当前屏幕,完成按下键盘的“PringScreenSysRq“键的功能。不同的是,这个程序还可以在抓取框中滚动抓取来的屏幕,可将其直接保存为BMP位图文件。 源码下载地址:点击下载 备用下载地址:...
  • android抓屏

    千次阅读 2013-12-09 16:21:38
    想要做图片的分享功能,首先就需要抓屏,将当前屏幕保存为一个图片文件。 下面就是一个将当前的Activity直接保存为一个图片文件的类库,可以直接使用。需要的,直接拿来主义就好了。 package ...
  • ADB调试桥的客户端应用程序,当ASM开始监控屏幕的时候,它通过5037端口连接至ADB,不断地把所监控设备的屏幕数据保存在帧缓存中并且把图像数据转换成用户可观测的内容。概念和业务场景明白了,下面就是实现的过程: ...
  • FastStone Capture这款屏幕截图工具我已经用了三四年了. 在这里给大家推荐一个小软件 。主要用于截图,这类软件现在是太多了,之所以觉得它不错第一是因为体积小,这个版本不是最新的,但是我觉得最好用的,第二...
  • #!/usr/bin/python'''by zevolo, 2012.12.20'''import gtk.gdkimport gtkimport glibclass MyRect():def __init__(self, x = 0, y = 0, w = 0, h = 0):self.x = xself.y = yself.w = wself.h = hdef __init__(self, ...
  • 抓屏原理

    2013-02-20 09:26:00
    有时候我们需要编程抓取整个屏幕上的内容,下面我将介绍抓屏是如何实现的。典型地,我们可以用GID和DirectX来完成,另外一个选择是Windows Media API,在这篇文章我会逐一加以分析。在每一种方法里,一旦我们把...
  • webrtc windows抓屏

    千次阅读 2018-07-16 16:52:34
    在webrtc对外接口中,没有直接实现屏幕共享和抓屏接口; 但是可以webrtc中实现了windows上的抓屏模块; DesktopCapturer   src\modules\desktop_capture\desktop_capturer.h   具体可以参考示例; 这里特别...
  • RPA抓屏技术

    2020-09-04 22:32:16
    为了模拟人工在应用程序上的操作,RPA就必须要与屏幕上各种窗口、按钮、下拉列表等不同要素进行交互,所以RPA中有一项重要的技术,俗称“抓屏”(Screen Scraping)。这里谈到的抓屏技术,并不是传统意义上所说的...

空空如也

空空如也

1 2 3 4 5 ... 16
收藏数 308
精华内容 123
关键字:

屏幕抓屏