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 


How to adjust image transparency

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 203

PostPosted: Tue Dec 10, 2019 10:22 am    Post subject: How to adjust image transparency Reply with quote

Need your help, can you use the code to adjust the transparency of the image, just like PS


transparency.png
 Description:
 Filesize:  616.5 KB
 Viewed:  3649 Time(s)

transparency.png


Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Tue Dec 10, 2019 7:52 pm    Post subject: Reply with quote

This works for CE7.0+
Image "example.png" embedded to table, UDF1 contains empty TCEImage.
Code:
function TBlendFunction(SourceConstantAlpha)
  if TBlendFunctionStruct==nil then
    TBlendFunctionStruct = createMemoryStream()
    TBlendFunctionStruct.writeByte(0) -- BlendOp = AC_SRC_OVER
    TBlendFunctionStruct.writeByte(0) -- BlendFlags
    TBlendFunctionStruct.writeByte(SourceConstantAlpha) -- SourceConstantAlpha
    TBlendFunctionStruct.writeByte(1) -- AlphaFormat = AC_SRC_ALPHA
  else
    TBlendFunctionStruct.Position = 2
    TBlendFunctionStruct.writeByte(SourceConstantAlpha) -- SourceConstantAlpha
  end
  TBlendFunctionStruct.Position = 0
  return TBlendFunctionStruct.readDword()
end

pngImage = createImage(nil)
pngImage.Picture.PNG.loadFromStream(findTableFile('example.png').Stream)

local width  = pngImage.Picture.Bitmap.Width
local height = pngImage.Picture.Bitmap.Height

UDF1.CEImage1.Picture.Bitmap.PixelFormat = pf32bit
UDF1.CEImage1.Picture.Bitmap.Width  = width
UDF1.CEImage1.Picture.Bitmap.Height = height

executeCodeLocalEx("msimg32.AlphaBlend", UDF1.CEImage1.Picture.Bitmap.Canvas.Handle, 0, 0, width, height,
                                              pngImage.Picture.Bitmap.Canvas.Handle, 0, 0, width, height, TBlendFunction(128))
UDF1.CEImage1.repaint()
pngImage.destroy()


Unfortunately official CE7.0 doesn't provide Canvas.Handle. Maybe DB will help you with this.

_________________
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Wed Dec 11, 2019 3:58 am    Post subject: Reply with quote

In ceshare I use
Code:

readPointerLocal(userDataToInteger(sender.Canvas)+0xc8)

to get the handle for the 4th processlist tab for rendering the processicons in 7.0


but you also need to make the handle available first by accessing it. So i've adjusted the script:
Code:

function TBlendFunction(SourceConstantAlpha)
  if TBlendFunctionStruct==nil then
    TBlendFunctionStruct = createMemoryStream()
    TBlendFunctionStruct.writeByte(0) -- BlendOp = AC_SRC_OVER
    TBlendFunctionStruct.writeByte(0) -- BlendFlags
    TBlendFunctionStruct.writeByte(SourceConstantAlpha) -- SourceConstantAlpha
    TBlendFunctionStruct.writeByte(1) -- AlphaFormat = AC_SRC_ALPHA
  else
    TBlendFunctionStruct.Position = 2
    TBlendFunctionStruct.writeByte(SourceConstantAlpha) -- SourceConstantAlpha
  end
  TBlendFunctionStruct.Position = 0
  return TBlendFunctionStruct.readDword()
end

pngImage = createImage(nil)
pngImage.Picture.PNG.loadFromStream(findTableFile('example.png').Stream)

local width  = pngImage.Picture.Bitmap.Width
local height = pngImage.Picture.Bitmap.Height

UDF1.CEImage1.Picture.Bitmap.PixelFormat = pf32bit
UDF1.CEImage1.Picture.Bitmap.Width  = width
UDF1.CEImage1.Picture.Bitmap.Height = height

function getCanvasHandle(canvas)
  return readPointerLocal(userDataToInteger(canvas)+0xc8)
end

UDF1.CEImage1.Picture.Bitmap.Canvas.getPixel(0,0) --makes the handle available
pngImage.Picture.Bitmap.Canvas.getPixel(0,0)

executeCodeLocalEx("msimg32.AlphaBlend", getCanvasHandle(UDF1.CEImage1.Picture.Bitmap.Canvas), 0, 0, width, height,
                                         getCanvasHandle(pngImage.Picture.Bitmap.Canvas), 0, 0, width, height, TBlendFunction(128))
UDF1.CEImage1.repaint()
pngImage.destroy()

_________________
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
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Wed Dec 11, 2019 6:11 am    Post subject: Reply with quote

download msimg32.AlphaBlend.demo.CT.zip
(note: for now only 64bit CE)




script:
Code:
function TBlendFunction(SourceConstantAlpha)
  return byteTableToDword({0,0,SourceConstantAlpha,1})
end

function getCanvasHandle(canvas)
  canvas.getPixel(0,0)
  return readPointerLocal(userDataToInteger(canvas)+0xc8)
end

function demo(alpha)
  pngImage = createImage(nil)
  pngImage.Picture.PNG.loadFromStream(findTableFile('example.png').Stream)

  tmpImage = createImage(nil)

  local width  = pngImage.Picture.Bitmap.Width
  local height = pngImage.Picture.Bitmap.Height

  tmpImage.Picture.Bitmap.PixelFormat = pf32bit
  tmpImage.Picture.Bitmap.Width  = width
  tmpImage.Picture.Bitmap.Height = height

  executeCodeLocalEx("msimg32.AlphaBlend", getCanvasHandle(tmpImage.Picture.Bitmap.Canvas), 0, 0, width, height,
                                           getCanvasHandle(pngImage.Picture.Bitmap.Canvas), 0, 0, width, height, TBlendFunction(alpha))

  UDF1.CEImage1.Picture.assign(tmpImage.Picture)
  UDF1.CEImage1.repaint()

  pngImage.destroy()
  tmpImage.destroy()

  UDF1.Caption = 'alpha is '..alpha
end

function UDF1_CETrackBar1Change(sender)
  demo(sender.Position)
end

demo(128)

_________________
Back to top
View user's profile Send private message MSN Messenger
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 203

PostPosted: Wed Dec 11, 2019 7:27 am    Post subject: Reply with quote

@mgr.inz.Player
@Dark Byte
Thank you very much for helping me solve all kinds of problems. I'm very happy. Although it only supports 64 bits for the time being, I think it's very good
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Wed Dec 11, 2019 8:18 am    Post subject: Reply with quote

.lua wrote:
@mgr.inz.Player
@Dark Byte


Then is possible using user32.clll function SetLayeredWindowAttributes() and SetWindowLongA() to make transparent object component such as TButton, TMemo etc?. Or use Win32 windows styles, especially WS_TRANSPARENT (or WS_EX_TRANSPARENT) ?

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 203

PostPosted: Wed Dec 11, 2019 9:51 am    Post subject: Reply with quote

This is exactly what I want, but I don't know if ce7.0 can call user32.clll quickly and simply. I also hope that edit and listbox can adjust the transparency depth
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