Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6791947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:54:31+00:00 2026-05-26T17:54:31+00:00

I use WPF and my program has images in a DLL resource file. I

  • 0

I use WPF and my program has images in a DLL resource file. I have this well working way to read in images from disk:

Private Function GetImageFromFile(ByVal fileName As String) As BitmapImage
    Dim buffer As Byte() = IO.File.ReadAllBytes(fileName)
    Dim memoryStream As New IO.MemoryStream(buffer)

    Dim bitmap As New BitmapImage()
    bitmap.BeginInit()
    bitmap.StreamSource = memoryStream
    bitmap.EndInit()
    bitmap.Freeze()

    Return bitmap
End Function

Now, how can I get images in this MemoryStream-way from a DLL resource?

The basic problem: If I use simply the “bitmap.UriSource = whatever uri” way and load many images in sequence like an animation it builds up the memory. I tried with the above memorystream way and it worked perfectly fine, but then I store my images in a dll and I don’t know how to do this trick. If anybody knows how to read many images from a managed dll without building up the memory pls, let me know.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:54:32+00:00Added an answer on May 26, 2026 at 5:54 pm

    I found the answer to my question. I put it here for others who may need it. There are more ways to load images from a resource dll file. The easiest way to initialize the BitmapImage and set bi.UriSource=uriPath (where the path looks like I show below) but when you load images in a sequence, as an animation for example, it seems to take a lot of memory. Then you can use a StreamResourceInfo as shown below and just put like bi.StreamSource = sri.Stream. That works, too, but memorywise it has same results. So in practice I found the following way the fastest and most memory efficient way to load hundreds of images in a sequence:

    Public Function GetImageFromDLL(ByVal uriPath As String) As BitmapImage
        Dim sri As Windows.Resources.StreamResourceInfo = Application.GetResourceStream(New Uri(uriPath, UriKind.Absolute))
        Dim binReader As New System.IO.BinaryReader(sri.Stream)
        Dim buffer As Byte() = binReader.ReadBytes(sri.Stream.Length)
        Dim memoryStream As New IO.MemoryStream(buffer)
    
        Dim bi As New BitmapImage()
        bi.BeginInit()
        bi.CacheOption = BitmapCacheOption.Default
        bi.CreateOptions = BitmapCreateOptions.None
        bi.StreamSource = memoryStream
        bi.EndInit()
        bi.Freeze()
    
        Return bi
    End Function
    

    Where the uriPath is something like: “pack://application:,,,/YourDLL;Component/YourImageFile.jpg”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a program in C# WPF. I use an external dll
I have a WPF application which has a DirectX component within it. This component
I'm designing a WPF program that will use a DLL-plugin architecture. The host application
I am working on a program in WPF for the first time. I have
Can I use the WPF DataGrid control in the same way I use a
I'd like to use a WPF ComboBox in a similar way to the Flag
I have expanders that contain text boxes, the text boxes use the wpf validation
I am writing a WPF program in C# in which I have a ListView
Say, I have a WPF program with a Windows Forms control in WindowsFormsHost on
I have been having this issue with blurry text in WPF. I know that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.