[ itf @ 23.05.2007. 09:34 ] @
Recimo da želim "uslikati" dio forme. Primjerice, dio definiran s 4 koordinate (x1, x2, y1, y2) i da to stavim u radnu memoriju (copy). Ideje? Hvala |
[ itf @ 23.05.2007. 09:34 ] @
[ X Files @ 23.05.2007. 10:30 ] @
Otprilike ovako nekako /netestirano/:
GetDC() - Prozor bez naslovne linije GetWindowDC - Prozor sa naslovnom linijom GetDC(0) - Desktop GetDC( Nesto ) - Handle na prozor Code: // bool All, da li sa naslovnom linijom ili bez // AHandle, da li prozor ili screen // takodje proveri da li treba provera ako je All == true i AHandle == 0, ne znam sta bi se dogodilo Graphics::TBitmap* ScreenCapture( bool All, HDC AHandle, int ALeft, int ATop, int AWidth, int AHeight ) { TRect r = Rect(ALeft, ATop, AWidth, AHeight); Graphics::TBitmap *bmp = new Graphics::TBitmap(); bmp->Width = r.Width(); bmp->Height = r.Height(); bmp->PixelFormat = pf32bit; HDC hdc; if ( All ) hdc = ::GetWindowDC( AHandle ); else hdc = ::GetDC( AHandle ); ::BitBlt( bmp->Canvas->Handle, 0, 0, bmp->Width, bmp->Height, hdc, ALeft, ATop, SRCCOPY); ::ReleaseDC( AHandle, hdc ); return bmp; } void __fastcall TForm1::Button1Click(TObject *Sender) { Image1->Picture->Bitmap->Assign( ScreenCapture( true, Form1->Handle, 10, 10, 100, 100 ) ); } ... a moze i sa CopyRect(), ako uspem da odradim, stavicu ovde kao EDIT: Code: Graphics::TBitmap* ScreenCapture2( bool All, HDC AHandle, int ALeft, int ATop, int AWidth, int AHeight ) { TRect r1 = Rect( ALeft, ATop, AWidth, AHeight ); Graphics::TBitmap *bmp = new Graphics::TBitmap(); bmp->Width = r1.Width(); bmp->Height = r1.Height(); bmp->PixelFormat = pf32bit; TCanvas *ScreenCanvas = new TCanvas(); try { if ( All ) ScreenCanvas->Handle = ::GetWindowDC( AHandle ); else ScreenCanvas->Handle = ::GetDC( AHandle ); try { TRect r2 = Rect( 0, 0, bmp->Width, bmp->Height ); bmp->Canvas->CopyRect( r2, ScreenCanvas, r1 ); } __finally { ::ReleaseDC( AHandle, ScreenCanvas->Handle ); } } __finally { delete ScreenCanvas; } return bmp; } [Ovu poruku je menjao X Files dana 23.05.2007. u 11:43 GMT+1] [Ovu poruku je menjao X Files dana 23.05.2007. u 12:00 GMT+1] [ itf @ 23.05.2007. 10:58 ] @
Radi, i zahvaljujem ;)
Iako, sjetimo se da Citat: void __fastcall TForm1::Button1Click(TObject *Sender) { Image1->Picture->Bitmap->Assign( ScreenCapture( true, Form1->Handle, 10, 10, 100, 100 ) ); } može izazvati access violation u ovom slučaju :))) pozdrav [ X Files @ 23.05.2007. 11:02 ] @
Citat: može izazvati access violation u ovom slučaju :))) pozdrav Jakako :) Proveri i ReleaseDC() argumente u MSDN dokumentaciji, da ne dodje do nekog issue-a (nisam bio dobro postavio u startu) Pozdrav [ vlaiv @ 24.05.2007. 13:31 ] @
U krajnjoj liniji, mozes i koristiti metodu PaintTo, TWinControl-a, da iscrtas prozor na canvas bitmape ...
Copyright (C) 2001-2025 by www.elitesecurity.org. All rights reserved.
|