Solved

Drawing on a TBitmap using bits.

Posted on 2006-10-26
3
208 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:
ciuly 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now