private async void ScaleRainbowButton_Click(object sender, RoutedEventArgs e) { SoftwareBitmap tempSB; double scale = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel; int renderTB_Width = 200; int renderTB_Height = 100; int newWidth = g704_softwareBitmap.PixelWidth; int newHeight = g704_softwareBitmap.PixelHeight; // Step 1 : // Create RenderTargetBitmap by ColorRectangle. // Don't worry about both width and height of ColorRectangle. RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(); ColorRectangle.Fill = MyColorHelper.GetRainbowBrush(); await renderTargetBitmap.RenderAsync(ColorRectangle, renderTB_Width, renderTB_Height); // Step 2 : // Get IBuffer from RenderTargetBitmap, IBuffer ib = await renderTargetBitmap.GetPixelsAsync(); // Step 3 : // Create a temporary SoftwareBitmap which is based on current scale tempSB = SoftwareBitmap.CreateCopyFromBuffer(ib, BitmapPixelFormat.Bgra8, (int)(renderTB_Width * scale), (int)(renderTB_Height * scale)); tempSB = SoftwareBitmap.Convert(tempSB, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); // Step 4 : // Adjust to the same size as g704 image tempSB = Resize(tempSB, newWidth, newHeight); // Step 5 : // Assign this temp image pixels to g704 image g704_softwareBitmap = SoftwareBitmap.Convert(g704_softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight); AssignPixelValues(g704_softwareBitmap, tempSB); g704_softwareBitmap = SoftwareBitmap.Convert(g704_softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); var source = new SoftwareBitmapSource(); await source.SetBitmapAsync(g704_softwareBitmap); G704.Source = source; }
private async void RainbowButton_Click(object sender, RoutedEventArgs e) { int width = g704_softwareBitmap.PixelWidth; int height = g704_softwareBitmap.PixelHeight; RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(); ColorRectangle.Fill = MyColorHelper.GetRainbowBrush(); await renderTargetBitmap.RenderAsync(ColorRectangle, width, height); g704_softwareBitmap = SoftwareBitmap.Convert(g704_softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight); IBuffer ib = await renderTargetBitmap.GetPixelsAsync(); byte[] pixel_array = ib.ToArray(); ApplyRainbow(g704_softwareBitmap, pixel_array); g704_softwareBitmap = SoftwareBitmap.Convert(g704_softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); var source = new SoftwareBitmapSource(); await source.SetBitmapAsync(g704_softwareBitmap); G704.Source = source; }