On 11.06.2014, at 00:36, Sungjin Chun <chunsj@castlesoft.co.kr> wrote:If the width is a multiple of 4, you can use the byte array directly as form bits:
> 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.
| w h bytes form |
w := 100.
h := 60.
bytes := ((1 to: w*h) collect: [:i | 256 atRandom - 1]) asByteArray.
form := ColorForm extent: w@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 -
_______________________________________________
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners