Das Thema
Thema
Bilder im webp Format in GUI anzeigen
Moin,
gibt es eine Möglichkeit das webp Bildformat in einer AutoIt-GUI anzeigen zu lassen?
Beispielbilder findet man unter https://developers.google.com/speed/webp/gallery1, z.B.
https://www.gstatic.com/webp/gallery/1.webp
Ich vermute es würde mit einem eingebetteten IE gehen, aber eventuell gibt es ja auch eine einfachere Methode.
Dabei gibt es ja wie bei GIF auch die Möglichkeit animierte webp-Bilder zu erstellen, Beispiel: https://mathiasbynens.be/demo/animated-webp
Ich habe schon ein wenig…
gibt es eine Möglichkeit das webp Bildformat in einer AutoIt-GUI anzeigen zu lassen?
Beispielbilder findet man unter https://developers.google.com/speed/webp/gallery1, z.B.
https://www.gstatic.com/webp/gallery/1.webp
Ich vermute es würde mit einem eingebetteten IE gehen, aber eventuell gibt es ja auch eine einfachere Methode.
Dabei gibt es ja wie bei GIF auch die Möglichkeit animierte webp-Bilder zu erstellen, Beispiel: https://mathiasbynens.be/demo/animated-webp
Ich habe schon ein wenig…
![](https://autoit.de/wcf/images/avatars/23/627-231e7afa2de4ac507c1d069c9d2c4ce79d01d596.jpg)
BLinz
hat mich neugierig gemacht, und deshalb habe ich eine kleine DLL gebastelt, die WebP Bilder in GDI+ / GDI umwandelt, sodass man sie direkt in Autoit benutzen kann.
Das Archiv beinhaltet u.a. die DLLs (x86 / x64), die zum Umwandeln benötigt werden.
UDF:
AutoIt: Webp.au3
;Version 0.3.1 build 2022-06-13 beta
#include-once
#include <GDIPlus.au3>
Enum $WEBP_PRESET_DEFAULT = 0, _ ; default preset.
$WEBP_PRESET_PICTURE, _ ; digital picture, like portrait, inner shot
$WEBP_PRESET_PHOTO, _ ; outdoor photograph, with natural lighting
$WEBP_PRESET_DRAWING, _ ; hand or line drawing, with high-contrast details
$WEBP_PRESET_ICON, _ ; small-sized colorful images
$WEBP_PRESET_TEXT ; text-like
; #FUNCTION# ====================================================================================================================
; Name ..........: WebP_Ver
; Description ...: Displays the DLL version information in a messagebox window
; Syntax ........: WebP_Ver([$sPath2DLL = ""])
; Parameters ....: $sPath2DLL - [optional] a string value. Default is "". Path to WebP dll if not in script dir
; Return values .: None
; Author ........: UEZ
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func WebP_Ver($sPath2DLL = "")
Local $sDLL = Path2DLL($sPath2DLL)
If Not FileExists($sDLL) Then Return SetError(1, 0, 0) ;DLL not found
DllCall($sDLL, "none", "WebP_DLL_Version")
Return True
EndFunc ;==>WebP_Ver
; #FUNCTION# ====================================================================================================================
; Name ..........: WebP_Ver2
; Description ...: Returns the DLL version information
; Syntax ........: WebP_Ver([$sPath2DLL = ""])
; Parameters ....: $sPath2DLL - [optional] a string value. Default is "". Path to WebP dll if not in script dir
; Return values .: DLL version
; Author ........: UEZ
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func WebP_Ver2($sPath2DLL = "")
Local $sDLL = Path2DLL($sPath2DLL)
If Not FileExists($sDLL) Then Return SetError(1, 0, 0) ;DLL not found
Return DllCall($sDLL, "str", "Web_DLL_Version2")[0]
EndFunc ;==>WebP_Ver
; #FUNCTION# ====================================================================================================================
; Name ..........: WebP_BitmapGetInfo
; Description ...: Gets some rudimentary information about the WebP image
; Syntax ........: WebP_BitmapGetInfo($sFilename[, $sPath2DLL = ""])
; Parameters ....: $sFilename - file to load
; $sPath2DLL - [optional] a string value. Default is "". Path to WebP dll if not in script dir
; Return values .: Struct
; Author ........: UEZ
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://developers.google.com/speed/webp
; Example .......: No
; ===============================================================================================================================
Func WebP_BitmapGetInfo($sFilename, $sPath2DLL = "")
Local $sDLL = Path2DLL($sPath2DLL)
If Not FileExists($sDLL) Then Return SetError(1, 0, 0) ;DLL not found
If Not FileExists($sFilename) Then Return SetError(2, 0, 0) ;file not found
Local $iFileSize = FileGetSize($sFilename), $nBytes
Local $tBuffer = DllStructCreate("struct;byte bin[" & $iFileSize & "];endstruct")
Local Const $hFile = _WinAPI_CreateFile($sFilename, 2, 2)
_WinAPI_ReadFile($hFile, $tBuffer, $iFileSize, $nBytes)
_WinAPI_CloseHandle($hFile)
If Int(BinaryMid($tBuffer.bin, 1, 4)) <> 1179011410 Or Int(BinaryMid($tBuffer.bin, 9, 6)) <> 88331643929943 Then Return SetError(3, 0, 0) ;header must contain RIFF and WEBPVP
Local $tWebPBitstreamFeatures = DllStructCreate("struct;long width; long height; long has_alpha; long has_animation; long format; ulong pad[5];endstruct")
Local $iReturn = DllCall($sDLL, "long", "WebP_BitmapGetInfo", "struct*", $tBuffer, "uint", $iFileSize, "struct*", $tWebPBitstreamFeatures)
If $iReturn = 0 Then Return SetError(4, 0, 0)
Return $tWebPBitstreamFeatures
EndFunc ;==>WebP_BitmapGetInfo
; #FUNCTION# ====================================================================================================================
; Name ..........: WebP_BitmapCreateGDIp
; Description ...: Converts (decodes) a WebP image from disk to a GDI / GDI+ bitmap handle
; Syntax ........: WebP_BitmasFilename[, $bGDIImage = False[, $sPath2DLL = ""]])
; Parameters ....: $sFilename - file to load
; $bGDIImage - [optional] a boolean value. Default is False (GDIPlus bitmap handle). If True then output is GDI bitmap handle
; $bCountColors - [optional] a boolean value. Default is False. If True then the colors will be counted and saved in extended. Use @extended to get color count.
; $sPath2DLL - [optional] a string value. Default is "". Path to WebP dll if not in script dir
; Return values .: GDI / GDIPlus bitmap handle and color count if $bCountColors = True in extended.
; Author ........: UEZ
; Modified ......:
; Remarks .......: Currently only WebP images are supported - no animated WebP images yet!
; Related .......:
; Link ..........: https://developers.google.com/speed/webp
; Example .......: No
; ===============================================================================================================================
Func WebP_BitmapCreateGDIp($sFilename, $bGDIImage = False, $bCountColors = False, $sPath2DLL = "")
Local $sDLL = Path2DLL($sPath2DLL)
If Not FileExists($sDLL) Then Return SetError(1, 0, 0) ;DLL not found
If Not FileExists($sFilename) Then Return SetError(2, 0, 0) ;file not found
Local $iFileSize = FileGetSize($sFilename), $nBytes
Local $tBuffer = DllStructCreate("byte bin[" & $iFileSize & "]")
Local Const $hFile = _WinAPI_CreateFile($sFilename, 2, 2)
_WinAPI_ReadFile($hFile, $tBuffer, $iFileSize, $nBytes)
_WinAPI_CloseHandle($hFile)
If Int(BinaryMid($tBuffer.bin, 1, 4)) <> 1179011410 Or Int(BinaryMid($tBuffer.bin, 9, 6)) <> 88331643929943 Then Return SetError(3, 0, 0) ;header must contain RIFF and WEBPVP
Local $tColors = DllStructCreate("struct;ulong cc;endstruct")
Local Const $hBitmap = DllCall($sDLL, "ptr", "WebP_BitmapCreateGDIp", "struct*", $tBuffer, "uint", $iFileSize, "boolean", $bGDIImage, "boolean", $bCountColors, "struct*", $tColors)[0]
If $hBitmap = 0 Then Return SetError(4, 0, 0)
Return SetExtended($tColors.cc, $hBitmap)
EndFunc ;==>WebP_BitmapCreateGDIp
; #FUNCTION# ====================================================================================================================
; Name ..........: WebP_BitmapCreateGDIpFromMem
; Description ...: Converts (decodes) a WebP image from memory to a GDI / GDI+ bitmap handle
; Syntax ........: WebP_BitmapCreateGDIpFromMem($tBuffer[, $iBufferSize = 0[, $bGDIImage = False[, $sPath2DLL = ""]]])
; Parameters ....: $tBuffer - a dll struct with WebP binary data as content or pointer to the memory data
; $iBufferSize - the size of the binary data (file size)
; $bGDIImage - [optional] a boolean value. Default is False (GDIPlus bitmap handle). If True then output is GDI bitmap handle
; $bCountColors - [optional] a boolean value. Default is False. If True then the colors will be counted and saved in extended. Use @extended to get color count.
; $sPath2DLL - [optional] a string value. Default is "". Path to WebP dll if not in script dir
; Return values .: GDI / GDIPlus bitmap handle and color count if $bCountColors = True in extended.
; Author ........: UEZ
; Modified ......:
; Remarks .......: Currently only WebP images are supported - no animated WebP images yet!
; Related .......:
; Link ..........: https://developers.google.com/speed/webp
; Example .......: No
; ===============================================================================================================================
Func WebP_BitmapCreateGDIpFromMem($tBuffer, $iBufferSize = 0, $bGDIImage = False, $bCountColors = False, $sPath2DLL = "")
Local $sDLL = Path2DLL($sPath2DLL)
If Not FileExists($sDLL) Then Return SetError(1, 0, 0) ;DLL not found
If $iBufferSize = 0 Then Return SetError(2, 0, 0)
Local $binMem
If IsPtr($tBuffer) Then
Local $tMem = DllStructCreate("byte bin[" & $iBufferSize & "]", $tBuffer)
$binMem = $tMem.bin
Else
$binMem = DllStructGetData($tBuffer, 1)
EndIf
If Int(BinaryMid($binMem, 1, 4)) <> 1179011410 Or Int(BinaryMid($binMem, 9, 6)) <> 88331643929943 Then Return SetError(3, 0, 0) ;header must contain RIFF and WEBPVP
Local $tColors = DllStructCreate("struct;ulong cc;endstruct")
Local Const $hBitmap = DllCall($sDLL, "ptr", "WebP_BitmapCreateGDIp", "struct*", $tBuffer, "uint", $iBufferSize, "boolean", $bGDIImage, "boolean", $bCountColors, "struct*", $tColors)[0]
If $hBitmap = 0 Then Return SetError(4, 0, 0)
Return SetExtended($tColors.cc, $hBitmap)
EndFunc ;==>WebP_BitmapCreateGDIpFromMem
; #FUNCTION# ====================================================================================================================
; Name ..........: WebP_CreateWebPLossySimpleFromBitmap
; Description ...: Converts a bitmap to WebP lossy image and save it to HD
; Syntax ........: WebP_CreateWebPLossySimpleFromBitmap($sFilename, $hBitmap[, $iQuality = 75[, $sPath2DLL = ""]])
; Parameters ....: $sFilename - file to load
; $hBitmap - GDIPlus bitmap handle
; $iQuality - [optional] an integer value. Default is 75. Valid range is 0 - 100.
; $sPath2DLL - [optional] a string value. Default is "". Path to WebP dll if not in script dir.
; Return values .: 0 for failure, 1 for success.
; Author ........: UEZ
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://developers.google.com/speed/webp
; Example .......: No
; ===============================================================================================================================
Func WebP_CreateWebPLossySimpleFromBitmap($sFilename, $hBitmap, $iQuality = 75, $sPath2DLL = "")
If $sFilename = "" Then Return SetError(1, 0, 0)
Local $sDLL = Path2DLL($sPath2DLL)
If Not FileExists($sDLL) Then Return SetError(2, 0, 0) ;DLL not found
Local $iReturn = DllCall($sDLL, "long", "WebP_CreateWebPLossySimpleFromBitmap", "str", $sFilename, "ptr", $hBitmap, "float", $iQuality)[0]
If $iReturn = 0 Then Return SetError(3, 0, 0)
Return 1
EndFunc ;==>WebP_CreateWebPLossySimpleFromBitmap
; #FUNCTION# ====================================================================================================================
; Name ..........: WebP_CreateWebPLosslessSimpleFromBitmap
; Description ...: Converts a bitmap to WebP lossless image and save it to HD
; Syntax ........: WebP_CreateWebPLosslessSimpleFromBitmap($sFilename, $hBitmap[, $sPath2DLL = ""])
; Parameters ....: $sFilename - file to load
; $hBitmap - GDIPlus bitmap handle
; $sPath2DLL - [optional] a string value. Default is "". Path to WebP dll if not in script dir.
; Return values .: 0 for failure, 1 for success.
; Author ........: UEZ
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://developers.google.com/speed/webp
; Example .......: No
; ===============================================================================================================================
Func WebP_CreateWebPLosslessSimpleFromBitmap($sFilename, $hBitmap, $sPath2DLL = "")
If $sFilename = "" Then Return SetError(1, 0, 0)
Local $sDLL = Path2DLL($sPath2DLL)
If Not FileExists($sDLL) Then Return SetError(2, 0, 0) ;DLL not found
Local $iReturn = DllCall($sDLL, "long", "WebP_CreateWebPLosslessSimpleFromBitmap", "str", $sFilename, "ptr", $hBitmap)[0]
If $iReturn = 0 Then Return SetError(3, 0, 0)
Return 1
EndFunc ;==>WebP_CreateWebPLosslessSimpleFromBitmap
; #FUNCTION# ====================================================================================================================
; Name ..........: WebP_CreateWebPAdvancedFromBitmap
; Description ...: Converts a bitmap to WebP lossy / lossless image and save it to HD
; Syntax ........: WebP_CreateWebPAdvancedFromBitmap($sFilename, $hBitmap[, $WebPPreset = $WEBP_PRESET_DEFAULT[, $lossless = 0[,
; $quality = 75.0[, $method = 4[, $sns_strength = 50[, $filter_sharpness = 0[, $filter_strength = 60[,
; $pass = 1[, $level = 6[, $sPath2DLL = ""]]]]]]]]]])
; Parameters ....: $sFilename - file to load
; $hBitmap - GDIPlus bitmap handle
; $WebPPreset - [optional] an unknown value. Default is $WEBP_PRESET_DEFAULT.
; $lossless - [optional] an unknown value. Default is 0. 0 for lossy encoding / 1 for lossless..
; $quality - [optional] an unknown value. Default is 75.0. Valid range is 0 - 100.
; $method - [optional] a map. Default is 4. Valid range is 0 - 6 (0=fast, 6=slower-better).
; $sns_strength - [optional] a string value. Default is 50. Spatial Noise Shaping. 0=off, 100=maximum
; $filter_sharpness - [optional] a floating point value. Default is 0. Range: [0 = off .. 7 = least sharp]
; $filter_strength - [optional] a floating point value. Default is 60. Range: [0 = off .. 100 = strongest]
; $pass - [optional] a pointer value. Default is 1. Number of entropy-analysis passes (in [1..10]).
; $level - [optional] an unknown value. Default is 6. Between 0 (fastest, lowest compression) and 9 (slower, best compression) only valid for lossless = 1!
; $near_lossless - [optional] an unknown value. Default is 100. Near lossless encoding [0 = max loss .. 100 = off (default)].
; $alpha_compression - [optional] an unknown value. Default is 1. Algorithm for encoding the alpha plane (0 = none,1 = compressed with WebP lossless). Default is 1.
; $alpha_filtering - [optional] an unknown value. Default is 1. Predictive filtering method for alpha plane.0: none, 1: fast, 2: best. Default if 1.
; $alpha_quality - [optional] an unknown value. Default is 100. Between 0 (smallest size) and 100 (lossless). Default is 100.
; $target_size - [optional] an unknown value. Default is 0. If non-zero, set the desired target size in bytes.
; $NoSave - [optional] an unknown value. Default is False.
; $pMem - [optional] a string value. Default is Null. If $NoSave = True then the pointer to the memory which holds the data will be returned.
; $pCallback - [optional] a pointer value. Default is 0. Pointer to a callback address for progress hook.
; $sPath2DLL - [optional] a string value. Default is "". Path to WebP dll if not in script dir.
; Return values .: negative value for failure, 1 for success or the struct with information (pointers, size) if $NoSave = True
; Author ........: UEZ
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://developers.google.com/speed/webp
; Example .......: No
; ===============================================================================================================================
Func WebP_CreateWebPAdvancedFromBitmap($sFilename, $hBitmap, $WebPPreset = $WEBP_PRESET_DEFAULT, $lossless = 0, $quality = 75.0, $method = 4, $sns_strength = 50, _
$filter_sharpness = 0, $filter_strength = 60, $pass = 1, $level = 6, $near_lossless = 100, $alpha_compression = 1, $alpha_filtering = 1, $alpha_quality = 100, _
$target_size = 0, $NoSave = False, $pCallback = 0, $sPath2DLL = "")
If $sFilename = "" And Not $NoSave Then Return SetError(1, 0, 0)
Local $sDLL = Path2DLL($sPath2DLL)
If Not FileExists($sDLL) Then Return SetError(2, 0, 0) ;DLL not found
Local $tMem = DllStructCreate("struct;ptr pPic; ptr pWriter; ptr pMemData; uint memsize;endstruct")
Local $iReturn = DllCall($sDLL, "long", "WebP_CreateWebPAdvancedFromBitmap", _
"str", $sFilename, _ ;Webp filename
"ptr", $hBitmap, _ ;handle to GDI+ bitmap
"long", $WebPPreset, _ ;WebPPreset
"long", $lossless, _ ;lossless
"float", $quality, _ ;quality
"long", $method, _ ;method
"long", $sns_strength, _ ;sns_strength
"long", $filter_sharpness, _ ;filter_sharpness
"long", $filter_strength, _ ;filter_strength
"long", $pass, _ ;pass
"long", $level, _ ;level
"long", $near_lossless, _ ;near_lossless
"long", $alpha_compression, _ ;alpha_compression
"long", $alpha_filtering, _ ;alpha_filtering
"long", $alpha_quality, _ ;alpha_quality
"long", $target_size, _ ;target_size
"bool", $NoSave, _ ;
"struct*", $tMem, _ ;
"ptr", @AutoItX64 ? $pCallback : 0)[0] ;x86 crashes for unknown reason
If $iReturn < 0 Then Return SetError(3, 0, $iReturn)
If $NoSave And $tMem.memsize = 0 Then SetError(4, 0, 0)
Return $NoSave ? $tMem : $iReturn
EndFunc ;==>WebP_CreateWebPAdvancedFromBitmap
; #FUNCTION# ====================================================================================================================
; Name ..........: WebP_FreeUp
; Description ...: Release the ressources from $tMem struct
; Syntax ........: WebP_FreeUp(Byref $tMem[, $sPath2DLL = ""])
; Parameters ....: $tMem - [in/out] a dll struct value.
; $sPath2DLL - [optional] a string value. Default is "".
; Return values .: 1
; Author ........: UEZ
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://developers.google.com/speed/webp
; Example .......: No
; ===============================================================================================================================
Func WebP_FreeUp(ByRef $tMem, $sPath2DLL = "")
Local $sDLL = Path2DLL($sPath2DLL)
If Not FileExists($sDLL) Then Return SetError(1, 0, 0) ;DLL not found
Local $iReturn = DllCall($sDLL, "long", "WebP_FreeUp", "struct*", $tMem)[0]
Return $iReturn
EndFunc ;==>WebP_FreeUp
; #FUNCTION# ====================================================================================================================
; Name ..........: BitmapCountColors
; Description ...: Counts the colors used by the bitmap
; Syntax ........: BitmapCountColors($hBitmap)
; Parameters ....: $hBitmap - a handle to a GDI+ bitmap.
; $bGDIImage - [optional] a boolean value. Default is False (GDIPlus bitmap handle).
; Return values .: Number of colors used by the image.
; Author ........: UEZ
; Modified ......:
; Remarks .......: The result may differ from other programs for JPG images depending on the decoder.
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func BitmapCountColors($hBitmap = 0, $bGDIImage = False, $sPath2DLL = "")
If IsPtr($hBitmap) = 0 Or $hBitmap = 0 Then SetError(1, 0, 0)
Local $sDLL = Path2DLL($sPath2DLL)
If Not FileExists($sDLL) Then Return SetError(2, 0, 0) ;DLL not found
Local $iReturn = DllCall(Path2DLL(), "ulong", "BitmapCountColors", "ptr", $hBitmap)[0]
Return $iReturn
EndFunc
; #INTERNAL_USE_ONLY#============================================================================================================
; Name...........: Path2DLL
; Description ...: Return the path to the _WebP_x??.dll
; Author ........: UEZ
; Modified.......:
; Remarks .......: This function is used internally by WebP.au3
; ===============================================================================================================================
Func Path2DLL($sPath2DLL = "")
Return $sPath2DLL ? $sPath2DLL : @ScriptDir & (@AutoItX64 ? "\_WebP_x64.dll" : "\_WebP_x86.dll")
EndFunc ;==>Path2DLL
Alles anzeigen
Beispiel 1:
AutoIt: WebP Example1.au3
;Coded by UEZ
#AutoIt3Wrapper_UseX64=y
#include <GUIConstantsEx.au3>
#include "WebP.au3"
;~ Global $sFile
Global $sFile = FileOpenDialog("Select an image", "", "Images (*.webp)")
If @error Then Exit
Global Const $STM_SETIMAGE = 0x0172
_GDIPlus_Startup()
Global Const $hBitmap = WebP_BitmapCreateGDIp($sFile, True)
Global $tDim = DllStructCreate($tagBITMAP)
DllCall("gdi32.dll", "int", "GetObject", "int", $hBitmap, "int", DllStructGetSize($tDim), "ptr", DllStructGetPtr($tDim))
Global Const $iW = DllStructGetData($tDim, "bmWidth"), $iH = DllStructGetData($tDim, "bmHeight")
Global Const $hGUI = GUICreate("WebP Image Viewer", $iW, $iH)
GUISetBkColor(0xFFFFFF)
Global Const $iPic = GUICtrlCreatePic("", 0, 0, $iW - 1, $iH - 1)
_WinAPI_DeleteObject(GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap))
GUISetState()
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_Shutdown()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Alles anzeigen
Beispiel 2:
AutoIt: WebP Example2.au3
;Coded by UEZ
#AutoIt3Wrapper_UseX64=n
#include <GUIConstantsEx.au3>
#include "WebP.au3"
Global Const $STM_SETIMAGE = 0x0172
_GDIPlus_Startup()
Global Const $binData = _WebP_Test_Image(), $iLen = BinaryLen($binData)
Global $tMem = DllStructCreate("byte bin[" & BinaryLen($binData) & "]")
$tMem.bin = $binData
Global Const $hBitmap = WebP_BitmapCreateGDIpFromMem($tMem, $iLen, True)
Global $tDim = DllStructCreate($tagBITMAP)
DllCall("gdi32.dll", "int", "GetObject", "int", $hBitmap, "int", DllStructGetSize($tDim), "ptr", DllStructGetPtr($tDim))
Global Const $iW = DllStructGetData($tDim, "bmWidth"), $iH = DllStructGetData($tDim, "bmHeight")
Global Const $hGUI = GUICreate("WebP Image Viewer", $iW, $iH)
GUISetBkColor(0xFFFFFF)
Global Const $iPic = GUICtrlCreatePic("", 0, 0, $iW - 1, $iH - 1)
_WinAPI_DeleteObject(GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap))
GUISetState()
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_Shutdown()
$tMem.bin = ""
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
;Code below was generated by: 'File to Base64 String' Code Generator v1.20 Build 2020-06-05
Func _WebP_Test_Image($bSaveBinary = False, $sSavePath = @ScriptDir)
Local $WebP_Test_Image
$WebP_Test_Image &= 'UklGRgoLAABXRUJQVlA4IP4KAAAQegCdASqCAYsBP3G00mI8P7+/pBHaG/IuCWVu/FSUDQP65DOGlzh3srUbSh0m7gLnkn0zylfD+3W3563nm3UeUfYAr/I3Qj4CCxiTF7emTO+xvUY4kg2rzauyNuFY/JImZ7Gzl+m4xHjyVFILDmEMardGsjrGgb8sg2rzKF2nqKPwaNlAibxnwCndTWvaLGgb8sg2qziJeSAxdOBWiM329B65bkk7GgGY7TD2no+AgsYF+N0f4wih++8dx1UkdTEhrFLM1DaSpfcGILkHwrLKcMoqOsz5euU3pVxCCHb4jeFZBtXm1W0BrkRPsde55VHmI5xsRjQVb3N3Ckm8DsS9BHnKzJeHgn25dkrqUWraZ3iJ0Q0DflkG1eZe45wD+S/HEoF5ZVOXLULDz7SZ0PmAY4zSdG0zosPQPsjbgpubXQPiDy1LCfNqabcZ8ZgHG8dLOKqJGDbs4YEjEosPQF2U1di55z257vpQyE7H9J+tKAAeN7EPDKlR64Ng3gJrNivHFVHeSw9AXZTV2Lbz6w8jM96fhqkmafvL+uy2sqOYzn2Cx4bd6RGvCE5rzZegqLD1HCpC1RXtr3IUFGe3riu7n1A2qbRh2NnZsTWG7YHA9F/fj18zv2Kjh+DeNXV3GdkL9Ku7T4fMowjgYrSKUwyYYj9uTmEo0kzYeOriVnC2zLtaiV8ymz3OTuvrefOxerK8fs/nANGbkcdiQIt1gCUlor/XmxuQi0z4eZRVhyGprWmYDz1SrHGINSHErz1tzbjGZLiUOplRP2FvArcgR5lemd8NGPq8RD9DMy8EQV2nUWFUjz/9BUIXYPSNvaldhXBQpyZem++Us+1uoUZwjmgkwV8QGn+uI3XiNaywpcE/6lEk3vhI65DxdZPxI4oEgm5217rvXWqYtfrb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NFTkS5YWjl230Fj8VlhfBzEEC6lBKY9wBzyn7ZXxJMNdS/Y0Dnk8e2YrkepX7qV7p545QxGYqbxfK+E/Vqb+yTwuUAJzKNzV25vb1cs98omMAATuDu2zYKodOJtO0bYy6tI3FAF5NXPaAWivkuqrExwrloFi/mG7HFrIMvEbnsSTPhoh1BKT+L1HFDa6PvBo1yhc4UYnr3ITJ7pqJSBp6Xu2T52NDbXuWCXnew4haL7peDlftd5xkdZgtWe3/Q/Vxov2QZq6jrNJDKo9iQPTuWDO1yeulWY+aXvjMqYIRPzIusnkop3iIX3VANrVxIIHEfyEiXDIkqU93hU3hLeABwZMeCcEzz5wLubpq1Q58qmdHgANGQp4RggzHBKjly8WL8ch8fsiithuaPFad2hCh51ZszDtPq5C2j5tWCca/6SE3+ySZKEo/AtaAvIMib0oK8M0Z6rAcIwVG0TAnWto/cqmGmbQAhsSNhFVYafhGDdV2aHAVQOzwaC8L+Y/0QT9YJY600pdjL1AkAf21pNPei+uhIjYR+RfjiTYjkWYHOtGpRa/V8OAKPQec2fwqecBOjQA60prWye6Vcrm2xKdQqL5G0hxR+xl89O8Idi0QBcKul3rEk9gx78n8KXI6ND4ai/2wvCivKhwDQwDWU3ZL8FGeW81XH8yL2rIvXo1Aa2Eo7s+gQwojP7HqJ9W4c/4JjU33BfB8Dw0yJTpWpNvAAAAAAEuuxacKAAAAAA='
Local $bString = _WinAPI_Base64Decode($WebP_Test_Image)
If @error Then Return SetError(1, 0, 0)
$bString = Binary($bString)
If $bSaveBinary Then
Local Const $hFile = FileOpen($sSavePath & "\Baby Tux small.webp", 18)
If @error Then Return SetError(2, 0, $bString)
FileWrite($hFile, $bString)
FileClose($hFile)
EndIf
Return $bString
EndFunc ;==>_WebP_Test_Image
Func _WinAPI_Base64Decode($sB64String)
Local $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "ptr", 0, "dword*", 0, "ptr", 0, "ptr", 0)
If @error Or Not $aCrypt[0] Then Return SetError(1, 0, "")
Local $bBuffer = DllStructCreate("byte[" & $aCrypt[5] & "]")
$aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "struct*", $bBuffer, "dword*", $aCrypt[5], "ptr", 0, "ptr", 0)
If @error Or Not $aCrypt[0] Then Return SetError(2, 0, "")
Return DllStructGetData($bBuffer, 1)
EndFunc ;==>_WinAPI_Base64Decode
Alles anzeigen
Beispiel 3:
AutoIt
;Coded by UEZ
#AutoIt3Wrapper_UseX64=n
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include "WebP.au3"
Global $sFile = FileOpenDialog("Select an image", "", "Images (*.webp)")
If @error Then Exit
Global $tBitmapInfo = WebP_BitmapGetInfo($sFile)
If Not @error Then MsgBox($MB_ICONINFORMATION, "WebP Bitmap Information", "Image width = " & $tBitmapInfo.width & @CRLF & _
"Image height = " & $tBitmapInfo.height & @CRLF & _
"Image format = " & ($tBitmapInfo.format = 0 ? "undefined " : ($tBitmapInfo.format = 1 ? "lossy" : "lossless")) & @CRLF & _
"Image has alpha = " & $tBitmapInfo.has_alpha & @CRLF & _
"Image has animation = " & $tBitmapInfo.has_animation)
WebP_Ver()
Alles anzeigen
Beispiel 4:
AutoIt
;Coded by UEZ
#AutoIt3Wrapper_UseX64=y
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include "WebP.au3"
Global $sFile = FileOpenDialog("Select an GDI+ supported image", "", "Images (*.jpg;*.png;*.bmp;*.gif;*.tif)")
If @error Then Exit
_GDIPlus_Startup()
Global $hImage = _GDIPlus_ImageLoadFromFile($sFile)
If Not $hImage Then Exit _GDIPlus_Shutdown()
Global $iReturn1 = WebP_CreateWebPLossySimpleFromBitmap(@ScriptDir & "\LossySimple.webp", $hImage, 1)
Global $iReturn2 = WebP_CreateWebPLosslessSimpleFromBitmap(@ScriptDir & "\LosslessSimple.webp", $hImage)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
ShellExecute("Explorer.exe", ".", @ScriptDir)
Alles anzeigen
Beispiel 5:
AutoIt
;Coded by UEZ
#AutoIt3Wrapper_UseX64=n
#include <GUIConstantsEx.au3>
#include "WebP.au3"
Global $sFile = FileOpenDialog("Select an image to compress", "", "Images (*.jpg;*.bmp;*.png;*.gif;*.tif)")
If @error Then Exit
Global Const $STM_SETIMAGE = 0x0172
_GDIPlus_Startup()
Global $hImage = _GDIPlus_ImageLoadFromFile($sFile), $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
;Example with maximal lossy compression settings
Global $tMem = WebP_CreateWebPAdvancedFromBitmap("", $hImage, _
0, _ ;$WebPPreset (0 - 5)
0, _ ;$lossless (0 - 1)
0, _ ;$quality (0.0 - 100.0)
6, _ ;$method (0 - 6)
0, _ ;$sns_strength (0 - 100)
0, _ ;$filter_sharpness (0 - 7)
0, _ ;$filter_strength (0 - 100)
10, _ ;$pass (1 - 10)
9, _ ;$level (0 - 9) for lossless compression only
100, _ ;$near_lossless (0 - 100)
1, _ ;$alpha_compression (0 - 1)
2, _ ;$alpha_filtering (0 - 2)
0, _ ;$alpha_quality (0 - 100)
0, _ ;$target_size (0 = off, size in bytes)
True) ;hold the compressed image in memory only, no save to HD!
Global $hBitmap = WebP_BitmapCreateGDIpFromMem($tMem.pMemData, $tMem.memsize, True)
Global $tDim = DllStructCreate($tagBITMAP)
DllCall("gdi32.dll", "int", "GetObject", "int", $hBitmap, "int", DllStructGetSize($tDim), "ptr", DllStructGetPtr($tDim))
Global Const $iW = DllStructGetData($tDim, "bmWidth"), $iH = DllStructGetData($tDim, "bmHeight")
Global Const $hGUI = GUICreate("WebP Image Viewer (Image size: " & Round($tMem.memsize / 1024, 2) & " kb)", $iW * 2, $iH)
GUISetBkColor(0xFFFFFF)
Global Const $iPic_WebP = GUICtrlCreatePic("", 0, 0, $iW - 1, $iH - 1)
Global Const $iPic_Original = GUICtrlCreatePic("", $iW, 0, $iW - 1, $iH - 1)
_WinAPI_DeleteObject(GUICtrlSendMsg($iPic_WebP, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap))
_WinAPI_DeleteObject(GUICtrlSendMsg($iPic_Original, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap))
GUISetState()
_GDIPlus_ImageDispose($hImage)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteObject($hHBitmap)
_GDIPlus_Shutdown()
WebP_FreeUp($tMem)
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Alles anzeigen
WebP Advanced Encoder GUI.au3:
Bitte mal testen, ob's bei euch auch funzt.
Btw, die DLL ist in Freebasic geschrieben.
Mehr zum Thema WebP API kann hier eingesehen werden: https://developers.google.com/speed/webp/docs/api.