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 and bitmap transparency issues

 
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: Mon Oct 27, 2025 4:30 am    Post subject: Image and bitmap transparency issues Reply with quote

1.As shown in the figure, due to some unknown reason, the image is not a transparent background.
2.Download the CT example below and remove the suffix .lua
2.I hope you can help me solve the transparency issue



image.jpg
 Description:
 Filesize:  4.1 KB
 Viewed:  112 Time(s)

image.jpg



SaveImage.CT.lua
 Description:

Download
 Filename:  SaveImage.CT.lua
 Filesize:  151.5 KB
 Downloaded:  15 Time(s)

Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1527

PostPosted: Tue Oct 28, 2025 7:02 am    Post subject: Reply with quote

I haven't tried the code with an icon.

I assume you can also use the icon in a "png" format.

Here's a clean code that works:

Code:
function drawTextOnImage(imageSource, imageControl, text, x, y, fontColor, showText)
  -- Load image source
  local pic = type(imageSource) == "userdata" and imageSource or createPicture()
  if type(imageSource) ~= "userdata" then
    pic.loadFromStream(findTableFile(imageSource).stream)
  end

  local originalBmp = pic.getBitmap()
  local w, h = originalBmp.Width, originalBmp.Height

  -- Create new bitmap
  local srcbmp = createBitmap(w, h)
  srcbmp.TransparentColor = 0x000000
  srcbmp.Transparent = true

  -- Copy original image into new bitmap
  srcbmp.Canvas.copyRect(0, 0, w, h, originalBmp.Canvas, 0, 0, w, h)

  -- Optionally draw text
  if showText then
    srcbmp.Canvas.Brush.Style = 1 -- bsSolid
    srcbmp.Canvas.Font.Color = fontColor or 0x0000FF
    srcbmp.Canvas.Font.Size = 12
    srcbmp.Canvas.Font.Style = fsBold
    srcbmp.Canvas.Font.Quality = 'fqCleartype'
    srcbmp.Canvas.TextOut(x or 10, y or 10, text or "✔")

    -- Debug pixel color (optional)
    -- local px = srcbmp.Canvas.getPixel(x or 10, y or 10)
    -- print(string.format("Pixel color at (%d,%d): 0x%X", x or 10, y or 10, px))
  end

  -- Apply bitmap to image control
  imageControl.Picture = srcbmp
  imageControl.TransparentColor = 0x000000
  imageControl.Transparent = true

  -- Cleanup
  pic.Destroy()
  srcbmp.Destroy()
end

-- Create form
if mf2 then mf2.Destroy() mf2=nil end
mf2 = createForm()
mf2.Caption = "test"

-- Create image control
saveImg = createImage(mf2)
saveImg.SetPosition(100, 50)
saveImg.Stretch = true

-- Create button
btn1 = createButton(mf2)
btn1.SetPosition(90, 150)
btn1.Width = saveImg.Width + 20
btn1.Caption = "Replace Tick: ✔"

-- Text rendering functions
imageText = function(s) drawTextOnImage("tt.png", saveImg, s, 12, 12, 0x0000FF, true) end
imageTextClear = function() drawTextOnImage("tt.png", saveImg, nil, nil, nil, false) end

-- Tick symbol table
tckTbl = { "✔", "✖", "" }

-- Initial tick
imageText("✔")
local tck = 1

-- Button click logic
btn1.OnClick = function()
  tck = tonumber(tck) + 1
  if tckTbl[tck] ~= "" then
    imageText(tckTbl[tck])
  else
    imageTextClear()
    tck = 0
  end

  local s = (tck == 0) and tckTbl[#tckTbl] or tckTbl[tck]
  btn1.Caption = "Replace Tick: " .. s
end



Ekran Alıntısı.PNG
 Description:
 Filesize:  38.51 KB
 Viewed:  60 Time(s)

Ekran Alıntısı.PNG



_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
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