Page 1 of 1

Question about Texture Atlases

Posted: 15 Jan 2014, 11:46
by jc_lvngstn
Something I was wondering but haven't gotten to yet: Let's say you have a large atlas with your icons, for your project. In your example of the running alladin character, you create a resource dictionary defining an image for each icon.
<!-- Created using Noesis XAML exporter for TexturePacker (http://www.texturepacker.com) -->
<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ImageBrush x:Key="aladin01" ImageSource="aladin-atlas.png" Viewbox="145,58,33,54" ViewboxUnits="Absolute"
      Stretch="Fill"/>
    <ImageBrush x:Key="aladin02" ImageSource="aladin-atlas.png" Viewbox="180,58,30,54" ViewboxUnits="Absolute"
      Stretch="Fill"/>
    <ImageBrush x:Key="aladin03" ImageSource="aladin-atlas.png" Viewbox="73,61,27,57" ViewboxUnits="Absolute"
      Stretch="Fill"/>
    <ImageBrush x:Key="aladin04" ImageSource="aladin-atlas.png" Viewbox="39,2,33,57" ViewboxUnits="Absolute"
      Stretch="Fill"/>
    <ImageBrush x:Key="aladin05" ImageSource="aladin-atlas.png" Viewbox="112,2,38,54" ViewboxUnits="Absolute"
      Stretch="Fill"/>
    <ImageBrush x:Key="aladin06" ImageSource="aladin-atlas.png" Viewbox="74,2,36,56" ViewboxUnits="Absolute"
      Stretch="Fill"/>
    <ImageBrush x:Key="aladin07" ImageSource="aladin-atlas.png" Viewbox="152,2,31,54" ViewboxUnits="Absolute"
      Stretch="Fill"/>
    <ImageBrush x:Key="aladin08" ImageSource="aladin-atlas.png" Viewbox="185,2,27,54" ViewboxUnits="Absolute"
      Stretch="Fill"/>
    <ImageBrush x:Key="aladin09" ImageSource="aladin-atlas.png" Viewbox="41,61,30,57" ViewboxUnits="Absolute"
      Stretch="Fill"/>
    <ImageBrush x:Key="aladin10" ImageSource="aladin-atlas.png" Viewbox="2,2,35,58" ViewboxUnits="Absolute"
      Stretch="Fill"/>
    <ImageBrush x:Key="aladin11" ImageSource="aladin-atlas.png" Viewbox="102,60,41,55" ViewboxUnits="Absolute"
      Stretch="Fill"/>
    <ImageBrush x:Key="aladin12" ImageSource="aladin-atlas.png" Viewbox="2,62,37,57" ViewboxUnits="Absolute"
      Stretch="Fill"/>

</ResourceDictionary>
For something like a static set of icons (not a running character where the image changes very quickly), would you recommend instead to just create the imagebrush at runtime, when you show the icon?

In my case, I have a quickbar of skills you choose in mind. I would only be showing a small amount at one time, but the total I have to choose from may be in the hundreds.

Re: Question about Texture Atlases

Posted: 15 Jan 2014, 15:00
by sfernandez
Unless you have memory problems by defining all the ImageBrushes in one or more ResourceDictionaries, this is the recommended way of using an image atlas.

The alternative would require you to define, in a ResourceDictionary, a ImageSource for each image atlas texture, and use it to create in runtime the ImageBrushes and setting the ImageSource and Viewbox properties manually.