Created
November 22, 2011 21:28
-
-
Save nicwise/1387037 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Ignore] | |
public UIImage ExpenseImage | |
{ | |
get | |
{ | |
string basePath = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), "expenseimages"); | |
if (!Directory.Exists(basePath)) Directory.CreateDirectory(basePath); | |
string filename = Path.Combine (basePath, string.Format("{0}.jpg", Id)); | |
if (File.Exists(filename)) | |
{ | |
return UIImage.FromFile(filename); | |
} else return null; | |
} | |
} | |
[Ignore] | |
public bool HasImage | |
{ | |
get | |
{ | |
string basePath = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), "expenseimages"); | |
if (!Directory.Exists(basePath)) return false; | |
string filename = Path.Combine (basePath, string.Format("{0}.jpg", Id)); | |
return File.Exists(filename); | |
} | |
} | |
[Ignore] | |
public string ImageFilename | |
{ | |
get | |
{ | |
string basePath = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), "expenseimages"); | |
return Path.Combine (basePath, string.Format("{0}.jpg", Id)); | |
} | |
} | |
[Ignore] | |
public void DeleteImage() | |
{ | |
if (HasImage) | |
{ | |
try { | |
if (File.Exists(ImageFilename)) File.Delete(ImageFilename); | |
} catch { | |
Util.Log("Tried to delete image {0}, but it failed {1}.", Id, ImageFilename); | |
} | |
} | |
} | |
[Ignore] | |
public NSData ImageData = null; | |
[Ignore] | |
public void SaveImageData() | |
{ | |
if (ImageData != null) | |
{ | |
string basePath = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), "expenseimages"); | |
if (!Directory.Exists(basePath)) Directory.CreateDirectory(basePath); | |
NSError error; | |
ImageData.Save(Path.Combine (basePath, string.Format("{0}.jpg", Id)), false, out error); | |
} | |
} | |
public NSData AsJPEG | |
{ | |
get | |
{ | |
//CurrentImage is a UIImage | |
return CurrentImage.AsJPEG(StockImages.JPEGQuality); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment