Page 1 of 1

ScreenCapture problem!

Posted: Thu Mar 29, 2007 9:09 pm
by kochon
Hi,

I know how to make a FullScreen Capture but when the source app or game is in 8bits color mode, the colors are corrupted.

I Think it's due to the fact in 256 colors mode, the palette is indexed.

So, is it possible to get an indexed palette from a DC or from the resulting bitmap in 8bits mode?

Thanks...
köchOn

Re: ScreenCapture problem!

Posted: Fri Mar 30, 2007 1:05 am
by SFSxOI
kochon wrote:Hi,

I know how to make a FullScreen Capture but when the source app or game is in 8bits color mode, the colors are corrupted.

I Think it's due to the fact in 256 colors mode, the palette is indexed.

So, is it possible to get an indexed palette from a DC or from the resulting bitmap in 8bits mode?

Thanks...
köchOn
Have you tried the GDI Plus API?

Posted: Sun Apr 01, 2007 4:17 pm
by netmaestro
Hello there,

Your screen capture procedure has to be tweaked a bit if you want to capture an 8-bit screen and not lose the colors. Your typical screencapture proc begins with something like:

Code: Select all

SrcDC = CreateDC_("DISPLAY","","",dm.DEVMODE)
or similar, followed by CreateCompatibleBitmap_(SrcDC), all of which is fine for your native display colordepth but incompatible with an 8-bit screen. To correct this, exchange the first line for:

Code: Select all

SrcDC = StartDrawing(ScreenOutput())
and you should be golden, as long as a screen is already open when you call the procedure. Here's a sample proc:

Code: Select all

Procedure.l CaptureScreen(x, y, Width, Height) 
  srcDC = StartDrawing(ScreenOutput()) 
    trgDC = CreateCompatibleDC_(srcDC) 
    BMPHandle = CreateCompatibleBitmap_(srcDC, Width, Height) 
    SelectObject_( trgDC, BMPHandle) 
    BitBlt_( trgDC, 0, 0, Width, Height, srcDC, x, y, #SRCCOPY) 
  StopDrawing() 
  DeleteDC_( trgDC) 
  ProcedureReturn BMPHandle 
EndProcedure 
and a test prog:

Code: Select all

Declare CaptureScreen(x, y, Width, Height) 

InitSprite():InitKeyboard() 

OpenScreen(800,600,8, "") 

Repeat 
  ClearScreen($CC9999)
  StartDrawing(ScreenOutput())
    Circle(130,300,64,#White) 
    Circle(264,300,64,#Red) 
    Circle(400,300,64,#Green) 
    Circle(536,300,64,#Blue) 
    Circle(668,300,64,#Black)
    DrawingMode(#PB_2DDrawing_Transparent)
    DrawText(300, 150, "Press Any Key to Continue...",#Yellow) 
  StopDrawing() 
  FlipBuffers() 
  ExamineKeyboard() 
Until KeyboardReleased(#PB_Key_All) 

hBmp = CaptureScreen(0,0,800,600) 

CloseScreen() 
GetObject_(hBmp, SizeOf(bitmap), bmp.BITMAP)
depth = bmp\bmBitsPixel
OpenWindow(0,0,0,800,600,"Captured Bitmap (depth = "+Str(depth)+" bits/pixel):",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
CreateGadgetList(WindowID(0)) 
ImageGadget(0,0,0,0,0,hBmp) 
Repeat:Until WaitWindowEvent()=#WM_CLOSE 

Procedure.l CaptureScreen(x, y, Width, Height) 
  srcDC = StartDrawing(ScreenOutput()) 
    trgDC = CreateCompatibleDC_(srcDC) 
    BMPHandle = CreateCompatibleBitmap_(srcDC, Width, Height) 
    SelectObject_( trgDC, BMPHandle) 
    BitBlt_( trgDC, 0, 0, Width, Height, srcDC, x, y, #SRCCOPY) 
  StopDrawing() 
  DeleteDC_( trgDC) 
  ProcedureReturn BMPHandle 
EndProcedure 

Posted: Mon Apr 02, 2007 5:56 am
by netmaestro
Just remember if you use that proc to DeleteObject_(hBmp) on the returned bitmap when you're finished with it, else you'll have a memory leak.

Posted: Mon Apr 02, 2007 9:57 am
by kochon
Hi Maestro,

I ve tryed your code but it seems to work in combination with the penScreen function.
It has failed with my code cause I don't use PB Screen commands...

I am working on capturing System colors for the actual Dislpay then converting the bitmap...

Thanks