Solved

Drawing on a TBitmap using bits.

Posted on 2006-10-26
3
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

687 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