Terenz Posted May 25, 2015 Share Posted May 25, 2015 (edited) I want to create circle in GDI and yes in theory i can use PNG with an alfa channel but just for know if possible to load a circular jpg-bmp without edit-re save it?This is what i'm using now, stripped_GDIPlus_Startup() $hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\Test.png") $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 100, 100, 100, 100) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown()The circle in theory will be bound the square of the image. Thanks for any help Edited May 25, 2015 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 May 25, 2015 Share Posted May 25, 2015 I want to create circle in GDI and yes in theory i can use PNG with an alfa channel but just for know if possible to load a circular jpg-bmp without edit-re save it?I don't understand what you mean exactly. Can you describe it with an example please?Thx. 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 May 25, 2015 Author Share Posted May 25, 2015 (edited) Sure. With _GDIPlus_GraphicsDrawImageRect i can take whatever image in whatever size and load it in a rectangle of a size of my choice, also if not corrisponding to original size, like this:Now, instead to draw in a rectangle, i'd like to use the same parameter of the above function ( example resize the original image to a square of 300 w and 300 h ) but draw it a circle ( circle inscribed in a square/rectangle formula ), in this way:I have think to use something like load image as graphic handle ( _GDIPlus_BitmapCreateFromFile+GDIPlus_ImageGetGraphicsContext ) and the use _GDIPlus_GraphicsFillEllipse. My attempts have failed but probably is my fault. I don't want to edit the original image or save it later on the disk, only display in the GUI. Thanks UEZ Edited May 25, 2015 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 May 25, 2015 Share Posted May 25, 2015 load the imagecreate a texture brush object from the bitmap -> _GDIPlus_TextureCreatedraw a filled ellipse using the texture as the brush 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 May 25, 2015 Author Share Posted May 25, 2015 (edited) I have already tried that method, works, but the problem is it can't load the entire image but only a portion of it, instead of DrawImageRect can load everything in a fixed size whatever the size of the image isEDIT: Is a cool effect but not what i want #include <GDIPlus.au3> #include <GUIConstantsEx.au3> _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Test.jpg") ;create an image object based on a file Local $hGUI = GUICreate("GDI+ Example", 320, 320) GUISetState(@SW_SHOW) Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a Graphics object from a window handle _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2) ; $GDIP_SMOOTHINGMODE_HIGHQUALITY ;sets the graphics object rendering quality (antialiasing) Local $hTexture = _GDIPlus_TextureCreate($hImage) Do _GDIPlus_GraphicsFillEllipse($hGraphics, Random(1, 200), Random(1, 200), Random(1, 200), Random(1, 200), $hTexture) ;draw ellipse with texture as a brush Sleep(200) Until GUIGetMsg() = $GUI_EVENT_CLOSE ;cleanup resources _GDIPlus_BrushDispose($hTexture) _GDIPlus_ImageDispose($hImage) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() GUIDelete($hGUI) ; 3.3.8.1 Func _GDIPlus_TextureCreate($hImage, $iWrapMode = 0) Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateTexture", "handle", $hImage, "int", $iWrapMode, "handle*", 0) If @error Then Return SetError(@error, @extended, 0) If $aResult[0] Then Return SetError(10, $aResult[0], 0) Return $aResult[3] EndFunc ;==>_GDIPlus_TextureCreateSee also this:http://stackoverflow.com/questions/26845921/draw-image-into-shape Edited May 25, 2015 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...
Terenz Posted May 25, 2015 Author Share Posted May 25, 2015 (edited) UEZ,After many many ( many ) hours of research from the post of stackoverflow i have found the solution:_GDIPlus_GraphicsSetClipPathThat, in combination with PathCreate+PathAddEllipse+GraphicsDrawImage, create an image like that one of my post. There is a sort of example in the help so is useless to post "mine" because is just a copy-paste of that. Many thanks for your help ( and point me on the wrong way lol ) but from that way i have found the solution! Edited May 25, 2015 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 May 25, 2015 Share Posted May 25, 2015 (edited) I did this meanwhile:expandcollapse popup#include <GDIPlus.au3> #include <GUIConstantsEx.au3> _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Test.jpg") ;create an image object based on a file Local $hGUI = GUICreate("GDI+ Example", 320, 320) GUISetState(@SW_SHOW) Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a Graphics object from a window handle _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2) ; $GDIP_SMOOTHINGMODE_HIGHQUALITY ;sets the graphics object rendering quality (antialiasing) Local $hBitmap = _GDIPlus_BitmapCreateEllipseFilled($hImage) Do _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, Random(1, 200), Random(1, 200), Random(1, 200), Random(1, 200)) ;draw ellipse with texture as a brush Sleep(200) Until GUIGetMsg() = $GUI_EVENT_CLOSE ;cleanup resources _GDIPlus_ImageDispose($hImage) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() GUIDelete($hGUI) Func _GDIPlus_BitmapCreateEllipseFilled($hBitmap, $iW = -1, $iH = -1, $iWrapMode = 0) If $iW = -1 Or $iH = -1 Then $iW = _GDIPlus_ImageGetWidth($hBitmap) $iH = _GDIPlus_ImageGetHeight($hBitmap) EndIf Local Const $hBmp = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBmp) Local Const $hTexture = _GDIPlus_TextureCreate($hBitmap, $iWrapMode) _GDIPlus_GraphicsSetInterpolationMode($hCtxt, 7) _GDIPlus_GraphicsSetCompositingQuality($hCtxt, 2) _GDIPlus_GraphicsFillEllipse($hCtxt, 0, 0, $iW, $iH, $hTexture) _GDIPlus_BrushDispose($hTexture) _GDIPlus_GraphicsDispose($hCtxt) Return $hBmp EndFunc Edited May 25, 2015 by UEZ forgot _GDIPlus_BitmapDispose($hBitmap) Terenz 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 May 25, 2015 Author Share Posted May 25, 2015 Nice 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 May 25, 2015 Share Posted May 25, 2015 Is this what you was looking for? 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 May 25, 2015 Author Share Posted May 25, 2015 With GraphicsSetClipPath i have resolved but that script can be useful so go directly in my snippet folder Nothing is so strong as gentleness. Nothing is so gentle as real strength 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