本文整理汇总了C#中Android.Graphics.Bitmap.Compress方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.Compress方法的具体用法?C# Bitmap.Compress怎么用?C# Bitmap.Compress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Graphics.Bitmap
的用法示例。
在下文中一共展示了Bitmap.Compress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PutBitmapToCacheByUrl
public static bool PutBitmapToCacheByUrl (string url, Bitmap bitmap, Context ctx)
{
var imagePath = GetCachePathForUrl (url, "UserImages", ctx);
try {
Directory.CreateDirectory (FilePath.GetDirectoryName (imagePath));
using (var fileStream = new FileStream (imagePath + ".png", FileMode.Create)) {
bitmap.Compress (Bitmap.CompressFormat.Png, 90, fileStream);
}
return true;
} catch (IOException ex) {
var log = ServiceContainer.Resolve<ILogger> ();
if (ex.Message.StartsWith ("Sharing violation on")) {
// Treat FAT filesystem related failure as expected behaviour
log.Info (LogTag, ex, "Failed to save bitmap to cache.");
} else {
log.Warning (LogTag, ex, "Failed to save bitmap to cache.");
}
return false;
} catch (Exception ex) {
var log = ServiceContainer.Resolve<ILogger> ();
log.Warning (LogTag, ex, "Failed to save bitmap to cache.");
return false;
}
}
示例2: CreateTask
/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
public static Couchbase.Lite.Document CreateTask(Database database, string title,
Bitmap image, string listId)
{
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
);
Calendar calendar = GregorianCalendar.GetInstance();
string currentTimeString = dateFormatter.Format(calendar.GetTime());
IDictionary<string, object> properties = new Dictionary<string, object>();
properties.Put("type", DocType);
properties.Put("title", title);
properties.Put("checked", false);
properties.Put("created_at", currentTimeString);
properties.Put("list_id", listId);
Couchbase.Lite.Document document = database.CreateDocument();
UnsavedRevision revision = document.CreateRevision();
revision.SetUserProperties(properties);
if (image != null)
{
ByteArrayOutputStream @out = new ByteArrayOutputStream();
image.Compress(Bitmap.CompressFormat.Jpeg, 50, @out);
ByteArrayInputStream @in = new ByteArrayInputStream(@out.ToByteArray());
revision.SetAttachment("image", "image/jpg", @in);
}
revision.Save();
return document;
}
示例3: ByteArrayFromImage
public static byte[] ByteArrayFromImage(Bitmap bmp)
{
using (var stream = new MemoryStream())
{
bmp.Compress(Bitmap.CompressFormat.Png, 0, stream);
return stream.ToArray();
}
}
示例4: getBytes
static private byte[] getBytes(Bitmap b)
{
using (var stream = new MemoryStream())
{
b.Compress(Bitmap.CompressFormat.Png, 0, stream);
return stream.ToArray();
}
}
示例5: BitmapToBase64String
public static String BitmapToBase64String(Bitmap originalImage)
{
MemoryStream ms = new MemoryStream();
originalImage.Compress(Bitmap.CompressFormat.Png, 100, ms);
byte[] imageData = ms.ToArray();
originalImage.Dispose();
return Base64.EncodeToString(imageData, Base64Flags.NoWrap);
}
示例6: WriteBmp
public static void WriteBmp( Bitmap bmp, Stream dst )
{
#if !ANDROID
bmp.Save( dst, ImageFormat.Png );
#else
bmp.Compress( Bitmap.CompressFormat.Png, 100, dst );
#endif
}
示例7: AsImage
public static DumpValue AsImage(Bitmap image)
{
byte[] dataBytes;
using (var stream = new MemoryStream())
{
image.Compress(Bitmap.CompressFormat.Jpeg, 60, stream);
dataBytes = stream.ToArray();
}
return new DumpValue { TypeName = "___IMAGE___", DumpType = DumpValue.DumpTypes.Image, PrimitiveValue = Convert.ToBase64String(dataBytes) };
}
示例8: SaveBitmap
private File SaveBitmap(Bitmap b)
{
string filename = string.Format("{0}MyFile{1:HH_mm_s}.jpg", DIRECTORY_PATH, DateTime.Now);
File f = new File(filename);
using (System.IO.FileStream fs = new System.IO.FileStream(f.AbsolutePath, System.IO.FileMode.OpenOrCreate))
{
b.Compress(Bitmap.CompressFormat.Jpeg, 9, fs);
return f;
}
}
示例9: UploadImage
public async Task<string> UploadImage(Bitmap bitmap)
{
var uploadVM = new UploadViewModel();
var stream = new MemoryStream();
bitmap.Compress(Bitmap.CompressFormat.Png, 0, stream);
uploadVM.PictureStream = stream;
uploadVM.ImageIdentifier = Guid.NewGuid() + ".bmp";
await azureStorageService.UploadPicture(uploadVM);
return string.Format("{0}{1}", AndroidPollImageViewModel.PollPicturesUrlBase, uploadVM.ImageIdentifier);
}
示例10: WriteToFile
public static void WriteToFile(Bitmap bitmap)
{
try
{
var outFile = new MemoryStream();
bitmap.Compress(Bitmap.CompressFormat.Png, 90, outFile);
outFile.Position = 0;
var path = Path.Combine("/sdcard/Download", "test.png");
var otherPath = Path.Combine(Application.Context.GetExternalFilesDir("unit_test_images").AbsolutePath, "test.png");
var fos = new FileStream(otherPath, FileMode.OpenOrCreate);
fos.Write(outFile.ToArray(), 0, (int)outFile.Length);
fos.Flush();
fos.Close();
}
catch (Exception)
{
Console.WriteLine("fout!");
}
}
示例11: SaveImage
public async Task<bool> SaveImage(ImageSource img, string imageName)
{
try
{
var renderer = new StreamImagesourceHandler();
imagem = await renderer.LoadImageAsync(img, Forms.Context);
var documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string pngPath = System.IO.Path.Combine(documentsDirectory, imageName + ".png");
using (System.IO.FileStream fs = new System.IO.FileStream(pngPath, System.IO.FileMode.OpenOrCreate))
{
imagem.Compress(Bitmap.CompressFormat.Png, 100, fs);
return await Task.FromResult<bool>(true);
}
}
catch (Exception)
{
return await Task.FromResult<bool>(false);
}
}
示例12: ImageData
public ImageData (Bitmap image, string filename)
{
if (image == null) {
throw new ArgumentNullException ("image");
}
if (string.IsNullOrEmpty (filename)) {
throw new ArgumentException ("filename");
}
Image = image;
Filename = filename;
var compressFormat = Bitmap.CompressFormat.Jpeg;
MimeType = "image/jpeg";
if (filename.ToLowerInvariant ().EndsWith (".png")) {
MimeType = "image/png";
compressFormat = Bitmap.CompressFormat.Png;
}
var stream = new MemoryStream ();
image.Compress (compressFormat, 100, stream);
stream.Position = 0;
Data = stream;
}
示例13: saveOutput
private void saveOutput(Bitmap croppedImage)
{
if (saveUri != null)
{
try
{
using (var outputStream = ContentResolver.OpenOutputStream(saveUri))
{
if (outputStream != null)
{
croppedImage.Compress(outputFormat, 75, outputStream);
}
}
}
catch (Exception ex)
{
Log.Error(this.GetType().Name, ex.Message);
}
Bundle extras = new Bundle();
SetResult(Result.Ok, new Intent(saveUri.ToString())
.PutExtras(extras));
}
else
{
Log.Error(this.GetType().Name, "not defined image url");
}
croppedImage.Recycle();
Finish();
}
示例14: WriteBitmapToCache
/// <summary>
/// Writes the bitmap to cache.
/// </summary>
/// <param name="bitmap">Current bitmap.</param>
/// <param name="position">Position.</param>
private void WriteBitmapToCache(Bitmap bitmap, int position)
{
if (bitmap != null)
{
try
{
using (Stream outputStream = File.Create(this.GetCacheFileName(position)))
{
// tune it for better results
bitmap.Compress(Bitmap.CompressFormat.Png, 90, outputStream);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
示例15: AttachImage
/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
public static void AttachImage(Couchbase.Lite.Document task, Bitmap image)
{
if (task == null || image == null)
{
return;
}
UnsavedRevision revision = task.CreateRevision();
ByteArrayOutputStream @out = new ByteArrayOutputStream();
image.Compress(Bitmap.CompressFormat.Jpeg, 50, @out);
ByteArrayInputStream @in = new ByteArrayInputStream(@out.ToByteArray());
revision.SetAttachment("image", "image/jpg", @in);
revision.Save();
}