(no subject)
"Boris Gärtner"
Boris.Gaertner at gmx.net
Thu Jun 8 11:21:16 UTC 2006
Noname Myname <gcdart_squeak at rediffmail.com> wrote:
> >
> >>I have a the pixels of a bitmap image which i need to display
> >
This is not a very clear problem description. What kind of a bitmap
image do you have? a black-and-white image? A grayscaled image? A
colored image? You can create Fomrs with different color depths and
also forms with a color map, but to choose a proper form you have to
know the properties of the image.
> >Have you tried making a Morph? Many objects respond to #asMorph,
> >giving a Morph which may be displayed in a morphic project. You could
> >first create a Form from your data, if necessary.
> >
> >Hope this helps!
> >
> >--Tom Phoenix
>
> I have the pixels , ( each pixel corresponds to a byte ),
> as a ByteArray.
Is such a byte used to represent two color values (black or white)
or up to 256 different colors?
> I cud not create a Form the Pixels , becuz i think the form expects some
> kind of initial header structure . Although creating a form does not pop
> any error messages , however when i try to display them , it says an error
> message in BitBlt 's copybits.
> Is there ne work around possible , like directly give the byte values than
> go by creating a Form etc etc..
>
To display an image, you need a form.
Here is the code to create a black-and-white form from a ByteArray:
| byteArray extent form cnt |
byteArray := ByteArray new: 16*16.
33 to: 64 do: [:idx | byteArray at: idx put: 1].
" the byteArray stores the pixels of the black-and-white image
line-by-line. The following code creates a suitable Form and
copies the bits into the form. "
form := Form extent: (extent := 16 at 16).
cnt := 1.
0 to: extent y -1 do:
[:py |
0 to: extent x -1 do:
[:px | | isBlack |
isBlack := (byteArray at: cnt) ~= 0.
form colorAt: px @py put: (isBlack ifTrue: [Color black] ifFalse: [Color white]).
cnt := cnt + 1
].
].
form displayAt: 10 @ 10.
For a gray-scaled image or an image with a color palette you would use a ColorForm that you can convert into a Form if such a conversion is needed.
Hope this helps,
if it does not help, please post a more detailed problem description!
Greetings,
Boris
More information about the Squeak-dev
mailing list
|