Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Algorithmen, Datenstrukturen und Klassendesign (https://www.delphipraxis.net/78-algorithmen-datenstrukturen-und-klassendesign/)
-   -   How to get Integer from Pointer (https://www.delphipraxis.net/211934-how-get-integer-pointer.html)

neumimnemecky 23. Nov 2022 18:35


How to get Integer from Pointer
 
Hello,
I have a TBitmap or TPaintBox and I scanline to get pointer to first line...

Code:
ps0 := DWORD(bm1.scanline[0]);
Then I have
Code:
type TRGBColor = Integer;
var pFirstByte:DWord;
MyColor: TRGBColor;
MyColor:= how to make the cast to get the color in integer?

This is just for comparison of colors, the order of bytes is not important here.

TurboMagic 23. Nov 2022 18:50

AW: How to get Integer from Pointer
 
1. I'm not sure why you're posting in English here, when there's an English forum over at en.delphipraxis.net but welcome here anyway.

2. Why don't you declare a pointer to that TRGBType and let that one point to the scanline property? By incremeinting that pointer you can scan 4 bytes forwards then.

Something like this one:

Delphi-Quellcode:
type
  TRGBColor = Integer;
var
  pFirstByte:^TRGBColor;
  MyColor: TRGBColor;
begin
  pFirstByte := DWORD(bm1.scanline[0]);
  MyColor := pFirstByte^;
  inc(pFirstByte); // point to the next color(s)
  MyColor := pFirstByte^;

neumimnemecky 23. Nov 2022 19:14

AW: How to get Integer from Pointer
 
Because I have type like this:

Code:
type Arr =
  // Array[1..9] represents the sampled pixels around and including current position
  Array[1..256] of Array[1..256] of Array[1..9] of TRGBColor;
type PArray = ^Arr;
...
new(pArr);
pArr is container of sampled pixels. By sampled I mean, that I have picked up colors from image and store them there.

neumimnemecky 23. Nov 2022 20:57

AW: How to get Integer from Pointer
 
I have found solution.

Code:
new(pArr);
p := pFirstByte;
pArr^[1][1][1]:=PINT(p)^; // Test of the first pixel color
:-D

I have found help in code of David Dirkse.


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:02 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz