[Implemented] SaveImageToMemory()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
cxAlex
User
User
Posts: 88
Joined: Fri Oct 24, 2008 11:29 pm
Location: Austria
Contact:

[Implemented] SaveImageToMemory()

Post by cxAlex »

Implemented as EncodeImage()

I'd like some commands to save images directly to the memory, for example in JPG format. I always have to save the image to the HD and read it again into the memory, for example when i make a screenshot an send it directly via network. An JPG - compressed it's much faster than send it raw.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

There is Windows only code in these forums to do that using a named pipe. You should be able to find it easily enough.

The request has been made before; but it is not a bad request! :wink:
I may look like a mule, but I'm not a complete ass.
cxAlex
User
User
Posts: 88
Joined: Fri Oct 24, 2008 11:29 pm
Location: Austria
Contact:

Post by cxAlex »

Thank you.

I found the code and made a Procedure:

Code: Select all

Procedure SaveImageToMemory(Image, *MemSize, Format = #PB_ImagePlugin_JPEG, Compression = 7)
  Protected *Mem, MemSize, ImageDataPipe
  MemSize = ImageDepth(Image)*ImageHeight(Image)*ImageWidth(Image)
  *Mem = AllocateMemory(MemSize)
  ImageDataPipe = CreateNamedPipe_("\\.\pipe\ImageDataPipe", #PIPE_ACCESS_INBOUND | #FILE_FLAG_OVERLAPPED, #PIPE_TYPE_BYTE | #PIPE_READMODE_BYTE | #PIPE_NOWAIT, 1, MemSize, MemSize, #NMPWAIT_USE_DEFAULT_WAIT, #Null)
  SaveImage(Image, "\\.\pipe\ImageDataPipe", Format, Compression)
  ReadFile_(ImageDataPipe, *Mem, MemSize, *MemSize, #Null)
  CloseHandle_(ImageDataPipe)
  ProcedureReturn *Mem
EndProcedure
Post Reply