How to convert image to Binary

I took screenshot using Take screenshot activity. But i need to store this screenshot in Binary format in sql query(DB). So How to convert a screenshot from Image to Binary format.

Hi @BNK

Assuming that you have saved the screenshot in a variable called capturedScreenshot which is of the data type System.Drawing.Image, you can use the following snippet to convert it to the binary format:

Using stream As New System.IO.MemoryStream()
capturedScreenshot.Save(stream, System.Drawing.Imaging.ImageFormat.Png)
Dim binaryData As Byte() = stream.ToArray()
End Using

Hope this helps,
Best Regards.

The datatype of image UiPath.Core.Image

@BNK

Well, in that case, you can directly use the following expression:

Dim imageBytes As Byte() = System.Convert.ToBase64String(capturedScreenshot.ToBitmap.GetBytes()).ToArray()

Hope this helps,
Best Regards.

image

I am getting above error

Sample code:

Sequence.xaml (7.1 KB)

Hi,

How about the following?

Using stream As System.IO.MemoryStream  = New System.IO.MemoryStream()
    Using bmp As Bitmap =New Bitmap(capturedScreenshot)
        bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png)
        arrByte= stream.ToArray()
    End Using
End Using

Sequence(1).xaml (10.1 KB)

Regards,

I am getting below mentioned error

Method not found: ‘Microsoft.CodeAnalysis.SyntaxTree Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxTree.ParseText(System.String, Microsoft.CodeAnalysis.VisualBasic.VisualBasicParseOptions, System.String, System.Text.Encoding, System.Collections.Immutable.ImmutableDictionary`2<System.String,Microsoft.CodeAnalysis.ReportDiagnostic>, System.Threading.CancellationToken)’.

I am using UiPath.system.activities= 21.10.3
UiPath.uiautomation.activities= 22.4.4

I can’t downgrade the package version.

Final_screenshot.xaml (7.5 KB)

Final_screenshot.xaml (7.5 KB)

Hi,

Can you try to downgrade System.Activities package 20.10.x or Upgrade UiPath studio?
Because InvokeCode in SystemActivities package 21.10.x doesn’t work in Studio20.10 as the followniog document.

Regards,

Instead of downgrade any other options is available?
Bcoz if did downgrade some other workflows not working.

Hi,

We can write the above code without InvokeCode as the following. Can you try this?

Sample20230613-6L.zip (3.3 KB)

Regards,

This workflow is working, But i need to store this information to database . The datatype in database is Varbinary

How i need to convert this to varbinary

Hi,

Varbinary is data type of SQL server. Basically it’s byte array in .net(UIiPath) (arrByte in the above code)

Regards,