Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

( solved )applying transparency to images using gdip matrix


  • Please log in to reply
1 reply to this topic
closed
  • Members
  • 509 posts
  • Last active: Jan 14 2012 06:14 PM
  • Joined: 07 Feb 2008
To use images as background in a layered window i need to make them into transparent png so i change the ARGB value A=255 into A=180 but it takes several seconds with cpu close to 100%.

Is there another way of doing it?


Used this code for testing.

#SingleInstance, Force
#NoEnv
SetBatchLines, -1

fileselectfile,file1
gui,add,text,w200 h30 vmytext
Gui, Add, Progress, w300 h20 cBlue vMyProgress
gui,add,picture, h200 w-1 vmyimage,%file1%
Gui, show,,progress
settimer,alert,20
gosub start
return

alert:
GuiControl,, MyProgress, % x*100/h
return
 
start:
QPX( True )
If !pToken := Gdip_Startup()
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}


pBitmap := Gdip_CreateBitmapFromFile(File1)
w := Gdip_GetImageWidth(pBitmap), h := Gdip_GetImageHeight(pBitmap)


Gdip_LockBits(pBitmap, 0, 0, w, h, Stride, Scan0, BitmapData)
y := 0
Loop, %h%
{
   x++
   Loop, %w%
   {
      color := Gdip_GetLockBitPixel(Scan0, A_Index-1, y, Stride)
      Gdip_FromARGB(color,  A, R, G,  B)
      newcolor:=Gdip_ToARGB(180, R, G, B)
      Gdip_SetLockBitPixel(newcolor, Scan0, A_Index-1, y, Stride)
      }

   y++
}
Gdip_UnlockBits(pBitmap, BitmapData)
Gdip_SaveBitmapToFile(pBitmap, "FinalImage.png")
Gdip_DisposeImage(pBitmap)
Gdip_DeleteGraphics(G)
Gdip_Shutdown(pToken)
Ti :=  QPX( False )
GuiControl,, myimage,  *h200 *w-1 finalimage.png 

controlsettext,static1,time needed=%Ti% ,progress

Gui, Show, AutoSize Center
Return

QPX( N=0 ) {       ;  Wrapper for  QueryPerformanceCounter()by SKAN  | CD: 06/Dec/2009
 Static F,A,Q,P,X  ;  www.autohotkey.com/forum/viewtopic.php?t=52083 | LM: 10/Dec/2009
 If ( N && !P )
    Return  DllCall("QueryPerformanceFrequency",Int64P,F) + (X:=A:=0)
          + DllCall("QueryPerformanceCounter",Int64P,P)
 DllCall("QueryPerformanceCounter",Int64P,Q), A:=A+Q-P, P:=Q, X:=X+1
Return ( N && X=N ) ? (X:=X-1)<<64 : ( N=0 && (R:=A/X/F) ) ? ( R + (A:=P:=X:=0) ) : 1
}


guiclose:
esc::
exitapp

Update : Using Tic's esplanation of construction of the matrix in drawimage i solved my question :)

<!-- m -->http://www.autohotke...ic63741-15.html<!-- m -->

To change into transparent value 180 :

Matrix =
(
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 0.7 0
0 0 0 0 1
)

tic
  • Members
  • 1934 posts
  • Last active: May 30 2018 08:13 PM
  • Joined: 22 Apr 2007
Hi Thanh00....I gave the option that you can specify just the number 0.7 as the matrix which will change just the transparency as it is such a common requirement