Embed Picture to Custom Control

S-Soft 666 Reputation points
2023-04-12T04:25:55.3566667+00:00

Hello all I'm gonna use this method to embed a small 16x16 transparent png to my custom control:

    Dim PictureStream As New IO.MemoryStream(New Byte() _
    {&H89, xxxxxxxxxxxxxx})
    PictureBox1.Image = New Drawing.Bitmap(PictureStream)
    PictureStream = Nothing

However, don't know how to get the MemoryStream from my png icon on disc? Any idea? Thanks

output is expected to be like: -with or without {}

> {&H89, &H50, &H4E, &H47, &HAE, &H42, &H60, &H82}
> ```
> 
> 

Developer technologies | VB
Developer technologies | C#
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2023-04-12T05:05:32.0466667+00:00

    If you have an image file, then:

    PictureBox1.ImageLocation = "C:\SomeFolder\MyImage.png"
    

    The stream is not needed.


  2. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2023-04-20T08:16:11.01+00:00

    Hi @S-Soft , Try using Image.FromStream Method

        Dim image As Image = Image.FromStream(ms)
        PictureBox1.Image = image
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.