当前位置: 首页>>代码示例>>C#>>正文


C# Bitmap.Compress方法代码示例

本文整理汇总了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;
            }
        }
开发者ID:VDBBjorn,项目名称:toggl_mobile,代码行数:25,代码来源:CachingUtil.cs

示例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;
 }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:27,代码来源:Task.cs

示例3: ByteArrayFromImage

		public static byte[] ByteArrayFromImage(Bitmap bmp)
		{
			using (var stream = new MemoryStream())
			{
				bmp.Compress(Bitmap.CompressFormat.Png, 0, stream);
				return stream.ToArray();
			}
		}
开发者ID:natevarghese,项目名称:XamarinTen,代码行数:8,代码来源:ImageUtils.cs

示例4: getBytes

		static private byte[] getBytes(Bitmap b)
		{
			using (var stream = new MemoryStream())
			{
				b.Compress(Bitmap.CompressFormat.Png, 0, stream);
				return stream.ToArray();
			}
		}
开发者ID:billy-lokal,项目名称:Dateifi_Old,代码行数:8,代码来源:ProfileFragment.cs

示例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);
		}
开发者ID:sourcefile,项目名称:OrdinaCompetitie,代码行数:8,代码来源:ImageUtil.cs

示例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
 }
开发者ID:Chameleonherman,项目名称:ClassicalSharp,代码行数:8,代码来源:Platform.cs

示例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) };
 }
开发者ID:tluyben,项目名称:ProtoPad,代码行数:10,代码来源:ObjectDumper.cs

示例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;
            }
        }
开发者ID:adbk,项目名称:spikes,代码行数:11,代码来源:Activity1.cs

示例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);
		}
开发者ID:kamilkk,项目名称:MyVote,代码行数:14,代码来源:AndroidPollImageViewModelBase.cs

示例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!");
            }

        }
开发者ID:jdeksup,项目名称:Mapsui.Net4,代码行数:20,代码来源:TestsSample.cs

示例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);
            }
        }
开发者ID:jbravobr,项目名称:Mais-XamForms,代码行数:21,代码来源:SaveAndLoadFile_Droid.cs

示例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;
		}
开发者ID:stampsy,项目名称:Xamarin.Social,代码行数:25,代码来源:ImageData.cs

示例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();
        }
开发者ID:kevinrood,项目名称:cropimage-xamarin,代码行数:30,代码来源:CropImage.cs

示例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);
         }
     }
 }
开发者ID:baitun,项目名称:BGUEP-Journal,代码行数:23,代码来源:EasyPagerAdapter.cs

示例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();
 }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:14,代码来源:Task.cs


注:本文中的Android.Graphics.Bitmap.Compress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。