Solved

Drawing on a TBitmap using bits.

Posted on 2006-10-26
3
210 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help on project with Soap 10 54
How to debug For loops? 3 53
Delphi: ForceDirectory plain function 7 35
Base1 Encode/Decode 3 77
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…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

825 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