Perhaps this would help you,
Function PictureToString(p As Picture) As String
#pragma disableBackgroundTasks
Dim x,y,i,w,h,size As Integer
Dim MB As MemoryBlock
Dim Source As Picture
Dim Surface As RGBSurface
Dim c As Color
//First, check parameter validity
If p = nil then
Return ""
End If
//Store picture dimensions
w = p.Width
h = p.Height
//Access picture RGBSurface
Surface = p.RGBSurface
If Surface = nil then
//picture does not have a RGBSurface
//create a new picture which does have the RGBSurface
Source = NewPicture(w,h,24)
Source.Graphics.DrawPicture p,0,0
Surface = Source.RGBSurface
End if
//Create a memoryblock
size = 8+(w*h*3)
MB = NewMemoryBlock(size)
If MB = nil then
//apparently, we don't have enough memory available (if you are not on
OS X)
Return ""
End If
//Store picture dimensions
MB.Long(0) = W
MB.Long(4) = H
i = 8
w = w -1
h = h -1
For y = 0 to H
For x = 0 to W
c = Surface.Pixel(x,y)
MB.Byte(i) = c.Red
MB.Byte(i+1) = c.green
MB.Byte(i+2) = c.blue
i = i+3
Next
Next
//Return the string
Return MB.StringValue(0,Size)
//you may want to skip first 8 bytes as they are not part of the picture
//use this:
//Return MB.StringValue(8.size-8)
End Function
***************************************************************
Function StringToPicture(s As String) As Picture
Dim size,W,H,x,y,i As Integer
Dim MB As MemoryBlock
Dim Source As Picture
Dim Surface As RGBSurface
size = LenB(s)
If size<24 then//not even a pixel
Return Nil
End If
//Create a new MemoryBlock
MB = NewMemoryBlock(size)
if MB = Nil then
//There is not enough memory
Return Nil
End if
//Put the string into MB
MB.StringValue(0,size) = s
//Read picture dimensions
W = MB.Long(0)
H = MB.Long(4)
//Create a new picture
Source = NewPicture(W,H,32)
if Source = nil then
Return Nil
End IF
Surface = Source.RGBSurface
i = 8//skip first 8 bytes
h = h-1
w = w-1
//Main Loop
for y = 0 to h
for x = 0 to w
surface.pixel(x,y) = mb.colorValue(i,24)
i = i+3
next
next
Return Source
End Function
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>