Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) Extract data:image/png;base64 from HTMLDemonstrates how to extract base64 image data from HTMl and save to files.
Use ChilkatAx-win32.pkg Procedure Test Handle hoSb Handle hoBd Filename Handle hoSbFilename Integer iIndex Boolean iSuccess Boolean iMayHaveMore String sSBase64 Integer iCount String sTemp1 Integer iTemp1 Boolean bTemp1 Get Create (RefClass(cComChilkatStringBuilder)) To hoSb If (Not(IsComObjectCreated(hoSb))) Begin Send CreateComObject of hoSb End Get Create (RefClass(cComChilkatBinData)) To hoBd If (Not(IsComObjectCreated(hoBd))) Begin Send CreateComObject of hoBd End Get Create (RefClass(cComChilkatStringBuilder)) To hoSbFilename If (Not(IsComObjectCreated(hoSbFilename))) Begin Send CreateComObject of hoSbFilename End Move 1 To iIndex Get ComLoadFile Of hoSb "qa_data/html/oresp body.txt" "utf-8" To iSuccess // Assume success. Get ComLength Of hoSb To iTemp1 Showln "length = " iTemp1 Move True To iMayHaveMore While (iMayHaveMore = True) // Get the base64 between the 1st occurrence "data:image/png;base64," and "'" Get ComGetBetween Of hoSb "data:image/png;base64," "'" To sSBase64 // If nothing is found, then we'll exit the loop because there are no more. Get ComLastMethodSuccess Of hoSb To iMayHaveMore Get ComLastMethodSuccess Of hoSb To bTemp1 If (bTemp1 = True) Begin // Found something. // Load into bd and save. Get ComLoadEncoded Of hoBd sSBase64 "base64" To iSuccess Get ComSetString Of hoSbFilename "qa_output/png_" To iSuccess Get ComAppendInt Of hoSbFilename iIndex To iSuccess Get ComAppend Of hoSbFilename ".png" To iSuccess Get ComGetAsString Of hoSbFilename To sTemp1 Get ComWriteFile Of hoBd sTemp1 To iSuccess // Replace "data:image/png;base64" with "data:image-png;base64" so the next iteration finds the next occurrence. Get ComReplaceFirst Of hoSb "data:image/png;base64" "data:image-png;base64" To iSuccess End Move (iIndex + 1) To iIndex Loop // Restore our replacements.. Get ComReplace Of hoSb "data:image-png;base64" "data:image/png;base64" To iCount Showln "All done." End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.