BCB屏幕截图(抓图)程序-转

1、屏幕截图

  void   __fastcall   TmainForm::N31Click(TObject   *Sender)                                                                                                                         

  {

    Graphics::TBitmap   *scrBitmap=new   Graphics::TBitmap();

    scrBitmap->Width=Screen->Width;

    scrBitmap->Height=Screen->Height;

    HDC   hdc=GetWindowDC(0);

    BitBlt(scrBitmap->Canvas->Handle,0,0,scrBitmap->Width,scrBitmap->Height,hdc,0,0,SRCCOPY);

    scrBitmap->SaveToFile(".\\screen\\screen.bmp");

    delete   scrBitmap;

  }

  //---------------------------------------------------------------------------

2、工作区截图

  void   __fastcall   TmainForm::N32Click(TObject   *Sender)

  {

    Graphics::TBitmap   *scrBitmap=new   Graphics::TBitmap();

    scrBitmap->Width=mainForm->Width;

    scrBitmap->Height=mainForm->Height;

    HDC   hdc=GetWindowDC(0);

    BitBlt(scrBitmap->Canvas->Handle,0,0,scrBitmap->Width,scrBitmap->Height,hdc,mainForm->Left,mainForm->Top,SRCCOPY);

    scrBitmap->SaveToFile(".\\screen\\screen1.bmp");

    delete   scrBitmap;

  }

Top

3、远程截取和发送的代码,如果只是本地的,可以直接用savetofile就可以了.

  if(CanCapture)

  {

                  CanCapture=false;

                  HDC   SourceDC,DestDC,Bhandle;

                  Bitmap->Width=Screen->Width;

                  Bitmap->Height=Screen->Height;

                  SourceDC=CreateDC("DISPLAY",NULL,NULL,NULL);

                  StretchBlt(Bitmap->Canvas->Handle,0,0,Bitmap->Width,Bitmap->Height,SourceDC,0,0,Screen->Width,Screen->Height,SRCCOPY);

                  //changetojpg-------------------------------------------

                  jpeg->PixelFormat=jf24Bit;                           //或jf8Bit

                  jpeg->CompressionQuality=Pix;               //1-100

                  jpeg->Assign((TPersistent*)Bitmap);

                  jpeg->Compress();

                  Stream->Clear();

                  jpeg->SaveToStream(Stream);

                  //send   picture----------------------------------------

                  const   int   ThreshHold=2048;

                  Stream->Position=0;

                  char   *Buffer=new   char[ThreshHold];

                  int   BuffSize=Stream->Size;

                  int   Buffers=BuffSize/ThreshHold;

                  for(int   i=0;i<=Buffers;i++)

                  {

                    if(BuffSize>=ThreshHold)

                                  {

                                    Stream->Read(Buffer,ThreshHold);

                                    NMUDP1->SendBuffer(Buffer,ThreshHold,ThreshHold);

                                  }

                    else

                                  {

                                  if(BuffSize<=0)

                                                  break;

                                  else

                                                  {

                                                  Stream->Read(Buffer,BuffSize);

                                                  NMUDP1->SendBuffer(Buffer,BuffSize,BuffSize);

                                                  }

                                  }

                  BuffSize-=ThreshHold;

                  }

                  NMUDP1->SendBuffer("E",1,1);

                  delete   Buffer;

                  CanCapture=true;

  }


阅读更多
换一批

没有更多推荐了,返回首页