Terenz Posted July 17, 2013 Share Posted July 17, 2013 (edited) Hello, I need to do all of three in the same control Pic. I have found some example but they are all related to save an image "edited", but i don't need to do that but: . Rotate an image of 180° (Done, but i don't know how to set the Widht-Height?) . Add a trasparency to image like WinSetTrans . Add a vertical gradient, from trasparent color ( top ) to black ( bottom ) . Show all this in gui-memory only (GUICtrlCreatePic) without saving My code: #include <GUIConstantsEx.au3> #include <GDIPlus.au3> Global $iW = 500, $iH = 500, $hImage _GDIPlus_Startup() Global $hGUI = GUICreate("Image", $iW, $iH) _RotateImage("image.jpg", 0, 0, 25, 25) GUISetState() Do Sleep(100) Until GUIGetMsg() = -3 _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Exit Func _RotateImage($hImage, $left, $top, $width, $height) $hPicture = GUICtrlCreatePic("", $left, $top, $width, $height) GUICtrlSetState(-1, $GUI_DISABLE) $hImage = _GDIPlus_ImageLoadFromFile($hImage) DllCall($ghGDIPDll, "int", "GdipImageRotateFlip", "hwnd", $hImage, "long", 2) Local $hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _WinAPI_DeleteObject(GUICtrlSendMsg($hPicture, 0x0172, 0, $hBMP)) EndFunc ;==>_RotateImage Thanks Edited July 17, 2013 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
UEZ Posted July 17, 2013 Share Posted July 17, 2013 (edited) Add a vertical gradient, from trasparent color ( top ) to black ( bottom ) I don't understand what you mean? After setting the image transparence you want to add a vertical gradient to where? Background? Can you show an example how the image should look like? Br, UEZ PS: This is GDI+ and not GDI! Edited July 17, 2013 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
UEZ Posted July 17, 2013 Share Posted July 17, 2013 (edited) Is this what you are looking for?expandcollapse popup;coded by UEZ 2013-07-17 #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GDIPlus.au3> Opt("MustDeclareVars", 1) Global Const $STM_SETIMAGE = 0x0172, $tagGDIPCOLORMATRIX = "float m[25];", $IMAGE_BITMAP = 0 _GDIPlus_Startup() Global Const $sFile = "RedSquare.jpg" Global Const $hBitmap = _GDIPlus_BitmapCreateFromFile($sFile) Global Const $iW = _GDIPlus_ImageGetWidth($hBitmap) Global Const $iH = _GDIPlus_ImageGetHeight($hBitmap) Global Const $hGUI = GUICreate("Test", 400, 400, -1, -1, $WS_POPUP) GUISetBkColor(0xFFFF00) Global Const $iPic = GUICtrlCreatePic("", 50, 50, 300, 300) GUICtrlSetState(-1, $GUI_DISABLE) Global $hHBitmap = _GDIPlus_FlipTransparencyGradient($hBitmap, 300, 300, 0xFF) Global $hB = GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap) If $hB Then _WinAPI_DeleteObject($hB) GUISetState() Sleep(2000) $hB = GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, 0) ;delete the image (useful for transparent images) If $hB Then _WinAPI_DeleteObject($hB) _WinAPI_DeleteObject($hBitmap) $hHBitmap = _GDIPlus_FlipTransparencyGradient($hBitmap, 300, 300) Global $hB = GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap) If $hB Then _WinAPI_DeleteObject($hB) Do If GUIGetMsg() = $GUI_EVENT_CLOSE Then _WinAPI_DeleteObject($hHBitmap) _GDIPlus_BitmapDispose($hBitmap) GUIDelete() _GDIPlus_Shutdown() Exit EndIf Until False Func _GDIPlus_FlipTransparencyGradient($hBitmap, $iNewW, $iNewH, $iTrans = 0x60, $iRotateFlipType = 2, $iStartColor = 0x80FF0000, $iEndColor = 0x00000000, $bConvert2HBmp = True); coded by UEZ 2013 Local $hBmp = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iNewW, "int", $iNewH, "int", 0, "int", $GDIP_PXF32ARGB, "ptr", 0, "int*", 0) $hBmp = $hBmp[6] Local $hGfxContext = _GDIPlus_ImageGetGraphicsContext($hBmp) Local $hBrush = _GDIPlus_LineBrushCreate($iNewW / 2, 0, $iNewW / 2, $iNewH, $iStartColor, $iEndColor) _GDIPlus_GraphicsFillRect($hGfxContext, 0, 0, $iNewW, $iNewH, $hBrush) DllCall($ghGDIPDll, "uint", "GdipImageRotateFlip", "handle", $hBitmap, "int", $iRotateFlipType) Local $fTransparency = -1 + $iTrans / 256 Local $hAttribute_Alpha = _GDIPlus_ImageAttributesCreate() Local $tColorMatrix = _GDIPlus_ColorMatrixCreateTranslate(0, 0, 0, $fTransparency) Local $pColorMatrix = DllStructGetPtr($tColorMatrix) _GDIPlus_ImageAttributesSetColorMatrix($hAttribute_Alpha, 0, True, $pColorMatrix) _GDIPlus_GraphicsDrawImageRectRectIA($hGfxContext, $hBitmap, 0, 0, _GDIPlus_ImageGetWidth($hBitmap) , _GDIPlus_ImageGetHeight($hBitmap), 0, 0, $iNewW, $iNewH, $hAttribute_Alpha) _GDIPlus_ImageAttributesDispose($hAttribute_Alpha) _GDIPlus_GraphicsDispose($hGfxContext) If $bConvert2HBmp Then Local $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp) _GDIPlus_BitmapDispose($hBmp) Return $hHBmp EndIf Return $hBmp EndFunc Func _GDIPlus_ColorMatrixCreate() Return _GDIPlus_ColorMatrixCreateScale(1, 1, 1, 1) EndFunc ;==>_GDIPlus_ColorMatrixCreate Func _GDIPlus_ColorMatrixCreateScale($nRed, $nGreen, $nBlue, $nAlpha = 1) Local $tCM $tCM = DllStructCreate($tagGDIPCOLORMATRIX) DllStructSetData($tCM, "m", $nRed, 1) DllStructSetData($tCM, "m", $nGreen, 7) DllStructSetData($tCM, "m", $nBlue, 13) DllStructSetData($tCM, "m", $nAlpha, 19) DllStructSetData($tCM, "m", 1, 25) Return $tCM EndFunc ;==>_GDIPlus_ColorMatrixCreateScale Func _GDIPlus_ColorMatrixCreateTranslate($nRed, $nGreen, $nBlue, $nAlpha = 0) Local $iI, $tCM, $aFactors[4] = [$nRed, $nGreen, $nBlue, $nAlpha] $tCM = _GDIPlus_ColorMatrixCreate() For $iI = 0 To 3 DllStructSetData($tCM, "m", $aFactors[$iI], 21 + $iI) Next Return $tCM EndFunc ;==>_GDIPlus_ColorMatrixCreateTranslate Func _GDIPlus_GraphicsDrawImageRectRectIA($hGraphics, $hImage, $nSrcX, $nSrcY, $nSrcWidth, $nSrcHeight, $nDstX, $nDstY, $nDstWidth, $nDstHeight, $hImageAttributes = 0, $iUnit = 2) Local $aResult = DllCall($ghGDIPDll, "int", "GdipDrawImageRectRect", "handle", $hGraphics, "handle", $hImage, "float", $nDstX, "float", $nDstY, "float", $nDstWidth, "float", $nDstHeight, "float", $nSrcX, "float", $nSrcY, "float", $nSrcWidth, "float", $nSrcHeight, "int", $iUnit, "handle", $hImageAttributes, "int", 0, "int", 0) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] = 0 EndFunc ;==>_GDIPlus_GraphicsDrawImageRectRectIA Func _GDIPlus_ImageAttributesCreate() Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateImageAttributes", "int*", 0) If @error Then Return SetError(@error, @extended, 0) Return $aResult[1] EndFunc ;==>_GDIPlus_ImageAttributesCreate Func _GDIPlus_ImageAttributesDispose($hImageAttributes) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDisposeImageAttributes", "handle", $hImageAttributes) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] = 0 EndFunc ;==>_GDIPlus_ImageAttributesDispose Func _GDIPlus_ImageAttributesSetColorMatrix($hImageAttributes, $iColorAdjustType = 0, $fEnable = False, $pClrMatrix = 0, $pGrayMatrix = 0, $iColorMatrixFlags = 0) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetImageAttributesColorMatrix", "handle", $hImageAttributes, "int", $iColorAdjustType, "int", $fEnable, "ptr", $pClrMatrix, "ptr", $pGrayMatrix, "int", $iColorMatrixFlags) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] = 0 EndFunc ;==>_GDIPlus_ImageAttributesSetColorMatrix Func _GDIPlus_LineBrushCreate($nX1, $nY1, $nX2, $nY2, $iARGBClr1, $iARGBClr2, $iWrapMode = 0) Local $tPointF1, $pPointF1 Local $tPointF2, $pPointF2 Local $aResult $tPointF1 = DllStructCreate("float;float") $pPointF1 = DllStructGetPtr($tPointF1) $tPointF2 = DllStructCreate("float;float") $pPointF2 = DllStructGetPtr($tPointF2) DllStructSetData($tPointF1, 1, $nX1) DllStructSetData($tPointF1, 2, $nY1) DllStructSetData($tPointF2, 1, $nX2) DllStructSetData($tPointF2, 2, $nY2) $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateLineBrush", "ptr", $pPointF1, "ptr", $pPointF2, "uint", $iARGBClr1, "uint", $iARGBClr2, "int", $iWrapMode, "int*", 0) If @error Then Return SetError(@error, @extended, 0) Return $aResult[6] EndFunc ;==>_GDIPlus_LineBrushCreateTo do: error handling. Br,UEZ Edited July 19, 2013 by UEZ FireFox 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Terenz Posted July 17, 2013 Author Share Posted July 17, 2013 (edited) Ave UEZ, guru of GDI+ Yes the gradient is on the image, but in this direction: And another thing, as i have say before, i don't have understand how to set the size W-H of the GUICtrlCreatePic / image ( this not work --> Global Const $iPic = GUICtrlCreatePic("", 0, 0, 25, 25) ), i need to set more than one image. My last two question: . For the background color or bk image of the GUI i need to use GDI+ or simply GUISetBkColor / GUICtrlCreatePic disabled? . If i want to "replace" one of the existing image after i have load it, i need to call again _GDIPlus_FlipTransparencyGradient($hBitmap) with another $hBitmap? Thanks again Edited July 17, 2013 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
UEZ Posted July 17, 2013 Share Posted July 17, 2013 (edited) I updated the code from post #3. All questions answered?You said vertical gradient but your screenshot shows a horizontal gradient. Br,UEZ Edited July 17, 2013 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Terenz Posted July 18, 2013 Author Share Posted July 18, 2013 (edited) UEZ, sorry for this late answer, less then perfect There are some problem with Const in the script ( $hHBitmap previusly declaread as a Const ), but isn't a problem I have notice now that gradient is from white to black ( from top to bottom ) but i'd like to have from trasparent/no color to black, so not add a color in top but only the black at down ( i hope i was clear ) I know GDI+ uses ARGB, so with alfa channel but after a research i don't have found nothing about a real trasparent color. If is not possible is the same, i'll use your actually version Edited July 18, 2013 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
UEZ Posted July 18, 2013 Share Posted July 18, 2013 (edited) I forgot to delete the line just above.Try $iStartColor = 0xFF000000 and $iEndColor = 0x00000000Br,UEZ Edited July 18, 2013 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Terenz Posted July 18, 2013 Author Share Posted July 18, 2013 If i use 0xFF00000 i can't see the image Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
UEZ Posted July 18, 2013 Share Posted July 18, 2013 Show me your image.Br,UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Terenz Posted July 18, 2013 Author Share Posted July 18, 2013 (edited) I have made an red square in paint, jpg format, for see the effect of the script on a image: This is the effect with your script above ( $iStartColor = 0xFFB0B0B0, $iEndColor = 0xFF000000 ) I don't like that white on top, if possible i prefer a trasparent color ( no, i can't make it red ) This is with $iStartColor = 0xFF000000, $iEndColor = 0x00000000 Pratically i can't see the image, everything is the same except $iStartColor and $iEndColor Edited July 18, 2013 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
UEZ Posted July 18, 2013 Share Posted July 18, 2013 It works for me. I made the background white and you can see now how the alpha channel looks like:What os do you use?Br,UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Terenz Posted July 18, 2013 Author Share Posted July 18, 2013 Now i'm on Xp, later i'll test on 7 Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
Terenz Posted July 18, 2013 Author Share Posted July 18, 2013 (edited) Now i'm on Xp, later i'll test on 7 Done, same problem with $iStartColor = 0xFF000000 and $iEndColor = 0x00000000, so it's not a OS issue. I'm using the lastest stable v3.3.8.1 EDIT: I'd like to make something like this image, make it just for test with paint, starting from the "red box image" uploaded above: '> I have make a different bg and the trasparency off-on just for check the gradient effect, the gradient has only one color ( black ) and not two ( black-white ) Edited July 18, 2013 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
UEZ Posted July 18, 2013 Share Posted July 18, 2013 (edited) I modified the code above using your red square and the result looks like this here:Br,UEZ Edited July 18, 2013 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Terenz Posted July 19, 2013 Author Share Posted July 19, 2013 (edited) Undestood, we always need two color. UEZ, can you re-add the part of the code for change the image of the control after i have created it? Then i can considered this thread solved. Thanks Edited July 19, 2013 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
UEZ Posted July 19, 2013 Share Posted July 19, 2013 Done.Br,UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now