Recent

Author Topic: TFPColor  (Read 956 times)

Bart

  • Hero Member
  • *****
  • Posts: 4034
    • Bart en Mariska's Webstek
Re: TFPColor
« Reply #15 on: November 15, 2020, 12:07:22 am »
@Bart:
It doesn't actually answer the question, does it? And if it doesn't it's useless, quiaff? Now, it *is* possible that circular doesn't want or know how to help, but I consider that rather unlikely. Then, why is his post unhelpfull? Because there is stuff missing from it. Maybe advanced users can guess that on their own, but I certainly couldn't, and I informed him... in a rather verbose fashion...

You could have phrased that (not being of help for you) quite a bit nicer.
A simple "I don't get how that helps with my current problem", would have sufficed.
This leaves open the possibility that the answer indeed was helpfull, but you did not quite see how.

The way you behave in this thread is not going to make you popular here.

Mind you, most of us really like to help anybody who asks questions here.
You make it rather difficult for us.

Bart
« Last Edit: November 15, 2020, 12:18:59 am by Bart »

wp

  • Hero Member
  • *****
  • Posts: 7737
Re: TFPColor
« Reply #16 on: November 15, 2020, 12:10:50 am »
So essentially, they make us jump through hoops when we just want to draw a simple dot on a paintbox???
You don't need TFPColor at all to draw a dot on a paintbox, TColor is enough. Please specify what you want to do.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

winni

  • Hero Member
  • *****
  • Posts: 2000
Re: TFPColor
« Reply #17 on: November 15, 2020, 12:16:53 am »
(Does this make sense?)

No.

If you were not so bullheaded and just have a look at the offered solutions, maybe you step a little bit forward.

Again: TBGRApixel

It has:

Code: Pascal  [Select][+][-]
  1. procedure FromFPColor(AColor: TFPColor);
  2. function ToFPColor: TFPColor;
  3.  

You could have found out . With our help.
But it seems that you don't even have looked into the code.

Winni

Andrew0Red

  • New member
  • *
  • Posts: 8
Re: TFPColor
« Reply #18 on: November 15, 2020, 12:38:10 am »
I was trying to do something like

PaintBox.Canvas.DrawPixel(x,y,TColorToFPColor($aa00aa));

to draw a pixel on a paintbox. (Not set on a paintbox, could be anything.)


'Operator overload' - sort of creating my own constructor for TFPColor? That would work too (prob. not with my skills, though).



And I think I should have posted in beginner...

wp

  • Hero Member
  • *****
  • Posts: 7737
Re: TFPColor
« Reply #19 on: November 15, 2020, 01:24:02 am »
The canvas of a Paintbox (I hope we are talking of the same thing...) is class TCanvas which uses 8-bit-per-channel colors. Using TFPColor does not give you an advantage here, in particular since you start with a TColor value. So, I'd set a TColor to the Pixels[] property instead which uses a TColor directly. (not the fastest, though):

Code: Pascal  [Select][+][-]
  1.   Paintbox.Canvas.Pixels[x, y] := $aa00aa;
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

anyone

  • Guest
Re: TFPColor
« Reply #20 on: November 15, 2020, 08:58:13 am »
This is how I extract RGB from TFPColor, though I have not tested with it how to form a TFPColor with RGB values.

Code: Pascal  [Select][+][-]
  1. var img : TFPMemoryImage;
  2.     pixel : TFPColor;
  3.    r, g, b:byte;
  4.  
  5.              pixel := img.Colors[x,y];
  6.              r := (pixel.Red shr 8) and $00ff;
  7.              g := (pixel.Green shr 8) and $00ff;
  8.              b := (pixel.Blue shr 8) and $00ff;

I have not tested the following, but it can compiles:

Code: Pascal  [Select][+][-]
  1.              
  2.              pixel.Red:=r * $101;
  3.              pixel.Green:=g * $101;
  4.              pixel.Blue:=b * $101;

So if r=$cc (Byte), if would expand to $cccc (Word) for pixel.Red, and so forth.
« Last Edit: November 15, 2020, 09:18:12 am by anyone »

Andrew0Red

  • New member
  • *
  • Posts: 8
Re: TFPColor
« Reply #21 on: November 15, 2020, 12:34:55 pm »
Code: Pascal  [Select][+][-]
  1.              
  2.              pixel.Red:=r * $101;

Don't think I'm going to use this, but *sweet* scaling!


Code: Pascal  [Select][+][-]
  1.   Paintbox.Canvas.Pixels[x, y] := $aa00aa;

Ah, much simpler! You mention inefficiency, but if I only use this for creating the hexagonal bitmaps in the first place, and then use the completed bitmaps later, it'd probably run fast enough for turn-based.


Thank you!


Sorry.



wp

  • Hero Member
  • *****
  • Posts: 7737
Re: TFPColor
« Reply #22 on: November 15, 2020, 05:14:00 pm »
Code: Pascal  [Select][+][-]
  1.   Paintbox.Canvas.Pixels[x, y] := $aa00aa;
You mention inefficiency, but if I only use this for creating the hexagonal bitmaps in the first place, and then use the completed bitmaps later, it'd probably run fast enough for turn-based.
No problem in this kind of application. You'll be unhappy with Canvas.Pixels[], though, when you manipulate a 20 mega-pixel image.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

circular

  • Hero Member
  • *****
  • Posts: 3568
    • Personal webpage
Re: TFPColor
« Reply #23 on: November 15, 2020, 10:57:38 pm »
Code: Pascal  [Select][+][-]
  1.   Paintbox.Canvas.Pixels[x, y] := $aa00aa;

Ah, much simpler!
That's the Pixels property I was mentioning.
Conscience is the debugger of the mind

winni

  • Hero Member
  • *****
  • Posts: 2000
Re: TFPColor
« Reply #24 on: November 15, 2020, 11:29:05 pm »

No problem in this kind of application. You'll be unhappy with Canvas.Pixels[], though, when you manipulate a 20 mega-pixel image.

Not such a big problem.
Meanwhile you can boil fresh coffee.

Winni

wp

  • Hero Member
  • *****
  • Posts: 7737
Re: TFPColor
« Reply #25 on: November 16, 2020, 12:39:46 am »
Code: Pascal  [Select][+][-]
  1.   Paintbox.Canvas.Pixels[x, y] := $aa00aa;

Ah, much simpler!
That's the Pixels property I was mentioning.
Sorry, circular. I misunderstood your post then. The OP was asking about FPColor and since I had never used FPColor in the context of a TCanvas I thought he is working with FP-Image where there is a Pixels property, too, but with a different meaning (Palette index). Only later it became clear that the questions was about a standard TCanvas, and I still did not see your post in this new context.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

circular

  • Hero Member
  • *****
  • Posts: 3568
    • Personal webpage
Re: TFPColor
« Reply #26 on: November 16, 2020, 09:26:31 am »
No problem.

We agree with a solution.  :)
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018