How can i show images without background of GUI? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
LoveGaruda
Posts: 6
Joined: 07 Aug 2019, 03:48

How can i show images without background of GUI?

07 Aug 2019, 04:19

Used this image:
Asus ROG logo.png
Asus ROG logo.png (69.21 KiB) Viewed 2169 times
I just wanted to show up ROG Logo on my screen. And i tried to do that with the code follows down here...

Code: Select all

#SingleInstance, Force
#NoEnv
#KeyHistory, 0
ListLines, Off
Process, Priority,, High
SetDefaultMouseSpeed, 0
SetControlDelay, -1
SetBatchLines, -1
SetMouseDelay, -1
SetKeyDelay, -1
SetWinDelay, -1
PW = 650
PH = 367
WX := A_ScreenWidth - PW
WY := (A_ScreenHeight - (A_ScreenHeight / 27)) - PH + 1
Gui, Color, E8E8E8
Gui, Add, Picture, x0 y0 w%PW% h%PH% vEWDA, Asus ROG logo.png
Gui, Show, x%WX% y%WY% w%PW% h%PH%, ROG Logo
Gui, -Caption +LastFound +AlwaysOnTop
WinSet, TransColor, E8E8E8
Gui, +E0x20
return
F10::
ExitApp
But there was some problems with transcolor... transcolor deleted only color E8E8E8. Like this image
no.png
no.png (827.94 KiB) Viewed 2169 times
There lefts some pixels on white background(and i want to make them med-transparent or something looks like..?).
I think.. 'maybe the anti-aliasing pixels are the problem?'.. so i tested!

https :// ibb.co/ FDdHyJ4

I copied layers and make them(anti-aliased pixels) to not anti-aliased pixels, and the result:
Yee.png
Yee.png (58.34 KiB) Viewed 2169 times
And well.. the quality of the first image was better obviously...

So there's the question, How can i show images without background of GUI?(Also with anti-aliased pixels(med-transparent pixels))
red_sun
Posts: 19
Joined: 12 Jul 2019, 05:22

Re: How can i show images without background of GUI?  Topic is solved

07 Aug 2019, 05:45

There is a function that you can use inside dropandcreate , but it needs the gdip library .

https://www.autohotkey.com/boards/viewtopic.php?t=31432
Here is a simplified extract of noname 's code just showing a selected file attached file image.ahk , the library is included .
Attachments
image.ahk
(130.19 KiB) Downloaded 106 times
LoveGaruda
Posts: 6
Joined: 07 Aug 2019, 03:48

Re: How can i show images without background of GUI?

07 Aug 2019, 08:41

And how can i update the image without making new GUI?
I'm so sorry for more question.. :/
Cory Cooper
Posts: 11
Joined: 01 Aug 2019, 07:38
Contact:

Re: How can i show images without background of GUI?

07 Aug 2019, 09:21

You can't.

But you can fake it. You can make an invisible gui without a titlebar with just the picture in it and presto, floating image.
https://autohotkey.com/board/topic/61388-transparent-gui/
https://autohotkey.com/board/topic/80720-solved-gui-opacity/

This will make a transparent gui with nothing in it:

Code: Select all

WinGet, selectedwindow,, A
Gui, B:-Border
Gui, B:Color, 808080
Gui, B:Show, x500 y500 w500 h500, GuiName
WinSet, Style, -0xC00000, GuiName
WinSet, TransColor, 808080, GuiName
red_sun
Posts: 19
Joined: 12 Jul 2019, 05:22

Re: How can i show images without background of GUI?

07 Aug 2019, 10:41

This code is not the best way of changing images but you can do it if the first image is the biggest one . If you want all kind of dimensions with the same Gui you have to use another concept or destroying the image and reloading the code.

Here is an example to change to another smaller or same size image using hotkey F4
Attachments
image_2.ahk
(130.49 KiB) Downloaded 73 times
iseahound
Posts: 1445
Joined: 13 Aug 2016, 21:04
Contact:

Re: How can i show images without background of GUI?

07 Aug 2019, 13:33

I built a library to handle these issues

https://www.autohotkey.com/boards/viewtopic.php?f=83&t=66774

There’s a short code example on the first post you can use.
teadrinker
Posts: 4330
Joined: 29 Mar 2015, 09:41
Contact:

Re: How can i show images without background of GUI?

07 Aug 2019, 22:05

Just another fun example:

Code: Select all

SetBatchLines, -1
filePath := A_ScriptDir . "\Asus ROG logo.png"
if !FileExist(filePath)
   URLDownloadToFile, https://www.autohotkey.com/boards/download/file.php?id=7738&sid=0f8912e745b2ee776d94be4553372ad7, % filePath

view := new ImageViewer
x := w := 0
y := A_ScreenHeight/2.2
Loop {
   i := A_Index
   view.Show(filePath, x += A_Index, y, w += i**1.3, -1)
   Sleep, 10
} until w > 800

Sleep 1200

WinGetPos, x, y, w, h, % "ahk_id" view.hwnd
Loop 30 {
   view.Show(filePath, x + mod(A_Index, 2)*2, y + mod(A_Index, 2)*2, w, h)
   Sleep, 50
}
Loop {
   view.Show(filePath, x += A_Index**2.5, y -= A_Index*4, w -= (i - A_Index)**1.4, -1)
   Sleep, 30
} until w < 2 || i - A_Index < 2

view := ""
ExitApp

class ImageViewer
{
   __New() {
      static exStyles := "E" . (WS_EX_LAYERED := 0x80000) | (WS_EX_TRANSPARENT := 0x20)
      Gui, New, -Caption +%exStyles% +LastFound +AlwaysOnTop +ToolWindow +hwndhGui -DPIScale
      Gui, Show, NA
      this.hwnd := hGui
   }
   
