本文整理汇总了C#中Android.Graphics.Bitmap.CompressAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.CompressAsync方法的具体用法?C# Bitmap.CompressAsync怎么用?C# Bitmap.CompressAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Graphics.Bitmap
的用法示例。
在下文中一共展示了Bitmap.CompressAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportBitmapAsJPG
public async void ExportBitmapAsJPG(Bitmap bitmap, int index)
{
string sdCardPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
string name = "_" + index.ToString () + ".jpg";
string filePath = System.IO.Path.Combine(sdCardPath, name);
var stream = new System.IO.FileStream(filePath, System.IO.FileMode.Create);
await bitmap.CompressAsync (Bitmap.CompressFormat.Jpeg, 30, stream);
stream.Close ();
}
示例2: UploadPhoto
public static async Task<bool> UploadPhoto(string listName, string imageName, Bitmap bitmap)
{
bool success = false;
try
{
string requestUrl = string.Format("{0}/_api/web/GetFolderByServerRelativeUrl('{1}')/Files/add(url='{2}',overwrite=true)", Constants.SHAREPOINT_URL + Constants.SHAREPOINT_SITE_PATH, listName, imageName);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
request.Method = "POST";
request.Accept = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5";
request.ContentType = "application/octet-stream";
request.Headers.Add("Authorization", "Bearer " + App.Token);
Stream requestStream = request.GetRequestStream();
MemoryStream outputStearm = new MemoryStream();
await bitmap.CompressAsync(Bitmap.CompressFormat.Jpeg, 100, outputStearm);
byte[] bytes = outputStearm.ToArray();
await requestStream.WriteAsync(bytes, 0, bytes.Length);
using (HttpWebResponse response = await request.GetResponseAsync() as HttpWebResponse)
{
if (response.StatusCode == HttpStatusCode.OK)
{
success = true;
}
}
}
catch (Exception)
{
success = false;
}
return success;
}
示例3: exportBitmapAsPNG
protected async void exportBitmapAsPNG(Bitmap bitmap, string path)
{
using (var stream = new FileStream(path, FileMode.Create))
{
await bitmap.CompressAsync(Bitmap.CompressFormat.Png, 100, stream);
}
}