Ravi Naik
Ravi Naik

Reputation: 513

Storing bitmap image in XAML

I need to store the bitmap image information in an XAML-formatted file. Can anyone please help me out on this regard?

Upvotes: 1

Views: 2311

Answers (2)

user694833
user694833

Reputation:

I think it can be a valid request for some few cases, like embedding small button images in png format. I have not tried it, but I think the following is valid:

  • Embedd a string into your xaml code containing a base-64 encoded image
  • Instantiate a converter, that will take a bas-64 string and return an Image
  • Place an Image object into the xaml, bound to the base-64 string and using the mentioned converter

By the way, I have seen that case (small icons) embedded in HTML pages, where it is possible without a converter.

Upvotes: 0

Shay Erlichmen
Shay Erlichmen

Reputation: 31928

It can't be done (Charles Petzold)

Sure, you can refer to external bitmaps in XAML files, but you can't embed a bitmap in a XAML file. What you would need is a class that derives from BitmapSource that has a property named Data or something that you could set to an array of bytes, and a converter that would accept a list of quoted bytes in the XAML file. And such a class does not exist.

What you really shouldn't be doing is getting weird and dangerous ideas, like possibly simulating a bitmap using a UniformGrid containing a bunch of one-pixel square Rectangle objects, one for each pixel. That's just nuts.

Once you start thinking crazy thoughts like that, you're likely to take a 6K 220×260 color JPEG and convert it into a 1.9 megabyte EmbeddedBitmap.xaml file that takes way too much time to load and compose.

Surely you have better sense than that!

Upvotes: 3

Related Questions