Click here to Skip to main content
15,878,003 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem with using the Barcodelib 3.0.2 in VB.NET.
It has a method encode which returns "SKImage".
When I try to show it in a picturebox, I get an error of wrong type.
How could I change it to image type?

Thank you in advance for your help!

What I have tried:

Searched Google with no results, tried to convert it to stream, etc.
Posted
Updated 12-Oct-23 9:45am
v2

1 solution

Call SKImage.Encode[^] to return an SKData[^] instance wrapping the encoded image.

Then call SKData.AsStream[^] to get a stream wrapping the encoded data.

You should then be able to pass that stream to the Image.FromStream[^] method to get a System.Drawing.Image, which you can use with your picture box.
 
Share this answer
 
Comments
tMichu 12-Oct-23 10:17am    
Hi, thank yourfor the quick reply - I have tried your solution but now I get "System.AccessViolationException" on method Encode.

My code is:
            Dim image_ean As SKImage
            image_ean = Barcode.DoEncode(Type.Code128, text, True, foreColor, backColor, CInt(PictureBox1.Width * 0.8), CInt(PictureBox1.Height * 0.8))
            Dim stdata As SKData
            stdata = image_ean.Encode // here I am getting an error
            Dim img As Image
            img = Image.FromStream(stdata.AsStream)
            PictureBox1.Image = img
Richard Deeming 12-Oct-23 10:24am    
Try calling the overload of Encode which accepts an SKEncodedImageFormat.

Otherwise, you may need to raise an issue[^] in the SkiaSharp repo or the BarCodeLib repo[^].
Member 16145188 21-Nov-23 10:18am    
Thanks a lot for your answer!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900