private async void ImageButton_Clicked_2(object sender, EventArgs e) { if (loading.Count == 0) { isRunning = true; string fileName = await DisplayPromptAsync("Save", "What would you like the file name to be?", "OK", "Cancel", "File Name"); //Gives option to save file with a custom name on photo gallery if (fileName != null && fileName != "" && fileName != "Cancel" && fileName != "OK") { option = await DisplayActionSheet("Quality", null, null, "Custom", "Max High", "Ultra High", "High", "Medium", "Low", "Very Low"); Option_Check(); cancel = false; canvasImage.IsVisible = true; canvasImageFast.IsVisible = false; loading.Add("Loading . . . "); double ri; double ci; double l; string downloadMacro; string downloadMicro; if (AdvancedModes.createAdvanced) { downloadMacro = AdvancedModes.macroInput; downloadMicro = AdvancedModes.microInput; ri = AdvancedModes.realInput; ci = AdvancedModes.complexInput; l = AdvancedModes.lengthInput; } else { downloadMacro = selectedColor; downloadMicro = selecterColorMicro; if (item <= 12) { ri = varList1[item]; ci = varList2[item]; l = varList3[item]; } else { ri = SavedFractals[item - 13].SavedReal; ci = SavedFractals[item - 13].SavedComplex; l = SavedFractals[item - 13].SavedLength; } } //Making 2x2 array with size height export and width export Complex complix; Pixel[,] picture = new Pixel[heightExport, widthExport]; int a; int b; //Setting format to Jpeg SKEncodedImageFormat imageFormat = SKEncodedImageFormat.Jpeg; int quality = 100; //For loop with calculations, every column calulated between loading changes //i goes up by the length value to make proportional for (double i = ri * heightExport; i < (ri + l) * heightExport; i += l) { if (cancel) { break; } Loading(); for (double j = ci * widthExport; j < (ci + l) * widthExport; j += l) { if (cancel) { break; } //setting shift of and position a = (int)((i - ri * heightExport) / l); b = (int)((j - ci * widthExport) / l); complix = new Complex((i - (14 * heightExport / 20.0)) / (widthExport / 3.0), (j - (widthExport / 2.0)) / (heightExport / 3.0 * widthExport / heightExport)); int onoff = (int)(Iterate(complix) * 255); updatePixelInputs(downloadMacro, downloadMicro, onoff); picture[a, b] = new Pixel(intInput1, intInput2, intInput3); //Sets individual pixels if (picture[a, b] == null) { picture[a, b] = new Pixel(0, 0, 0); SKColor colorPixelNull = new SKColor((byte)picture[a, b].GetRed(), (byte)picture[a, b].GetGreen(), (byte)picture[a, b].GetBlue()); bitmap.SetPixel(a, b, colorPixelNull); } else { SKColor colorPixel = new SKColor((byte)picture[a, b].GetRed(), (byte)picture[a, b].GetGreen(), (byte)picture[a, b].GetBlue()); bitmap.SetPixel(a, b, colorPixel); } } //Saves image every column using (MemoryStream memStream = new MemoryStream()) using (SKManagedWStream wstream = new SKManagedWStream(memStream)) { bitmap.Encode(wstream, imageFormat, quality); byte[] data = memStream.ToArray(); if (data != null && data.Length != 0) { await DependencyService.Get <IPhotoLibrary>(). SavePhotoAsync(data, "SaveFileFormats", fileName + ".Jpeg"); } } } cancel = false; } heightExport = (int)(Settings.QualityOptions[0].Quality); widthExport = (int)(Settings.QualityOptions[0].Quality); if (loading.Count != 0) { loading.RemoveAt(0); } isRunning = false; } }
public async void GenerateMandelbrotZoom(double ri, double ci, double l, string macroColor, string microColor) { if (loading.Count == 0) { isRunning = true; cancel = false; canvasImage.IsVisible = false; loading.Add("Loading . . . "); bitmapFast = new SKBitmap(widthExport, heightExport, true); canvasImageFast.IsVisible = true; cancel = false; //Making 2x2 array with size height export and width export Complex complix; Pixel[,] picture = new Pixel[widthExport, heightExport]; int a; int b; //Setting format to Jpeg SKEncodedImageFormat imageFormat = SKEncodedImageFormat.Jpeg; int quality = 100; //For loop with calculations, every column calulated between loading changes //i goes up by the length value to make proportional for (double i = ri * widthExport; i < (ri + l) * widthExport; i += l) { if (cancel) { break; } for (double j = ci * heightExport; j < (ci + l) * heightExport; j += l) { if (cancel) { break; } //setting shift of and position a = (int)((i - ri * widthExport) / l); b = (int)((j - ci * heightExport) / l); complix = new Complex((i - (14 * heightExport / 20.0)) / (widthExport / 3.0), (j - (widthExport / 2.0)) / (heightExport / 3.0 * widthExport / heightExport)); int onoff = (int)(Iterate(complix) * 255); updatePixelInputs(macroColor, microColor, onoff); picture[a, b] = new Pixel(intInput1, intInput2, intInput3); //Sets individual pixels if (picture[a, b] == null) { picture[a, b] = new Pixel(0, 0, 0); SKColor colorPixelNull = new SKColor((byte)picture[a, b].GetRed(), (byte)picture[a, b].GetGreen(), (byte)picture[a, b].GetBlue()); bitmapFast.SetPixel(a, b, colorPixelNull); } else { SKColor colorPixel = new SKColor((byte)picture[a, b].GetRed(), (byte)picture[a, b].GetGreen(), (byte)picture[a, b].GetBlue()); bitmapFast.SetPixel(a, b, colorPixel); } } //Saves image every column using (MemoryStream memStream = new MemoryStream()) using (SKManagedWStream wstream = new SKManagedWStream(memStream)) { bitmapFast.Encode(wstream, imageFormat, quality); byte[] data = memStream.ToArray(); if (data != null && data.Length != 0) { string fileName = null; await DependencyService.Get <IPhotoLibrary>(). SavePhotoAsync(data, "SaveFileFormats", fileName + ".Jpeg"); } } Loading(); } loading.RemoveAt(0); isRunning = false; } }