Drawing on a TBitmap using bits.


I was wondering if there is an easy way to draw on a TBitmap's canvas a bit map ?? (eg. '0001100011' where zeros are white and ones are black pixels)

THX in advance for any help
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

no, not exactly. however, assuming that the bit map is an array of byte, you can do something like this:

var b:tbitmap; i,x,y:integer; a:array of byte;
    mask:byte; p:0..7; c:tcolor;
  for i:=1 to length(a) do
    for p:=7 downto 0 do
      if a[i] and (1 shl p)= 1 then c:=clblack
                               else c:=clwhite;
      x:=length(a)*8 mod b.width;
      y:=length(a)*8 div b.width;
      b.Canvas.Pixels[x, y]:=c;

not tested but looks ok. let me know if there are issues.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
If you're interested in speed, you may define a mask with 1's and 0's and then use MaskBlt.
(I mean using the same bits you already have, not bytes)...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.