Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Image Pixel Color Conversion

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater Supreme
Reputation: 38

Joined: 10 Apr 2015
Posts: 1537

PostPosted: Wed Sep 02, 2020 10:22 pm    Post subject: Image Pixel Color Conversion Reply with quote

When use, example:

Code:
for i = 0, 10 do
 x = img.Picture.Bitmap.Canvas.getPixel(i,0)
 print(x)
end


it returns values as MS Access color code, like:

3878183
3680804
3680804
3680804
3615011
3680804
3878183
3943976
3746597
3812390
3878183

Now, how to convert that values to RGB values, using CE Lua script?.

In VB, I can use, example:

Code:
Color.FromArgb(_img.getPixel(i, _img.Height - 1).ToArgb))


Any solutions?

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 384

Joined: 09 May 2003
Posts: 23015
Location: The netherlands

PostPosted: Thu Sep 03, 2020 12:52 am    Post subject: Reply with quote

those are rgb colors (system colors are negative)

print using this
Code:

print(string.format('%.8x',x))

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 38

Joined: 10 Apr 2015
Posts: 1537

PostPosted: Thu Sep 03, 2020 11:15 am    Post subject: Reply with quote

Thanks DB, I try:

Code:
print(string.format('%.8x',x))


Those return hex color format?.
But how to port this as Lua script?

Code:
Color.FromArgb(_img.getPixel(i, _img.Height - 1).ToArgb))


I try:

Code:
function HEXtoRGB(hexArg)
   hexArg = hexArg:gsub('#','')
   if(string.len(hexArg) == 3) then
      return tonumber('0x'..hexArg:sub(1,1)) * 17, tonumber('0x'..hexArg:sub(2,2)) * 17, tonumber('0x'..hexArg:sub(3,3)) * 17
   elseif(string.len(hexArg) == 6) then
      return tonumber('0x'..hexArg:sub(1,2)), tonumber('0x'..hexArg:sub(3,4)), tonumber('0x'..hexArg:sub(5,6))
   else
      return 0, 0, 0
   end
end

function RGBtoHEX(redArg, greenArg, blueArg)
   return string.format('%.2x%.2x%.2x', redArg, greenArg, blueArg)
end

--- try to apply, example:

imgSource.setPixel(i + 1, j + 1, HEXtoRGB(RGBtoHEX(_img.getPixel(i, j))))



Get return error : "bad argument #3 to 'format' (number expected, got nil)"


[/code]

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 384

Joined: 09 May 2003
Posts: 23015
Location: The netherlands

PostPosted: Fri Sep 04, 2020 10:36 am    Post subject: Reply with quote

blue=value & 0xff
green=(value >> Cool & 0xff
red=(value >>16) & 0xff

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 38

Joined: 10 Apr 2015
Posts: 1537

PostPosted: Fri Sep 04, 2020 10:53 am    Post subject: Reply with quote

Dark Byte wrote:
blue=value & 0xff
green=(value >> Cool & 0xff
red=(value >>16) & 0xff


Ok, thanks. I will try to apply those statements on the script.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites