Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Get picture pixel color



Permlink Replies: 13 - Last Post: Oct 10, 2014 2:14 PM Last Post By: Eli M
Liste Listeler

Posts: 49
Registered: 7/26/07
Get picture pixel color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 26, 2014 9:25 AM
Hi
I can use Get Value(image1.Canvas.Pixels[in]) command from vcl, but it is not working firemonkey.
How can take pixel color on firemonkey?
Eli M

Posts: 1,346
Registered: 11/9/13
Re: Get picture pixel color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 26, 2014 9:43 AM   in response to: Liste Listeler in response to: Liste Listeler
I don't know if XE7 is different but here is XE5 and XE6.

{$IFNDEF VER270}FMX.PixelFormats{$ENDIF}
 
procedure TImageCacheLayout.ApplyNoAlphaEdge(ABitmap: TBitmap; OpacityThreshold: integer);
var
  bitdata1: TBitmapData;
  I: integer;
  J: integer;
  C: TAlphaColor;
begin
  if (ABitmap.Map(TMapAccess.maReadWrite, bitdata1)) then
    try
      for I := 0 to ABitmap.Width - 1 do
        for J := 0 to ABitmap.Height - 1 do
        begin
          begin
              {$IFDEF VER270}
              C := PixelToAlphaColor(@PAlphaColorArray(bitdata1.Data)
              [J * (bitdata1.Pitch div PixelFormatBytes[ABitmap.PixelFormat])
               + 1 * I], ABitmap.PixelFormat);
              {$ELSE}
              C := PixelToAlphaColor(@PAlphaColorArray(bitdata1.Data)
              [J * (bitdata1.Pitch div GetPixelFormatBytes(ABitmap.PixelFormat))
               + 1 * I], ABitmap.PixelFormat);
              {$ENDIF}
               if TAlphaColorRec(C).A<OpacityThreshold then
                begin
                  TAlphaColorRec(C).A := 0;
 
              {$IFDEF VER270}
                  AlphaColorToPixel(C, @PAlphaColorArray(bitdata1.Data)
                    [J * (bitdata1.Pitch div PixelFormatBytes[ABitmap.PixelFormat])
                     + 1 * I], ABitmap.PixelFormat);
              {$ELSE}
                  AlphaColorToPixel(C, @PAlphaColorArray(bitdata1.Data)
                    [J * (bitdata1.Pitch div GetPixelFormatBytes(ABitmap.PixelFormat))
                     + 1 * I], ABitmap.PixelFormat);
              {$ENDIF}
                end;
          end;
        end;
    finally
      ABitmap.Unmap(bitdata1);
    end;
end;


http://www.fmxexpress.com/get-direct-pixel-access-to-bitmaps-in-delphi-xe5-firemonkey-on-android-and-ios/
Liste Listeler

Posts: 49
Registered: 7/26/07
Re: Get picture pixel color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 26, 2014 10:14 AM   in response to: Eli M in response to: Eli M
Hi
Thanks for answer but it is not work on xe 7
I add Fmx.Types on uses but
GetPixelFormatBytes is unknown
[DCC Error] TabbedTemplate.pas(56): E2003 Undeclared identifier: 'GetPixelFormatBytes'
is it xe7 problem?

Eli M wrote:
I don't know if XE7 is different but here is XE5 and XE6.

{$IFNDEF VER270}FMX.PixelFormats{$ENDIF}
 
procedure TImageCacheLayout.ApplyNoAlphaEdge(ABitmap: TBitmap; OpacityThreshold: integer);
var
  bitdata1: TBitmapData;
  I: integer;
  J: integer;
  C: TAlphaColor;
begin
  if (ABitmap.Map(TMapAccess.maReadWrite, bitdata1)) then
    try
      for I := 0 to ABitmap.Width - 1 do
        for J := 0 to ABitmap.Height - 1 do
        begin
          begin
              {$IFDEF VER270}
              C := PixelToAlphaColor(@PAlphaColorArray(bitdata1.Data)
              [J * (bitdata1.Pitch div PixelFormatBytes[ABitmap.PixelFormat])
               + 1 * I], ABitmap.PixelFormat);
              {$ELSE}
              C := PixelToAlphaColor(@PAlphaColorArray(bitdata1.Data)
              [J * (bitdata1.Pitch div GetPixelFormatBytes(ABitmap.PixelFormat))
               + 1 * I], ABitmap.PixelFormat);
              {$ENDIF}
               if TAlphaColorRec(C).A<OpacityThreshold then
                begin
                  TAlphaColorRec(C).A := 0;
 
              {$IFDEF VER270}
                  AlphaColorToPixel(C, @PAlphaColorArray(bitdata1.Data)
                    [J * (bitdata1.Pitch div PixelFormatBytes[ABitmap.PixelFormat])
                     + 1 * I], ABitmap.PixelFormat);
              {$ELSE}
                  AlphaColorToPixel(C, @PAlphaColorArray(bitdata1.Data)
                    [J * (bitdata1.Pitch div GetPixelFormatBytes(ABitmap.PixelFormat))
                     + 1 * I], ABitmap.PixelFormat);
              {$ENDIF}
                end;
          end;
        end;
    finally
      ABitmap.Unmap(bitdata1);
    end;
end;


http://www.fmxexpress.com/get-direct-pixel-access-to-bitmaps-in-delphi-xe5-firemonkey-on-android-and-ios/
Eli M

Posts: 1,346
Registered: 11/9/13
Re: Get picture pixel color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 26, 2014 10:21 AM   in response to: Liste Listeler in response to: Liste Listeler
Change {$IFDEF VER270} to {$IF DEFINED(VER270) OR DEFINED(VER280)}.
Liste Listeler

Posts: 49
Registered: 7/26/07
Re: Get picture pixel color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 26, 2014 11:18 AM   in response to: Eli M in response to: Eli M
Ok . Thanks for answer
Now I can compile it. But only that line is working.

if TAlphaColorRec(C).A<OpacityThreshold then
begin
TAlphaColorRec(C).A := 0;


I want to take pixel color value for (rgb) LiKE GETBLUE, GET RED for the each pixel

It is very easy on vcl and It should be more easy on fire monkey.
This is working vcl site. How can I use that on firemonkey? .
GetRValue(img.Canvas.Pixels[i, j]);
GetGValue(img.Canvas.Pixels[i, j]);
GetBValue(img.Canvas.Pixels[i, j]);

Edited by: Liste Listeler on Sep 26, 2014 11:57 AM

Edited by: Liste Listeler on Sep 26, 2014 12:17 PM

Eli M

Posts: 1,346
Registered: 11/9/13
Re: Get picture pixel color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 26, 2014 2:47 PM   in response to: Liste Listeler in response to: Liste Listeler
TAlphaColorRec(C).R
TAlphaColorRec(C).G
TAlphaColorRec(C).B



//this procedure modify the RGB components of the colors stored in the generics list, adding a delta value (1..255) for each component (R, G, B)
procedure ChangeRGB(dR, dG, dB: Byte);
var
i : Integer;
v : TFMStyleLine;
begin
for i := 0 to FLines.Count-1 do
//only modify the lines which contains a Color <> claNull
if FLines[i].IsColor and (FLines[i].Color<>claNull) then
begin
v:=FLines[i];
TAlphaColorRec(v.Color).R:=TAlphaColorRec(v.Color).R+dR;
TAlphaColorRec(v.Color).G:=TAlphaColorRec(v.Color).G+dG;
TAlphaColorRec(v.Color).B:=TAlphaColorRec(v.Color).B+dB;
if v.Color<>FMod[i].Color then
FMod[i]:=v;
end;
end;

Liste Listeler

Posts: 49
Registered: 7/26/07
Re: Get picture pixel color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 27, 2014 5:29 AM   in response to: Eli M in response to: Eli M
Can you explain how is procedure TImageCacheLayout.ApplyNoAlphaEdge is working?
Where is the color codes?
c value is change but there is no result .


Eli M wrote:
Change {$IFDEF VER270} to {$IF DEFINED(VER270) OR DEFINED(VER280)}.
Eli M

Posts: 1,346
Registered: 11/9/13
Re: Get picture pixel color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 27, 2014 5:43 AM   in response to: Liste Listeler in response to: Liste Listeler
What that procedure does is loop through the pixels of a bitmap and read the color of each pixel out into the C variable. Then it checks the Alpha/Opacity/Transparency value (.A) of the pixel and if it is below the OpacityThreshold it sets the Alpha value to 0 and then writes the pixel color back into the bitmap.

Or that is the goal anyway.
Liste Listeler

Posts: 49
Registered: 7/26/07
Re: Get picture pixel color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 27, 2014 12:47 PM   in response to: Eli M in response to: Eli M
Hi,
I test it from xe6 .
Everything is working. Thanks for answers.
But there is one problem
I have a picture 800 x 600 size and I add it image1
than I coped same picture and rotate 90 angle from the paint and save it. so it will be 600 x 800 size. This is image2.
than I take RGB colors for all pixels. For image1 and image2
the total result is not same.
I think it should be same
Because picture is same picture.
Have you got any idea about that?

Eli M wrote:
What that procedure does is loop through the pixels of a bitmap and read the color of each pixel out into the C variable. Then it checks the Alpha/Opacity/Transparency value (.A) of the pixel and if it is below the OpacityThreshold it sets the Alpha value to 0 and then writes the pixel color back into the bitmap.

Or that is the goal anyway.
Eli M

Posts: 1,346
Registered: 11/9/13
Re: Get picture pixel color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 10, 2014 12:06 PM   in response to: Liste Listeler in response to: Liste Listeler
Yeah no idea without seeing some source code.
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: Get picture pixel color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 10, 2014 12:07 AM   in response to: Eli M in response to: Eli M
Eli M wrote:

Change {$IFDEF VER270} to {$IF DEFINED(VER270) OR DEFINED(VER280)}.

I'm not fond of VER defines. Once XE8 comes along, that must be changed
again. I rather use RTLVersion or CompilerVersion and > or >=.

--
Rudy Velthuis http://www.rvelthuis.de

"Humor is just another defense against the universe."
-- Mel Brooks (1926- )
Eli M

Posts: 1,346
Registered: 11/9/13
Re: Get picture pixel color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 10, 2014 11:56 AM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Unfortunately CompilerVersion does not seem to work in the Uses clause.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Get picture pixel color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 10, 2014 12:41 PM   in response to: Eli M in response to: Eli M
Eli wrote:

Unfortunately CompilerVersion does not seem to work in the Uses
clause.

Yes, it does:

uses
   ... // <-- other units here
  {$IF RTLVersion >= 27}, FMX.PixelFormats{$ENDIF}
  ;


--
Remy Lebeau (TeamB)
Eli M

Posts: 1,346
Registered: 11/9/13
Re: Get picture pixel color
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 10, 2014 2:14 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Odd. When I tried to use it there before I couldn't get it work. I must have had it incorrect somehow. Works for me now though.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02