Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OLEPicture fromByteArray: - How does this look?

3 views
Skip to first unread message

Christopher J. Demers

unread,
Dec 11, 2001, 11:28:44 PM12/11/01
to
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


0 new messages