Jump to content
Sign in to follow this  
toonboon

Save Graphic to file without print screen?

Recommended Posts

toonboon

Hi,

Basically the code I have here is the same as monoceres' answer in this topic:

http://www.autoitscript.com/forum/index.php?showtopic=85258

So the following would do.

#include <GDIPlus.au3>

Opt("GuiOnEventMode", 1)
$hwnd = GUICreate("Test", 300, 300)
GUISetState()
GUISetOnEvent(-3, "close")
_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
$bitmap = _GDIPlus_BitmapCreateFromGraphics(300, 300, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
$pen = _GDIPlus_PenCreate(0xFF00FF00, 2)

InetGet("http://msp5.photobucket.com/albums/y196/dannydude182/smiley-300x300.png",@ScriptDir&"\smiley.png")

$image=_GDIPlus_ImageLoadFromFile(@ScriptDir&"\smiley.png")

$matrix = _GDIPlus_MatrixCreate()

_GDIPlus_MatrixTranslate($matrix, 150, 150)



$inc = 0
Do
    _GDIPlus_GraphicsClear($backbuffer)
    
    _GDIPlus_MatrixRotate($matrix,1)
    _GDIPlus_GraphicsSetTransform($backbuffer,$matrix)
    
    _GDIPlus_GraphicsDrawImageRect($backbuffer,$image,-150,-150,300,300)
    
    
    _GDIPlus_GraphicsDrawImageRect($graphics,$bitmap,0,0,300,300)
    Sleep(10)
Until 0


Func close()
    Exit
EndFunc ;==>close


Func _GDIPlus_MatrixTranslate($hMatrix, $nOffsetX, $nOffsetY, $fOrder = True)
    $aResult = DllCall($ghGDIPDll, "int", "GdipTranslateMatrix", "ptr", $hMatrix, "float", $nOffsetX, "float", $nOffsetY, "int", $fOrder)
    If @error Then Return SetError(@error, @extended, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc ;==>_GDIPlus_MatrixTranslate

What I need to do is find a way to save this 300x300 image the graphic shows to a file, bmp preferredly, so that I can use it for further processing.

I have tried a lot of things but it either crashed or just completely messed up (showed a black 300x300 image when I opened the saved file.)

If anyone could help me out, I'd really appreciate it.


[right]~What can I say, I'm a Simplistic person[/right]

Share this post


Link to post
Share on other sites
trancexx

I do not comprehend the question no meter how hard I try :P

Could you explain once again what exactly you want to do?


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
Malkey

Hi,

Basically the code I have here is the same as monoceres' answer in this topic:

http://www.autoitscript.com/forum/index.php?showtopic=85258

So the following would do.

#include <GDIPlus.au3>
   
   Opt("GuiOnEventMode", 1)
   $hwnd = GUICreate("Test", 300, 300)
   GUISetState()
   GUISetOnEvent(-3, "close")
   _GDIPlus_Startup()
   $graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
   $bitmap = _GDIPlus_BitmapCreateFromGraphics(300, 300, $graphics)
   $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
   $pen = _GDIPlus_PenCreate(0xFF00FF00, 2)
   
   InetGet("http://msp5.photobucket.com/albums/y196/dannydude182/smiley-300x300.png",@ScriptDir&"\smiley.png")
   
   $image=_GDIPlus_ImageLoadFromFile(@ScriptDir&"\smiley.png")
   
   $matrix = _GDIPlus_MatrixCreate()
   
   _GDIPlus_MatrixTranslate($matrix, 150, 150)
   
   
   
   $inc = 0
   Do
       _GDIPlus_GraphicsClear($backbuffer)
       
       _GDIPlus_MatrixRotate($matrix,1)
       _GDIPlus_GraphicsSetTransform($backbuffer,$matrix)
       
       _GDIPlus_GraphicsDrawImageRect($backbuffer,$image,-150,-150,300,300)
       
       
       _GDIPlus_GraphicsDrawImageRect($graphics,$bitmap,0,0,300,300)
       Sleep(10)
   Until 0
   
   
   Func close()
       Exit
   EndFunc;==>close
   
   
   Func _GDIPlus_MatrixTranslate($hMatrix, $nOffsetX, $nOffsetY, $fOrder = True)
       $aResult = DllCall($ghGDIPDll, "int", "GdipTranslateMatrix", "ptr", $hMatrix, "float", $nOffsetX, "float", $nOffsetY, "int", $fOrder)
       If @error Then Return SetError(@error, @extended, False)
       Return SetError($aResult[0], 0, $aResult[0] = 0)
   EndFunc;==>_GDIPlus_MatrixTranslate

What I need to do is find a way to save this 300x300 image the graphic shows to a file, bmp preferredly, so that I can use it for further processing.

I have tried a lot of things but it either crashed or just completely messed up (showed a black 300x300 image when I opened the saved file.)

If anyone could help me out, I'd really appreciate it.

Using a hot key "Shift-Alt-s", this script save the image that is on the GUI when the hot key is pressed.

#include <GDIPlus.au3>
 
 Opt("GuiOnEventMode", 1)
 
 HotKeySet("+!s", "Save");Shift-Alt-s  Save image.
 
 $hwnd = GUICreate("Test", 300, 300)
 GUISetState()
 GUISetOnEvent(-3, "close")
 
 _GDIPlus_Startup()
 $graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
 $bitmap = _GDIPlus_BitmapCreateFromGraphics(300, 300, $graphics)
 $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
 $pen = _GDIPlus_PenCreate(0xFF00FF00, 2)
 
 InetGet("http://msp5.photobucket.com/albums/y196/dannydude182/smiley-300x300.png", @ScriptDir & "\smiley.png")
 
 $image = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\smiley.png")
 
 $matrix = _GDIPlus_MatrixCreate()
 _GDIPlus_MatrixTranslate($matrix, 150, 150)
 
 Do
     _GDIPlus_GraphicsClear($backbuffer)
     _GDIPlus_MatrixRotate($matrix, 1)
     _GDIPlus_GraphicsSetTransform($backbuffer, $matrix)
     _GDIPlus_GraphicsDrawImageRect($backbuffer, $image, -150, -150, 300, 300)
     _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, 300, 300)
     Sleep(10)
 Until 0
 
 Func close()
     _WinAPI_DeleteObject($bitmap)
     _GDIPlus_ImageDispose($image)
     _GDIPlus_GraphicsDispose($graphics)
     _GDIPlus_GraphicsDispose($backbuffer)
     _GDIPlus_Shutdown()
     Exit
 EndFunc  ;==>close
 
 Func Save()
     _GDIPlus_ImageSaveToFile($bitmap, @DesktopDir & "\TestWrite1.bmp")
     ShellExecute(@DesktopDir & "\TestWrite1.bmp")
 EndFunc  ;==>Save
 
;underscore _GDIPlus_MatrixTranslate is in GDIPlus.au3 include file. This function not needed.
 Func GDIPlus_MatrixTranslate($hMatrix, $nOffsetX, $nOffsetY, $fOrder = True)
     $aResult = DllCall($ghGDIPDll, "int", "GdipTranslateMatrix", "ptr", $hMatrix, "float", $nOffsetX, "float", $nOffsetY, "int", $fOrder)
     If @error Then Return SetError(@error, @extended, False)
     Return SetError($aResult[0], 0, $aResult[0] = 0)
 EndFunc  ;==>GDIPlus_MatrixTranslate<gdiplus.au3>

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×