   __Delete() {
      Gui, % this.hwnd . ": Destroy"
   }
   
   Show(imageFilePath, x := "", y := "", w := "", h := "") {
      oGDIP := new GDIp
      if !pBitmap := oGDIP.BitmapFromFile(imageFilePath) {
         oGDIP := ""
         throw Exception("Failed to get bitmap from file")
      }
      oGDIP.GetImageDimensions(pBitmap, width, height)
    , ( w = -1 && w := width * h / height )
    , ( h = -1 && h := height * w / width )
    , ( w = "" && w := width)
    , ( h = "" && h := height )
    , ( x = "" && x := (A_ScreenWidth - w)//2 )
    , ( y = "" && y := (A_ScreenHeight - h)//2 )
    , oCDC := new this.CompatibleDC(0, w, h)
    , hDC := oCDC.hCDC
    , G := oGDIP.GraphicsFromHDC(hDC)
    , oGDIP.SetSmoothingMode(G, 4)
    , oGDIP.DrawImage(G, pBitmap, 0, 0, w, h, 0, 0, width, height)
    , oGDIP.UpdateLayeredWindow(this.hwnd, hDC, x, y, w, h)
    , oCDC := ""
    , oGDIP.DeleteGraphics(G)
    , oGDIP.DisposeImage(pBitmap)
   }
   
   class CompatibleDC
   {
      __New(hDC, w, h)  {
         this.hCDC := DllCall("CreateCompatibleDC", Ptr, hDC, Ptr)
       , this.hBM := this.CreateDibSection(w, h, this.hCDC)
       , this.oBM := DllCall("SelectObject", Ptr, this.hCDC, Ptr, this.hBM, Ptr)
      }
      
      __Delete()  {
         DllCall("SelectObject", Ptr, this.hCDC, Ptr, this.oBM, Ptr)
       , DllCall("DeleteDC", Ptr, this.hCDC)
       , DllCall("DeleteObject", Ptr, this.hBM)
      }
      
      CreateDibSection(w, h, hdc, bpp := 32, ByRef ppvBits := 0) {
         VarSetCapacity(bi, 40, 0)
       , NumPut(w, bi, 4, "UInt")
       , NumPut(h, bi, 8, "UInt")
       , NumPut(40, bi, 0, "UInt")
       , NumPut(1, bi, 12, "ushort")
       , NumPut(0, bi, 16, "uInt")
       , NumPut(bpp, bi, 14, "ushort")
         Return hbm := DllCall("CreateDIBSection", Ptr, hdc, Ptr, &bi, UInt, 0, PtrP, ppvBits, Ptr, 0, UInt, 0, Ptr)
      }
   }
}

class GDIp   {
   __New() {
      if !DllCall("GetModuleHandle", Str, "gdiplus", Ptr)
         DllCall("LoadLibrary", Str, "gdiplus")
      VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
    , DllCall("gdiplus\GdiplusStartup", UPtrP, pToken, Ptr, &si, Ptr, 0)
    , this.token := pToken
   }
   
   __Delete()  {
      DllCall("gdiplus\GdiplusShutdown", Ptr, this.token)
      if hModule := DllCall("GetModuleHandle", Str, "gdiplus", Ptr)
         DllCall("FreeLibrary", Ptr, hModule)
   }
   
   BitmapFromFile(sFile)  {
      DllCall("gdiplus\GdipCreateBitmapFromFile", WStr, sFile, PtrP, pBitmap)
      Return pBitmap
   }
   
   GraphicsFromHDC(hdc)  {
      DllCall("gdiplus\GdipCreateFromHDC", Ptr, hdc, PtrP, pGraphics)
      return pGraphics
   }
   
   SetSmoothingMode(pGraphics, SmoothingMode)  {
      return DllCall("gdiplus\GdipSetSmoothingMode", Ptr, pGraphics, Int, SmoothingMode)
   }
   
   DrawImage(pGraphics, pBitmap, dx, dy, dw, dh, sx, sy, sw, sh)  {
      DllCall("gdiplus\GdipDrawImageRectRect", Ptr, pGraphics, Ptr, pBitmap
                                             , Float, dx, Float, dy, Float, dw, Float, dh
                                             , Float, sx, Float, sy, Float, sw, Float, sh
                                             , Int, 2, Ptr, 0, Ptr, 0, Ptr, 0)
   }
   
   GetImageDimensions(pBitmap, ByRef Width, ByRef Height)  {
      DllCall("gdiplus\GdipGetImageWidth", Ptr, pBitmap, UIntP, Width)
    , DllCall("gdiplus\GdipGetImageHeight", Ptr, pBitmap, UIntP, Height)
   }
   
   UpdateLayeredWindow(hwnd, hdc, x, y, w, h, Alpha := 255) {
      VarSetCapacity(pt, 8)
    , NumPut(x, pt, 0, "UInt")
    , NumPut(y, pt, 4, "UInt")
      return DllCall("UpdateLayeredWindow", Ptr, hwnd, Ptr, 0, Ptr, &pt, Int64P, w|h<<32
                                          , Ptr, hdc, Int64P, 0, UInt, 0, UIntP, Alpha<<16|1<<24, UInt, 2)
   }
   
   DisposeImage(pBitmap)  {
      return DllCall("gdiplus\GdipDisposeImage", Ptr, pBitmap)
   }
   
   DeleteGraphics(pGraphics)  {
      return DllCall("gdiplus\GdipDeleteGraphics", Ptr, pGraphics)
   }
}
External libraries are not required.
LoveGaruda
Posts: 6
Joined: 07 Aug 2019, 03:48

Re: How can i show images without background of GUI?

07 Aug 2019, 23:40

This is really funny XD Thanks for that mate!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, inseption86, jaka1 and 437 guests