Ejemplo n.º 1
0
		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 ();
		}
Ejemplo n.º 2
0
        //Bitmap to byte[]
        public static async Task <byte[]> AndroidBitmapToByteArray(Android.Graphics.Bitmap bitmap)
        {
            byte[] rotated;
            using (var ms2 = new MemoryStream())
            {
                await bitmap.CompressAsync(CompressFormat.Jpeg, 50, ms2);//quality:0~100?

                rotated = ms2.ToArray();
            }

            return(rotated);
        }
        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;
        }
Ejemplo n.º 4
0
		protected async void exportBitmapAsPNG(Bitmap bitmap, string path)
		{
			using (var stream =  new FileStream(path, FileMode.Create))
			{
				await bitmap.CompressAsync(Bitmap.CompressFormat.Png, 100, stream);
			}
		}