|
using System;
using System.IO;
using System.Windows.Media.Imaging;
namespace MediaAssistant.DAL.Helper
{
public class ConvertTo
{
public static string String(TimeSpan timeSpan)
{
var totalSeconds = Math.Abs(timeSpan.TotalSeconds);
var totalMinutes = Math.Abs(timeSpan.TotalMinutes);
var hours = Math.Abs(timeSpan.TotalHours);
if (totalSeconds > 0)
{
var seconds = Convert.ToInt16(totalSeconds%60);
var minutes = Convert.ToInt16(totalMinutes%60);
var totalHours = Convert.ToInt32(hours);
var text = System.String.Empty;
if (timeSpan.TotalMilliseconds < 0)
text += "-";
if (totalHours > 0)
text += System.String.Format("{0:00}:", totalHours);
text += System.String.Format("{0:00}:{1:00}", minutes, seconds);
return text;
}
return "00:00";
}
public static BitmapImage BitmapImage(byte[] bytes)
{
try
{
if (bytes == null || bytes.Length == 0)
return null;
var bmp = new BitmapImage();
bmp.BeginInit();
bmp.StreamSource = new MemoryStream(bytes);
bmp.EndInit();
return bmp;
}
catch (Exception)
{
return null;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.