Solved

Drawing on a TBitmap using bits.

Posted on 2006-10-26
3
211 Views
Last Modified: 2010-04-05
Hi

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
0
Comment
Question by:abrakadabra1
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
2266180 earned 190 total points
ID: 17810649
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;
begin
  for i:=1 to length(a) do
  begin
    for p:=7 downto 0 do
    begin
      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;
    end;
  end;

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

Expert Comment

by:alkisg
ID: 17815216
If you're interested in speed, you may define a mask with 1's and 0's and then use MaskBlt.
0
 
LVL 9

Expert Comment

by:alkisg
ID: 17815227
(I mean using the same bits you already have, not bytes)...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi application Soap connection 5 133
FMX and jaudiotracker playing memory stream 29 98
Firemonkey BASS_Init into a thread 17 56
shape, triangle, dbctrlgrid 3 33
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question