[Newbies] [Q] Creating Form from ByteArray
Bert Freudenberg
bert at freudenbergs.de
Wed Jun 11 10:41:26 UTC 2014
On 11.06.2014, at 00:36, Sungjin Chun <chunsj at castlesoft.co.kr> wrote:
> Hi,
>
> I want to draw gray scale bitmap using byte array which has pixel by pixel gray
> scale value as byte like this;
>
> [0 0 0 0 0 0 0 0
> 16 23 255 78 12 12 12 12
> ...
> ...] (8x4 for example)
>
> I can draw this using Pen class pixel by pixel manner but this is very slow and
> I think there should be faster way of creating a Form using above byte array.
If the width is a multiple of 4, you can use the byte array directly as form bits:
| w h bytes form |
w := 100.
h := 60.
bytes := ((1 to: w*h) collect: [:i | 256 atRandom - 1]) asByteArray.
form := ColorForm extent: w at h depth: 8 bits: bytes.
form colors: ((0 to: 255) collect: [:i | Color gray: i / 255]).
form display
This would be the best and fastest way. If the width is not a multiple of 4 then perhaps you can add the necessary padding when creating the byte array. Otherwise, a very fast way is to use BitBlt to copy whole lines from the byte array to the form.
But even creating a byte array with the right padding just using at:put: would be a lot faster than using a Pen.
- Bert -
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4142 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/beginners/attachments/20140611/4be7703e/smime.bin
More information about the Beginners
mailing list