Page 1 of 1

[Implemented] SaveImageToMemory()

Posted: Tue Apr 14, 2009 6:13 pm
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.

Posted: Tue Apr 14, 2009 6:24 pm
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:

Posted: Tue Apr 14, 2009 6:59 pm
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