Login / Register
▼
Binary Fortress
Binary Fortress Software
CheckCentral
ClipboardFusion
CloudShow
DisplayFusion
FileSeek
HashTools
LogFusion
Notepad Replacer
Online Base64 Decoder
Online Base64 Encoder
Online JSON Formatter
ShellSend
TrayStatus
VoiceBot
WallpaperFusion
Window Inspector
More Apps...
DisplayFusion
CheckCentral
CloudShow
ClipboardFusion
FileSeek
VoiceBot
WallpaperFusion
▼
Download
Download
Change Log
Download Beta
Beta Change Log
License (EULA)
▼
Features
Features
HotKeys
Macros
Triggers
Clipboard Syncing
Clipboard Manager
Languages
Free vs Pro
Purchase
Screenshots
Apps
▼
Online
Online
Recent Items
Pinned Items
▼
Help
Help Guide
FAQ
Discussions
Contact Us
Find My License
Mailing Address
Advanced Settings
Macros
Languages
Clipboard
Fusion
WARNING: You currently have Javascript disabled!
This website will not function correctly without Javascript enabled.
Title
Message
OK
Confirm
Yes
No
Convert Image to Base64 (Ready for HTML tag)
Return to ClipboardFusion Macros
Description
Converts an image to Base64 ready to be used in an HTML tag.
Language
C# (.Net)
Minimum Version
5.1.1+
Created By
Wakewalker
Contributors
-
Date Created
Oct 17, 2017
Date Last Modified
Oct 17, 2017
Macro Code
Copy
Select All
Toggle Line Wrapping
using System; using System.Collections.Generic; using System.Windows.Forms; using System.Drawing; using System.Runtime.Serialization.Formatters.Binary; using System.IO; using System.Text; using System.Web; public static class ClipboardFusionHelper { ///<summary> /// Base 64 Encoding with URL and Filename Safe Alphabet using UTF-8 character set. ///</summary> ///<param name="str">The origianl string</param> ///<returns>The Base64 encoded string</returns> public static string Base64ForUrlEncode(string str) { byte[] encbuff = Encoding.UTF8.GetBytes(str); return HttpServerUtility.UrlTokenEncode(encbuff); } ///<summary> /// Decode Base64 encoded string with URL and Filename Safe Alphabet using UTF-8. ///</summary> ///<param name="str">Base64 code</param> ///<returns>The decoded string.</returns> public static string Base64ForUrlDecode(string str) { byte[] decbuff = HttpServerUtility.UrlTokenDecode(str); return Encoding.UTF8.GetString(decbuff); } internal static byte[] ImageToByteArray(Image img) { byte[] byteArray = new byte[0]; MemoryStream stream = new MemoryStream(); img.Save(stream, System.Drawing.Imaging.ImageFormat.Png); stream.Close(); byteArray = stream.ToArray(); return byteArray; } public static string ProcessText(string text) { if(!Clipboard.ContainsImage()) return text; BinaryFormatter binFormatter = new BinaryFormatter(); using(Image img = Clipboard.GetImage()) { text = Convert.ToBase64String(ImageToByteArray(img)); } //BFS.Dialog.ShowMessageInfo("Convert image to Base64 is finished!"); return string.Format(@"data:image/gif;base64,{0}", text); } }
Copyright © 2007-2021 Binary Fortress Software
•
News
•
Discussions
•
FAQ
•
Support
•
Privacy
•
ToS
•
Get Binary Fortress Merch