ScreenCapture problem!

Windows specific forum
kochon
New User
New User
Posts: 8
Joined: Mon May 08, 2006 11:24 am
Location: France

ScreenCapture problem!

Post 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
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: ScreenCapture problem!

Post 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?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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 
BERESHEIT
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
kochon
New User
New User
Posts: 8
Joined: Mon May 08, 2006 11:24 am
Location: France

Post 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
Post Reply