Forum > Graphics

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

<< < (5/5)

I noticed loading doesn't work so I fixed loading. Is anything else wrong? Lazarus has problems with PixelFormat. You can't change PixelFormat of an "existing" bitmap. You can only set pixelformat when creating an image.

--- 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";}};} ---{loading a .bmp file}procedure TFormPf1bit.Button1Click(Sender: TObject); var bitmap:tbitmap; bitmap2:tbitmap;beginbitmap:=tbitmap.create;try with bitmap do    begin       if openPictureDialog1.execute then        bitmap.LoadFromFile(OpenPictureDialog1.FileName);    end;    label1.caption:=inttostr(bitmap.width)+' '+inttostr(bitmap.height);     bitmap2 := tbitmap.create;    bitmap2.setsize(bitmap.width, bitmap.height);    bitmap2.pixelformat:=pf1bit;    bitmap2.Canvas.CopyRect(rect(0,0,bitmap.width,bitmap.height), bitmap.canvas, rect(0,0,bitmap.width,bitmap.height));    ImageBits.Picture.graphic := Bitmap2;FINALLY    Bitmap.Free;;end;end;  

Ah, I quickly converted it to Lazarus and left the Delphi defines to make it compatible with Delphi.

Like mentioned previously, the colour part does not work in the Lazarus conversion (it does in the Delphi version) but you do get Black and White images.

Perhaps a member of the forum could possibly help with this conversion to add the colour part.


Looks like you posted at the same time as me.

The part where you change to different colours (define palette) does not work in the Lazarus version and as I remember possibly the saving bit (unsure have not touched this for a long time but came across it and thought you may like to play with it).

WP is really good at Delphi to Lazarus conversions. Possibly he may be able to help out.

If you would like the compiled Delphi version I can upload to elsewhere. Enjoy.

You mentioned "can't change PixelFormat"

I also recall that in the Delphi version when defining the PixelFormat it had to be a certain spot to work.

That message is in the code comments for saving to1bit BMP:

      Width  := ImageBits.Picture.Bitmap.Width;
      Height := ImageBits.Picture.Bitmap.Height;

      // Unclear why this must follow width/height to work correctly.
      // If PixelFormat precedes width/height, bitmap will always be black.
      PixelFormat := pf1bit;   

domasz, if you have any luck getting the define palette part to work that would be nice to share. I tried replacing all components with Lazarus components and manually putting in the code and Lazarus compiler directives but went round in circles. Perhaps you will have better luck?

Also in my Lazarus conversion, the loading of the BMP was working OK (possibly because I left the Delphi defines)
I also tried your solution and that worked as well.

With this example, I like how they also do rotation and symmetry of the pixel grid.


[0] Message Index

[*] Previous page

Go to full version