[Newbies] [Q] Creating Form from ByteArray

karl ramberg karlramberg at gmail.com
Wed Jun 11 12:08:25 UTC 2014


Form has some class side methods to create Forms from arrays, too.

Cheers,
Karl



On Wed, Jun 11, 2014 at 12:41 PM, Bert Freudenberg <bert at freudenbergs.de>
wrote:

> 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 -
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20140611/c71f6672/attachment.htm


More information about the Beginners mailing list