private void WriteTextureToFile(string fileName) { if (originalTexture != null) { PhotoConverter.SaveImageAs(originalTexture, fileName); } }
private void SerializeGeneratedWorkaround(Material material, string masterFileName, List <string> supportFiles) { // This is method is needed because of this issue: // ( if (material is MaterialGroup) { foreach (Material m in ((MaterialGroup)material).Children) { SerializeGeneratedWorkaround(m, masterFileName, supportFiles); } } else { Brush brush = null; if (material is DiffuseMaterial) { DiffuseMaterial dm = (DiffuseMaterial)material; brush = dm.Brush; } else if (material is EmissiveMaterial) { EmissiveMaterial em = (EmissiveMaterial)material; brush = em.Brush; } else if (material is SpecularMaterial) { SpecularMaterial sm = (SpecularMaterial)material; brush = sm.Brush; } if (brush is ImageBrush) { ImageBrush ib = (ImageBrush)brush; // NOTE: Other forms of memory-generated bitmaps may need the same treatment. if (ib.ImageSource is CachedBitmap) { CachedBitmap cb = (CachedBitmap)ib.ImageSource; // Generate new file Name int fileIndex = supportFiles.Count; string fileName = masterFileName.Replace(".xaml", "_support_") + fileIndex.ToString() + ".png"; // Save as an image file (PNG to keep transparency) PhotoConverter.SaveImageAs(cb, fileName); // Remember the name supportFiles.Add(fileName); // Now replace this in the old brush ib.ImageSource = new BitmapImage(new Uri(fileName, UriKind.RelativeOrAbsolute)); ib.ViewboxUnits = BrushMappingMode.RelativeToBoundingBox; } } // The default case is for this to be a NO-OP } }