private async Task RenderPlatform(Platform p, Color c, StorageFolder platformFolder) { foreach (LogoObject logoObject in p.SaveLogoList) { // ReSharper disable once PossibleLossOfFraction double ratio = (double)logoObject.Width / logoObject.Height; // ReSharper disable once PossibleLossOfFraction bool isCustom = ratio != ((double)620 / 300) && ratio != 1; if (isCustom) { RenderCustomImage(c, logoObject.Width, logoObject.Height); } else { RenderImage(c, logoObject.Width, logoObject.Height); } var savedFile = await platformFolder.CreateFileAsync(logoObject.FileName + ".scale-" + logoObject.Scale + ".png", CreationCollisionOption.ReplaceExisting); if (isCustom) { using (var outStream = await savedFile.OpenAsync(FileAccessMode.ReadWrite)) { await CustomRenderTarget.SaveAsync(outStream, CanvasBitmapFileFormat.Png); } continue; } if (logoObject.Width == logoObject.Height && IsManualAdjustSquareImage) { using (var outStream = await savedFile.OpenAsync(FileAccessMode.ReadWrite)) { await SRenderTarget.SaveAsync(outStream, CanvasBitmapFileFormat.Png); } } else { using (var outStream = await savedFile.OpenAsync(FileAccessMode.ReadWrite)) { await RenderTarget.SaveAsync(outStream, CanvasBitmapFileFormat.Png); } } } }
private void RenderImage(Color c, double width, double height) { double ratio = height / 300; var isSq = width == height; Vector2 vector2 = new Vector2((float)(ZoomF * ratio)); var effect = new Transform2DEffect { Source = UserBitmap, InterpolationMode = CanvasImageInterpolation.HighQualityCubic, TransformMatrix = Matrix3x2.CreateScale(vector2) }; if (isSq && IsManualAdjustSquareImage) { effect = new Transform2DEffect { Source = UserBitmap, InterpolationMode = CanvasImageInterpolation.HighQualityCubic, TransformMatrix = Matrix3x2.CreateScale(new Vector2((float)(SZoomF * ratio))) }; } //Render target: Main render if (isSq) { PlexibleX = X - 160; RenderTarget = new CanvasRenderTarget(_device, (float)(300 * ratio), (float)(300 * ratio), 96); if (IsManualAdjustSquareImage) { //Square SRenderTarget = new CanvasRenderTarget(_device, (float)(300 * ratio), (float)(300 * ratio), 96); } } else if (width > height) { RenderTarget = new CanvasRenderTarget(_device, (float)(620 * ratio), (float)(300 * ratio), 96); PlexibleX = X; } if (isSq && IsManualAdjustSquareImage) { using (var ds = SRenderTarget.CreateDrawingSession()) { //Clear the color ds.Clear(c); //Draw the user image to target ds.DrawImage(effect, (float)(SX * ratio), (float)(SY * ratio), new Rect(SRecX, SRecY, SRecW * ratio, SRecH * ratio), 1.0f, CanvasImageInterpolation.HighQualityCubic); } } else { using (var ds = RenderTarget.CreateDrawingSession()) { //Clear the color ds.Clear(c); //Draw the user image to target ds.DrawImage(effect, (float)(PlexibleX * ratio), (float)(Y * ratio), new Rect(RecX, RecY, RecW * ratio, RecH * ratio), 1.0f, CanvasImageInterpolation.HighQualityCubic); } } }