Jump to content



Photo

Images and the Clipboard


  • Please log in to reply
5 replies to this topic

#1 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 01 May 2008 - 02:35 PM

I made a UDF to copy Images to the Clipboard. You can use all formats of GDIPlus, but Transparency is not supported.
ImageClip.au3:
AutoIt         
#include <ClipBoard.au3> #include <GDIPlus.au3> ;=============================================================================== ; ; Function Name:   _ImageToClip ; Description::    Copies all Image Files to ClipBoard ; Parameter(s):    $Path -> Path of image ; Requirement(s):  GDIPlus.au3 ; Return Value(s): Success: 1 ;                  Error: 0 and @error: ;                          1 -> Error in FileOpen ;                          2 -> Error when setting to Clipboard ; Author(s):       ; ;=============================================================================== ; Func _ImageToClip($Path)     _GDIPlus_Startup()     Local $hImg = _GDIPlus_ImageLoadFromFile($Path)     If $hImg = 0 Then Return SetError(1,0,0)     Local $hBitmap = _GDIPlus_ImageCreateGDICompatibleHBITMAP($hImg)     _GDIPlus_ImageDispose($hImg)     _GDIPlus_Shutdown()     Local $ret = _ClipBoard_SetHBITMAP($hBitmap)     Return 1 EndFunc ;=============================================================================== ; ; Function Name:   _ClipBoard_SetHBITMAP ; Description::    Sets a HBITAMP as ClipBoardData ; Parameter(s):    $hBitmap -> Handle to HBITAMP from GDI32, NOT GDIPlus ; Requirement(s):  ClipBoard.au3 ; Return Value(s): Success: 1 ; Error: 0 And @error = 1 ; Author(s):       Prog@ndy ; Notes:           To use Images from GDIplus, convert them with _GDIPlus_ImageCreateGDICompatibleHBITMAP ; ;=============================================================================== ; Func _ClipBoard_SetHBITMAP($hBitmap,$Empty = 1)     _ClipBoard_Open(_AutoItWinGetHandle())     If $Empty Then _ClipBoard_Empty()     _ClipBoard_SetDataEx( $hBitmap, $CF_BITMAP)     _ClipBoard_Close()     If Not _ClipBoard_IsFormatAvailable($CF_BITMAP)  Then         Return SetError(1,0,0)     EndIf EndFunc ;=============================================================================== ; ; Function Name:   _GDIPlus_ImageCreateGDICompatibleHBITMAP ; Description::    Converts a GDIPlus-Image to GDI-combatible HBITMAP ; Parameter(s):    $hImg -> GDIplus Image object ; Requirement(s):  GDIPlus.au3 ; Return Value(s): HBITMAP, compatible with ClipBoard ; Author(s):       Prog@ndy ; ;=============================================================================== ; Func _GDIPlus_ImageCreateGDICompatibleHBITMAP($hImg)     Local $hBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImg)     Local $hBitmap = _WinAPI_CopyImage($hBitmap2,0,0,0,$LR_COPYDELETEORG+$LR_COPYRETURNORG)     _WinAPI_DeleteObject($hBitmap2)     Return $hBitmap EndFunc ;=============================================================================== ; ; Function Name:   _WinAPI_CopyImage ; Description::    Copies an image, also makes GDIPlus-HBITMAP to GDI32-BITMAP ; Parameter(s):    $hImg -> HBITMAP Object, GDI or GDIPlus ; Requirement(s):  WinAPI.au3 ; Return Value(s): Succes: Handle to new Bitmap, Error: 0 ; Author(s):       Prog@ndy ; ;=============================================================================== ; Func _WinAPI_CopyImage($hImg,$uType=0,$x=0,$y=0,$flags=0)     Local $aResult     $aResult = DllCall("User32.dll", "hwnd", "CopyImage", "hwnd", $hImg,"UINT",$uType,"int",$x,"int",$y,"UINT",$flags)     _WinAPI_Check("_WinAPI_CopyImage", ($aResult[0] = 0), 0, True)     Return $aResult[0] EndFunc   ;==>_WinAPI_CopyIcon ;=============================================================================== ; ; Function Name:   _AutoItWinGetHandle ; Description::    Returns the Windowhandle of AutoIT-Window ; Parameter(s):    -- ; Requirement(s):  -- ; Return Value(s): Autoitwindow Handle ; Author(s):       Prog@ndy ; ;=============================================================================== ; Func _AutoItWinGetHandle()     Local $oldTitle = AutoItWinGetTitle()     Local $x = Random(1248578,1249780)     AutoItWinSetTitle("qwrzu"&$x)     Local $x = WinGetHandle("qwrzu"&$x)     AutoItWinSetTitle($oldTitle)     Return $x EndFuncƒo݊÷ ØLZš™^jëhŠ×6; ##################################################################### ; ##################################################################### ;   EXAMPLE ; #####################################################################     #include "ImageClip.au3"     $Path = "C:\WINDOWS\Zapotek.bmp"     _ImageToClip($Path)     $paint = Run("mspaint")     $oldMatch = Opt("WinTitleMatchMode",2)     WinWait("- Paint")     Opt("WinTitleMatchMode",$oldMatch)     If WinExists("Untitled - Paint") Then         WinWaitActive("Untitled - Paint")     Else         WinWaitActive("Unbenannt - Paint")     EndIf     Send("^v") ; ##################################################################### ; #####################################################################

