Forum > Graphics

How to make a TBitMap in 2-color-Mode (PixelFormat=pf1bit) to work?

<< < (2/5) > >>

Hartmut:

--- Quote from: wp on December 19, 2023, 05:31:04 pm ---I did some further investigation why it first did not work in Linux and then it did: I also had switched from gtk2 to qt5 widgetset - on gtk2 it is not working (screenshot like in your initial post), on qt5 it works (screenshot like in my previous post). I also checked gtk3 - here the monochrome bitmap is converted to 24bit.

--- End quote ---

Thank you wp for investigating this. I'm on gtk2. Switching to qt5 now is not an option. But good to know for the future. Maybe I must stay with my 24-bit TBitMap...

Or is there any other class, where I can draw a font character on it and which can be set to monochrome and where I can read it's pixels?

wp:

--- Quote from: Hartmut on December 19, 2023, 03:00:19 pm ---I want to draw font characters of a selectable Font on a TCanvas of a TBitMap and then analyze their shape. For 2 reasons I want to use this TBitMap in 2-color-Mode (PixelFormat=pf1bit):
1) then I have only 2 colors to analyze (not black and white and *many* gray values)

--- End quote ---
Hmmm.... But the gray colors are what makes true-type fonts look nice. In pure black and white (no grays), the characters will look very ugly. Do you want this?

Hartmut:

--- Quote from: wp on December 19, 2023, 06:57:09 pm ---
--- Quote from: Hartmut on December 19, 2023, 03:00:19 pm ---I want to draw font characters of a selectable Font on a TCanvas of a TBitMap and then analyze their shape. For 2 reasons I want to use this TBitMap in 2-color-Mode (PixelFormat=pf1bit):
1) then I have only 2 colors to analyze (not black and white and *many* gray values)

--- End quote ---
Hmmm.... But the gray colors are what makes true-type fonts look nice. In pure black and white (no grays), the characters will look very ugly. Do you want this?

--- End quote ---

Yes. Because I do not display those characters, I only "draw" them somewhere not visual with the only purpose to analyze their shape. Therefore monochrome is much easier as to have many grays.

wp:
Here is a mini project based on FCLImage which works in Windows and Linux/gtk2 and displays the (anti-aliased) pixels of a text in black-and-white:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project1; uses  Types, FPImage, FPCanvas, FPImgCanv, FTFont; const  TXT = 'A'; var  img: TFPMemoryImage;  cnv: TFPCustomCanvas;  fnt: TFreeTypeFont;  sz: TSize;  x, y: Integer;  c: TFPColor;  fontName: String = 'DejaVuSans';begin  {$IFDEF Linux}  FTFont.InitEngine('/usr/share/fonts/truetype/ttf-dejavu/');  fontName := '/usr/share/fonts/truetype/dejavu/' + fontName;  {$ENDIF}  fnt := TFreeTypeFont.Create;  fnt.AntiAliased := false;   img := TFPMemoryImage.Create(1, 1);   // measure text size  cnv := TFPImageCanvas.Create(img);  cnv.Font := fnt;  cnv.Font.Name := fontName;  cnv.Font.Size := 20;  cnv.Font.FPColor := colBlack;  sz := cnv.TextExtent(TXT);  img.SetSize(sz.CX, sz.CY);   // Draw background  cnv.Brush.FPColor := colWhite;  cnv.FillRect(0, 0, img.Width, img.Height);   // Draw text  cnv.TextOut(0, sz.Cy, TXT);   // Output to screen  for y := 0 to img.Height-1 do  begin    for x := 0 to img.Width-1 do    begin      c := img.Colors[x, y];      if c = colBlack then        Write('XX')      else      if c = colWhite then        Write('..')      else        Write('??');    end;    WriteLn;  end;   cnv.Free;  img.Free;  fnt.Free;end.        

Hartmut:
Thank you very much wp for that demo. I studied it and again learned from you. Unfortunately it does not return the results which I am looking for:

In 1st line I want to detect if an UTF8-character is contained in a font or not. If not, those characters are normally displayed as a rectangle with 4 or 6 hex digits in it (see $EFBFBE and $EFBFBF in screenshot1).

With my program from my 1st post (with a small modification by using your displaying routine and setting Font.Height:=16) you can see this shape in screenshot2 (lower part), while your program shows something completely other (see screenshot3, lower part).

But even for valid UTF8-characters I found discrepancies: e.g. UTF-char $EFBFA5 is shown normally as something like letter "y" with 2 horizontal lines (see also screenshot1). My program from my 1st post shows the same (see screenshot2, upper part). But your program shows some additional artefact (see screenshot3, upper part). Another example would be $C2A9, which should display a "(c)" Copyright sign, but there is an additional "Ä" before it with your code (screenshot 4).

I don't want you to spend more time into this project because it is not important enough for me. I have a (not so ideal) 24-bit solution which "does the job". It would be fine to have a monochrome solution (which might be something faster), but it's not worth that you spend more time on it (I hope I found the right words - my English is not so good). Again thanks that you tried to help me.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version