本文整理汇总了C#中UIImage.AsJPEG方法的典型用法代码示例。如果您正苦于以下问题:C# UIImage.AsJPEG方法的具体用法?C# UIImage.AsJPEG怎么用?C# UIImage.AsJPEG使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIImage
的用法示例。
在下文中一共展示了UIImage.AsJPEG方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeImage
NSData SerializeImage (UIImage image, string typeIdentifier)
{
if (typeIdentifier == "public.png")
return image.AsPNG ();
return image.AsJPEG (JpegCompressionQuality);
}
示例2: AsImage
public static DumpValue AsImage(UIImage image)
{
var data = image.AsJPEG(0.6f);
var dataBytes = new byte[data.Length];
System.Runtime.InteropServices.Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length));
return new DumpValue { TypeName = "___IMAGE___", DumpType = DumpValue.DumpTypes.Image, PrimitiveValue = Convert.ToBase64String(dataBytes) };
}
示例3: HandleImagePick
private void HandleImagePick(UIImage image, int maxPixelDimension, int percentQuality,
Action<Stream> pictureAvailable, Action assumeCancelled)
{
if (image != null)
{
// resize the image
image = image.ImageToFitSize (new SizeF (maxPixelDimension, maxPixelDimension));
using (NSData data = image.AsJPEG ((float)((float)percentQuality/100.0)))
{
var byteArray = new byte [data.Length];
Marshal.Copy (data.Bytes, byteArray, 0, Convert.ToInt32 (data.Length));
var imageStream = new MemoryStream ();
imageStream.Write (byteArray, 0, Convert.ToInt32 (data.Length));
imageStream.Seek (0, SeekOrigin.Begin);
pictureAvailable (imageStream);
}
}
else
{
assumeCancelled ();
}
_picker.DismissModalViewControllerAnimated(true);
_presenter.NativeModalViewControllerDisappearedOnItsOwn();
}
示例4: SaveImageToTemporaryFileJpeg
public async Task<string> SaveImageToTemporaryFileJpeg(UIImage image, float quality = 1.0f)
{
var uniqueFileNamePortion = Guid.NewGuid().ToString();
var temporaryImageFileName = string.Format("{0}.jpg", uniqueFileNamePortion);
var documentsFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var temporaryStorageFolderPath = Path.Combine(documentsFolderPath, "..", "tmp");
var temporaryImageFilePath = Path.Combine(temporaryStorageFolderPath, temporaryImageFileName);
var imageData = image.AsJPEG(quality);
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;
}
示例5: ImageToByteArray
public static void ImageToByteArray(UIImage image, out byte[] mediaByteArray)
{
using (NSData imgData = image.AsJPEG ())
{
mediaByteArray = new byte[imgData.Length];
System.Runtime.InteropServices.Marshal.Copy (imgData.Bytes, mediaByteArray, 0, Convert.ToInt32 (imgData.Length));
}
image.Dispose ();
}
示例6: getSignatureString
private string getSignatureString(UIImage signatureImage)
{
NSData signatureData = signatureImage.AsJPEG();
Byte[] signatureByteArray = new byte[signatureData.Length];
System.Runtime.InteropServices.Marshal.Copy (signatureData.Bytes, signatureByteArray, 0, Convert.ToInt32 (signatureData.Length));
return System.Convert.ToBase64String(signatureByteArray);
}
示例7: ExportToJpg
public static byte[] ExportToJpg(UIImage image)
{
using (NSData data = image.AsJPEG(1)) {
byte[] binaryData = new byte[data.Length];
// Copy the unmanaged data hold by the NSData to a new managed byte array.
System.Runtime.InteropServices.Marshal.Copy(data.Bytes, binaryData, 0, (int)data.Length);
return binaryData;
}
}
示例8: FinishedPickingImage
public override void FinishedPickingImage(UIImagePickerController picker, UIImage image, NSDictionary editingInfo)
{
// Here you can do anything with the image... save for example.
var documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string jpgFilename = System.IO.Path.Combine(documentsDirectory, string.Format("{0}.jpg", Guid.NewGuid()));
using (NSData imageData = image.AsJPEG(0.2f))
{
NSError err;
if (!imageData.Save(jpgFilename, false, out err))
{
Console.WriteLine("Saving of file failed: " + err.Description);
}
}
}
示例9: 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 ());
}
}
示例10: SendTo
/// <summary>
/// Sends the specified UIImage to the AirPlay device.
/// </summary>
/// <param name='service'>
/// NSNetService (extension method target) representing the AirPlay device.
/// </param>
/// <param name='image'>
/// The UIImage to be send to the device.
/// </param>
/// <param name='complete'>
/// Optional method to be called when the operation is complete. True will be supplied if the action was
/// successful, false if a problem occured.
/// </param>
public static unsafe void SendTo(this NSNetService service, UIImage image, Action<bool> complete)
{
if (service == null) {
if (complete != null)
complete (false);
return;
}
// In general I prefer WebClient *Async methods but it does not provide methods to
// upload Stream and allocating a (not really required) byte[] is a huge waste
ThreadPool.QueueUserWorkItem (delegate {
bool ok = true;
try {
string url = String.Format ("http://{0}:{1}/photo", service.HostName, service.Port);
HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url);
using (var data = image.AsJPEG ()) {
req.Method = "PUT";
req.ContentLength = data.Length;
req.UserAgent = "AirPlay/160.4 (Photos)";
req.Headers.Add ("X-Apple-AssetKey", Guid.NewGuid ().ToString ());
req.Headers.Add ("X-Apple-Session-ID", session.ToString ());
var s = req.GetRequestStream ();
using (Stream ums = new UnmanagedMemoryStream ((byte *) data.Bytes, data.Length))
ums.CopyTo (s);
}
req.GetResponse ().Dispose ();
}
catch {
ok = false;
}
finally {
if (complete != null) {
NSRunLoop.Main.InvokeOnMainThread (delegate {
complete (ok);
});
}
}
});
}
示例11: GetImageIntoCache
public void GetImageIntoCache(NSAction doWhenDone)
{
if (image == null)
{
if (CachedThumbExists(Program.ProgramId))
{
image = UIImage.FromFileUncached(CachedThumbFullpath(Program.ProgramId));
} else
{
using (NSData imgData = NSData.FromUrl(new NSUrl(Program.ThumbnailUrl)))
{
using (UIImage tempimage = UIImage.LoadFromData(imgData))
{
image = ImageHelper.ResizeImage(tempimage, -1, 35);
NSData data = image.AsJPEG();
NSError error;
data.Save(CachedThumbFullpath(Program.ProgramId), false, out error);
}
}
}
}
doWhenDone();
}
示例12: 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();
}
示例13: SaveImage
public void SaveImage(UIImage image)
{
_imagePicked = true;
string filepath = Path.Combine(Environment.GetFolderPath (Environment.SpecialFolder.Personal), _filename);
using (NSData imageData = image.AsJPEG())
{
NSError err = new NSError();
imageData.Save(filepath, true, out err);
}
imageView.Image = image;
loadView.StopAnimating();
InitBarButtons();
_callback(this);
this.DismissModalViewControllerAnimated(true);
}
示例14: save
void save()
{
using (new NSAutoreleasePool())
{
NSError error = new NSError();
selectedImage = Graphics.PrepareForUpload(selectedImage);
selectedImage.AsJPEG().Save(Path.Combine(Util.PicDir,Value),NSDataWritingOptions.Atomic,out error);
NSObject invoker = new NSObject();
invoker.InvokeOnMainThread(delegate {
completed();
});
}
}
示例15: SendImage
private async void SendImage(UIImage image)
{
try
{
using (ISitecoreWebApiSession session = this.instanceSettings.GetSession())
{
Stream stream = image.AsJPEG().AsStream();
var request = ItemWebApiRequestBuilder.UploadResourceRequestWithParentPath(itemPathTextField.Text)
.ItemDataStream(stream)
.ContentType("image/jpg")
.ItemName(this.itemNameTextField.Text)
.FileName("imageFile.jpg")
.Build();
this.ShowLoader();
var response = await session.UploadMediaResourceAsync(request);
if (response != null)
{
AlertHelper.ShowAlertWithOkOption("upload image result","The image uploaded successfuly");
}
else
{
AlertHelper.ShowAlertWithOkOption("upload image result","something wrong");
}
}
}
catch(Exception e)
{
AlertHelper.ShowLocalizedAlertWithOkOption("Error", e.Message);
}
finally
{
BeginInvokeOnMainThread(delegate
{
this.HideLoader();
});
}
}