OLEPicture fromByteArray: - How does this look?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

OLEPicture fromByteArray: - How does this look?

Christopher J. Demers
I have implemented a fromByteArray: method for the OLEPicture class to
create one based on a ByteArray.  I needed this because I want to display
photos directly from a database without having to save them to a file first.
My code seems to work.  I just wonder if there were any "gotchas" lurking in
my use of IStream or IPicture.  Does anyone know of a better way to do this?
Feel free to use this code.

Here is a little test code:
=====================
fs := FileStream read: 'D:\test\test.jpg' text: false
op := OLEPicture fromByteArray: fs contents.

shell := Shell show.
op drawOn: shell view canvas.
=====================
Here are the methods I added:
=====================
!OLEPicture class methodsFor!

fromByteArray: byteArray

 "cdemers - 12-11-2001 Return a new OLEPicture based on byteArray."
 ^super new loadFromByteArray: byteArray.! !
!OLEPicture class categoriesFor: #fromByteArray:!*-unclassified!public! !

!OLEPicture methodsFor!

loadFromByteArray: byteArray

 "cdmers 12-5-2001 Load from byteArray."
 | is |

 is := IStream onHGLOBAL.
 is nextPutAll: byteArray.
 is position: 0.
 picture := IPicture readFromIStream: is.
 is free.
 self realize.! !
!OLEPicture categoriesFor: #loadFromByteArray:!*-unclassified!public! !
=====================

Chris