I just picked up Sam’s old clipboard demo “scrap”. For copying images
to the clipboard, it seems that SDL_surfaces are converted to BMPs and
then are serialized into char* buffers so they can be passed through
the API.
The demo code does this by calling SDL_SaveBMP on the SDL_Surface and
writes a temporary file. Then the file is read back in directly into a
char* buffer using fread().
I was wondering how to accomplish this without writing to the file
system. I was thinking of using RWops for this like so:
// Contents of the image_surface are converted to BMP and placed in scrap_buffer
SDL_SaveBMP_RW(image_surface, SDL_RWFromMem(scrap_buffer, scraplen), 1);
But I think I have a problem with this because I think I need to make
sure the buffer is large enough to hold the BMP. But I don’t know the
size should be.
Assuming this is the right approach, is there a safe way I can
determine the size the buffer needs to be?
From: ewmailing@gmail.com (Eric Wing)
Newsgroups: gmane.comp.lib.sdl
Sent: Saturday, June 10, 2006 5:31 PM
Subject: Converting an SDL_Surface to BMP format in memory
I just picked up Sam’s old clipboard demo “scrap”. For copying images
to the clipboard, it seems that SDL_surfaces are converted to BMPs and
then are serialized into char* buffers so they can be passed through
the API.
The demo code does this by calling SDL_SaveBMP on the SDL_Surface and
writes a temporary file. Then the file is read back in directly into a
char* buffer using fread().
I was wondering how to accomplish this without writing to the file
system. I was thinking of using RWops for this like so:
// Contents of the image_surface are converted to BMP and placed in
scrap_buffer
SDL_SaveBMP_RW(image_surface, SDL_RWFromMem(scrap_buffer, scraplen), 1);
But I think I have a problem with this because I think I need to make
sure the buffer is large enough to hold the BMP. But I don’t know the
size should be.
Assuming this is the right approach, is there a safe way I can
determine the size the buffer needs to be?