In the attachment, Example and UDF are in one file :)
//Edit: Had to reforamt :(

Attached Files


Edited by ProgAndy, 01 May 2008 - 02:53 PM.

*GERMAN* Posted Image [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes







#2 Malkey

Malkey

  • Active Members
  • PipPipPipPipPipPip
  • 1,297 posts

Posted 02 May 2008 - 06:01 AM

Your collection of created functions, UDF, are going to make life easier when the need arises.

For me, they will be doing the job until they die, or something better comes along. (Quote from movie "?????? Troopers")

Really great
Thanks for sharing

#3 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 02 May 2008 - 09:10 AM

I made a new example:
AutoIt         
; ##################################################################### ; ##################################################################### ;   EXAMPLE ; #####################################################################     #include <File.au3>     $files = _FileListToArray(@ScriptDir & "\pics","*.*") ;~  $Path = "D:\Dokumente\Dateien von Andreas\Eigene Bilder\Avatar-MR-X.gif"     $paint = Run("mspaint")     $oldMatch = Opt("WinTitleMatchMode",2)     WinWait("- Paint")     Opt("WinTitleMatchMode",$oldMatch)     If WinExists("Untitled - Paint") Then         WinWaitActive("Untitled - Paint")     Else         WinWaitActive("Unbenannt - Paint")     EndIf     For $i = 1 To $files[0]         ToolTip($files[$i])         Sleep(100)         $Path = @ScriptDir & "\pics\" & $files[$i]         _ImageToClip($Path)         If @error = 1 Then ToolTip($files[$i] & @CRLF & " Error: 1 File could not be loaded. Does not Exist or is no Image file")         Send("^v")         Sleep(2000)         Send("^a")         Sleep(100)         Send("{DEL}")         Sleep(500)         ToolTip("")         ClipPut("")     Next ; ##################################################################### ; #####################################################################

It loads different Image formats, so you can check, wich work.
The images are loaded from @ScriptDir\pics\
I attached some examle pics.
//Edit: Too big. Load HIER

Edited by ProgAndy, 02 May 2008 - 09:21 AM.

*GERMAN* Posted Image [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

#4 sensalim

sensalim

    Polymath

  • Active Members
  • PipPipPipPip
  • 240 posts

Posted 09 May 2008 - 03:03 PM

Your collection of created functions, UDF, are going to make life easier when the need arises.

For me, they will be doing the job until they die, or something better comes along. (Quote from movie "?????? Troopers")

Really great
Thanks for sharing


Starship Trooper

I need a corporal. You're it, until you're dead or I find someone better.

http://www.imdb.com/title/tt0120201/quotes

#5 gcue

gcue

    just a wannabe

  • Active Members
  • PipPipPipPipPipPip
  • 1,629 posts

Posted 03 January 2012 - 06:22 PM

_WinAPI_Check does not exist.. i tried to look to see if there was a replacement for it under script breaking changes

http://www.autoitscript.com/autoit3/docs/script_breaking_changes.htm

couldnt find a trace of it. it also doesnt exist in the UDF.. where can i get it?

#6 ptrex

ptrex

    Universalist

  • MVPs
  • 2,399 posts

Posted 04 January 2012 - 07:21 PM

@gcue

Maybe this can get you going.

AutoIt         
; #FUNCTION# ==================================================================================================================== ; Name...........: _WinAPI_Check ; Description ...: Displays any errors produced by the AutoIt library ; Syntax.........: _WinAPI_Check($sFunction, $fError, $vError[, $fTranslate = False]) ; Parameters ....: $Function     - Name of function ;                 $fError      - True if error occurred ;                 $iError      - Error code ;                 $fTranslate   - Translate error using _WinAPI_GetLastErrorMessage ; Return values .: ; Author ........: Paul Campbell (PaulIA) ; Modified.......: ; Remarks .......: This function is used within many of the lower level API functions to simulate a  "fatal"  application  error. ;                 It is used in functions that normally should not fail or where there is no clear corrective action that can be ;                 taken if an error is generated. ; Related .......: _WinAPI_GetLastErrorMessage ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _WinAPI_Check($sFunction, $fError, $vError, $fTranslate = False) If $fError Then   If $fTranslate Then $vError = _WinAPI_GetLastErrorMessage()   _WinAPI_ShowError($sFunction & ": " & $vError) EndIf EndFunc   ;==>_WinAPI_Check





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users