本文整理汇总了C#中UIImage.AsPNG方法的典型用法代码示例。如果您正苦于以下问题:C# UIImage.AsPNG方法的具体用法?C# UIImage.AsPNG怎么用?C# UIImage.AsPNG使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIImage
的用法示例。
在下文中一共展示了UIImage.AsPNG方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveImageToTemporaryFilePng
/// <summary>
/// Saves the image to temporary file in png format.
/// </summary>
/// <returns>Path to temporary file representing image provide as paramater</returns>
/// <param name="image">The image to be saved to a tempoarary png file</param>
public async Task<string> SaveImageToTemporaryFilePng(UIImage image)
{
var uniqueFileNamePortion = Guid.NewGuid().ToString();
var temporaryImageFileName = string.Format("{0}.png", uniqueFileNamePortion);
var documentsFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var temporaryStorageFolderPath = Path.Combine(documentsFolderPath, "..", "tmp");
var temporaryImageFilePath = Path.Combine(temporaryStorageFolderPath, temporaryImageFileName);
var imageData = image.AsPNG();
await Task.Run(() =>
{
//File.WriteAllBytes(temporaryImageFilePath, imageData);
NSError error = null;
if (imageData.Save(temporaryImageFilePath, false, out error))
{
Console.WriteLine("Saved image to temporary file: " + temporaryImageFilePath);
} else
{
Console.WriteLine("ERROR! Did NOT SAVE file because" + error.LocalizedDescription);
}
});
return temporaryImageFilePath;
}
示例2: SerializeImage
NSData SerializeImage (UIImage image, string typeIdentifier)
{
if (typeIdentifier == "public.png")
return image.AsPNG ();
return image.AsJPEG (JpegCompressionQuality);
}
示例3: UploadImage
private CloudBlockBlob UploadImage(UIImage image, String name)
{
var client = GetClient ();
var container = client.GetContainerReference("images");
container.CreateIfNotExists();
var blob = container.GetBlockBlobReference(name);
var pngImage = image.AsPNG ();
var stream = pngImage.AsStream();
blob.UploadFromStream (stream);
return blob;
}
示例4: ImageData
public ImageData (UIImage image, string filename)
{
if (image == null) {
throw new ArgumentNullException ("image");
}
if (string.IsNullOrEmpty (filename)) {
throw new ArgumentException ("filename");
}
Image = image;
Filename = filename;
MimeType = (filename.ToLowerInvariant ().EndsWith (".png")) ?
"image/png" : "image/jpeg";
if (MimeType == "image/png") {
Data = new NSDataStream (image.AsPNG ());
}
else {
Data = new NSDataStream (image.AsJPEG ());
}
}
示例5: AddToCache
internal void AddToCache(string id, UIImage img)
{
string file = picDir + GenerateMD5 (id) + ".png";
if (!File.Exists(file))
{
//Save it to disk
NSError err = null;
try
{
img.AsPNG().Save(file, false, out err);
if (err != null)
Console.WriteLine(err.Code.ToString() + " - " + err.LocalizedDescription);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
}
}
示例6: OpenLine
/// <summary>
/// Opens the line.
/// </summary>
/// <returns><c>true</c>, if line was opened, <c>false</c> otherwise.</returns>
/// <param name="image">Image.</param>
public static bool OpenLine(UIImage image)
{
if (!CanOpenLine())
return false;
var pasteboard = UIPasteboard.GetUnique();
pasteboard.SetData(image.AsPNG(), "public.png");
var pasteboardName = pasteboard.Name;
var encoded = Uri.EscapeDataString(pasteboardName);
var url = CreateNSUrl(LineUrlContentTypes.Image, encoded);
var shareApp = UIApplication.SharedApplication;
return shareApp.OpenUrl(url);
}
示例7: Save
public void Save(string path, ImageFormat format)
{
if (path == null)
throw new ArgumentNullException ("path");
if (NativeCGImage == null)
throw new ObjectDisposedException ("cgimage");
using (var uiimage = new UIImage (NativeCGImage)){
NSError error;
if (format == ImageFormat.Jpeg){
using (var data = uiimage.AsJPEG ()){
if (data.Save (path, NSDataWritingOptions.Atomic, out error))
return;
throw new IOException ("Saving the file " + path + " " + error);
}
} else if (format == ImageFormat.Png){
using (var data = uiimage.AsPNG ()){
if (data.Save (path, NSDataWritingOptions.Atomic, out error))
return;
throw new IOException ("Saving the file " + path + " " + error);
}
} else
throw new ArgumentException ("Unsupported format, only Jpeg and Png are supported", "format");
}
}
示例8: AddToCache
/// <summary>
/// Adds to cache.
/// </summary>
/// <param name="id">Identifier.</param>
/// <param name="img">Image.</param>
internal void AddToCache(string id, UIImage img)
{
string cachedFilename = cachedImageDir + "/" + StringUtils.GenerateMD5 (id) + ".png";
if (!File.Exists (cachedFilename)) {
// save it to disk
NSError err = null;
try {
img.AsPNG ().Save (cachedFilename, false, out err);
if (err != null)
Console.WriteLine ("UrlImageStore: Error encoding file {0} to cache ({1} - {2})", cachedFilename, err.Code.ToString (), err.LocalizedDescription);
} catch (Exception ex) {
Console.WriteLine ("UrlImageStore: Error encoding file {0} to cache ({1})\n{2}", cachedFilename, ex.Message, ex.StackTrace);
}
}
}
示例9: Log
public void Log( string tag, int level, UIImage image )
{
if (image == null) {
throw new ArgumentNullException("image");
}
NSString ns_tag = null;
IntPtr ptr_tag = IntPtr.Zero;
if (tag != null) {
ns_tag = new NSString(tag);
ptr_tag = ns_tag.Handle;
}
using (ns_tag) {
using (var png = image.AsPNG()) {
LogImageData( logger, ptr_tag, level, (int) image.Size.Width, (int) image.Size.Height, png.Handle );
}
}
}
示例10: PostNewAvatar
void PostNewAvatar(UIImage image)
{
NSData data = image.AsPNG ();
byte[] dataBytes = new byte[data.Length];
System.Runtime.InteropServices.Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length));
Engine.Instance.AvatarAccess.PostNewAvatar (dataBytes, (result) => {
if (result.Exceptin != null)
{
_controller.BeginInvokeOnMainThread (delegate {
_controller.RefreshHeaderCell ();
});
}
});
}
示例11: SaveImage
public static string[] SaveImage(string name, UIImage ourpic)
{
if (ourpic == null)
return new string[2]{ "", "" };
Console.WriteLine ("Save");
UIImage thumbPic = ourpic.Scale (new SizeF (50, 50)); //measurements taken from CustomCell, alternatly 33x33
if (ourpic != null) {
var documentsDirectory = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
var picname = name + ".png";
var thumbpicname = name + "_thumb.png";
string pngfileName = System.IO.Path.Combine (documentsDirectory, picname);
string thumbpngfileName = System.IO.Path.Combine (documentsDirectory, thumbpicname);
NSData imgData = ourpic.AsPNG ();
NSData img2Data = thumbPic.AsPNG ();
NSError err = null;
if (imgData.Save (pngfileName, false, out err)) {
Console.WriteLine ("saved as " + pngfileName);
} else {
Console.WriteLine ("NOT saved as " + pngfileName + " because" + err.LocalizedDescription);
}
err = null;
if (img2Data.Save (thumbpngfileName, false, out err)) {
Console.WriteLine ("saved as " + thumbpngfileName);
string[] result = new string[2] { picname, thumbpicname };
return result;
} else {
Console.WriteLine ("NOT saved as " + thumbpngfileName + " because" + err.LocalizedDescription);
return null;
}
}
return new string[2]{ "", "" };
}
示例12: Save
public static void Save(string path, UIImage image)
{
if(File.Exists(path))
{
File.Delete(path);
}
NSError err = null;
image.AsPNG().Save(path, true, out err);
}
示例13: GetImageStream
// public override void TouchesBegan(NSSet touches, UIEvent evt) {
// base.TouchesBegan(touches, evt);
// if (this.onResult == null)
// this.DismissViewController(true, null);
// }
private static Stream GetImageStream(UIImage image, ImageFormatType formatType) {
if (formatType == ImageFormatType.Jpg)
return image.AsJPEG().AsStream();
return image.AsPNG().AsStream();
}
示例14: SaveTemporaly
private string SaveTemporaly(UIImage image)
{
if (string.IsNullOrEmpty(IMAGE_FILE_NAME))
{
DirectoryInfo tempDir = new DirectoryInfo(EnviromentDirectories.IOS_TEMP_DIRECTORY);
FileInfo[] tempFiles = tempDir.GetFiles();
IMAGE_FILE_NAME = string.Format("{0}({1}).png", TEMP_IMAGE_NAME, tempFiles.Length);
}
string tempImagePath = Path.Combine(EnviromentDirectories.IOS_TEMP_DIRECTORY, IMAGE_FILE_NAME);
NSData imageData = image.AsPNG();
NSError error = null;
imageData.Save(tempImagePath, false, out error);
return tempImagePath;
}