Skip to content

VBMAN.Image - Image Data Conversion Object

Overview

VBMAN.Image provides mutual conversion functionality between Byte()Base64StdPicture image data formats, using a chained call design that allows complex conversions in a single line of code.

Core Features

  • Chained Calls: Fluent API design, one line to complete conversion + output
  • Three-Format Conversion: Free conversion between byte arrays, Base64 strings, and StdPicture objects
  • Data URI Support: Automatically parses data:image/jpeg;base64,... format
  • MIME Type Detection: Automatically identifies JPEG/PNG/GIF/BMP/WebP/ICO via file magic numbers
  • Direct Control Assignment: ShowTo method directly displays images to Image/PictureBox controls
  • Default Member: Data method is the default member, supporting VBMAN.Image.(base64Str) shorthand

Methods

Data

Chained call entry point, accepts Byte() array, Base64 string, StdPicture object. Default member.

vb
Public Function Data(ByVal vData As Variant) As cImage

Example:

vb
' From Base64 string
VBMAN.Image.Data(base64Str).ReturnPicture

' Shorthand (using default member)
VBMAN.Image.(base64Str).ReturnPicture

' From byte array
VBMAN.Image.Data(bytes).ReturnBase64

' From StdPicture
VBMAN.Image.Data(Image1.Picture).ReturnBase64

' Data URI format auto-parsing
VBMAN.Image.("data:image/png;base64,iVBOR...").ReturnPicture

ShowTo

Directly displays the image to the target control (chained call).

vb
Public Function ShowTo(ByVal Target As Object) As cImage

Parameters:

  • Target - Any control object with a Picture property (Image, PictureBox, etc.)

Example:

vb
' One-line display to Image control
VBMAN.Image.(base64Str).ShowTo Image1

' Display to PictureBox
VBMAN.Image.(bytesArr).ShowTo Picture1

ReturnBytes

Output as byte array.

vb
Public Function ReturnBytes() As Byte()

Example:

vb
Dim bytes() As Byte
bytes = VBMAN.Image.Data(base64Str).ReturnBytes

ReturnBase64

Output as Base64 string (without data: prefix).

vb
Public Function ReturnBase64() As String

Example:

vb
Dim b64 As String
b64 = VBMAN.Image.Data(Image1.Picture).ReturnBase64

ReturnPicture

Output as StdPicture object, can be directly assigned to control's Picture property.

vb
Public Function ReturnPicture() As StdPicture

Example:

vb
Set Image1.Picture = VBMAN.Image.Data(base64Str).ReturnPicture

ReturnDataUri

Output as Data URI format string (e.g., data:image/jpeg;base64,...).

vb
Public Function ReturnDataUri(Optional ByVal MimeType As String) As String

Parameters:

  • MimeType - Optional, MIME type. When omitted, uses auto-detection or defaults to image/jpeg

Example:

vb
' Auto-detect MIME
Dim uri As String
uri = VBMAN.Image.Data(bytes).ReturnDataUri

' Manually specify MIME
uri = VBMAN.Image.Data(bytes).SetMimeType("image/png").ReturnDataUri

SetMimeType

Manually set MIME type (chained call).

vb
Public Function SetMimeType(ByVal MimeType As String) As cImage

Example:

vb
VBMAN.Image.Data(bytes).SetMimeType("image/png").ReturnDataUri

ReturnMimeType

Returns the auto-detected MIME type.

vb
Public Function ReturnMimeType() As String

Supported detection: JPEG, PNG, GIF, BMP, WebP, ICO

Example:

vb
Dim mime As String
mime = VBMAN.Image.Data(bytes).ReturnMimeType  ' image/png

IsValid

Checks if data is valid.

vb
Public Function IsValid() As Boolean

Example:

vb
If VBMAN.Image.Data(base64Str).IsValid Then
    VBMAN.Image.ShowTo Image1
End If

Comprehensive Examples

Display Avatar from API

vb
' Get avatar Base64 from API, display in one line
Dim resp As String
resp = VBMAN.HttpClient.SetUrl("/api/avatar").Get
VBMAN.Image.(VBMAN.Json.Decode(resp)("avatar")).ShowTo Image1

Image Upload

vb
' Read image → Base64 → upload
VBMAN.FileEx.OpenFile "C:\photo.jpg", "R"
Dim bytes() As Byte
bytes = VBMAN.FileEx.ReadData.ReturnBytes
VBMAN.FileEx.CloseFile

Dim json As New cJson
json("image") = VBMAN.Image.Data(bytes).ReturnBase64
json("mime") = VBMAN.Image.Data(bytes).ReturnMimeType

VBMAN.HttpClient.SetUrl("/api/upload").SetBody(json.Encode).Post

Data URI Embedding in HTML

vb
' Image → Data URI → embed in page
Dim dataUri As String
dataUri = VBMAN.Image.Data(bytes).ReturnDataUri
WebBrowser1.Document.Write "<img src='" & dataUri & "'>"

Detailed Documentation

For complete API documentation, please refer to: Tools/Image Documentation

VB6 and LOGO copyright of Microsoft Corporation