This project is read-only.
ImageGenerator is like the TileImageGenerator, but allows different image sizes. This code generates a PNG image with blue background and 4 elements on random places:
var uris = new List<UriWithTransform>
{
   new UriWithTransform{ Uri =new Uri("Images/2.png", UriKind.Relative), Height=300, Width=300, TranslateTransform=new TranslateTransform()},
   new UriWithTransform{ Uri =new Uri("Images/5.png", UriKind.Relative), Height=73, Width=100, TranslateTransform=new TranslateTransform() { X=GenerateRandInt(),Y=GenerateRandInt()}},
    new UriWithTransform{ Uri =new Uri("Images/6.png", UriKind.Relative), Height=33, Width=33, TranslateTransform=new TranslateTransform() { X=GenerateRandInt(),Y=GenerateRandInt()}},
    new UriWithTransform{ Uri =new Uri("Images/5.png", UriKind.Relative), Height=73, Width=100, TranslateTransform=new TranslateTransform() { X=GenerateRandInt(),Y=GenerateRandInt()}},
    new UriWithTransform{ Uri =new Uri("Images/6.png", UriKind.Relative), Height=33, Width=33, TranslateTransform=new TranslateTransform() { X=GenerateRandInt(),Y=GenerateRandInt()}},
};
var uri = ImageGenerator.GenerateImage(uris.Select(ImageGenerator.UriToImage), "SampleImage.png", 300, 300);

byte[] data;
using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
   using (var isfs = isf.OpenFile(uri.LocalPath, FileMode.Open, FileAccess.Read))
   {
      data = new byte[isfs.Length];
      isfs.Read(data, 0, data.Length);
      isfs.Close();
   }
}

BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(new MemoryStream(data));
imageContainer.Source = bitmapImage;

Last edited Oct 11, 2012 at 7:19 PM by ad1Dima, version 5

Comments

No comments yet.