public void TestBitmapResize() { Color green = Color.FromArgb(0, 200, 0); Color red = Color.FromArgb(200, 0, 0); using (var bitmap = new Bitmap(20, 20)) { using (var graphics = Graphics.FromImage(bitmap)) using (var gBrush = new SolidBrush(green)) using (var rBrush = new SolidBrush(red)) { graphics.FillRectangle(gBrush, 0, 0, 10, 20); graphics.FillRectangle(rBrush, 10, 0, 10, 20); } using (var sourceRepresentation = new BitmapRepresentation(bitmap)) using (var sourceBitmapEx = sourceRepresentation.CreateBitmap()) using (var destinationBitmapEx = new BitmapEx(10, 10)) { BitmapHelpers.ResizeBitmap(sourceBitmapEx, destinationBitmapEx); var bmp = destinationBitmapEx.GetInternal(); { var green2 = bmp.GetPixel(3, 5); var red2 = bmp.GetPixel(7, 5); Assert.AreEqual(true, CompareColors(green, green2, 5)); Assert.AreEqual(true, CompareColors(red, red2, 5)); } } } }
private BitmapRepresentation GetBitmapRepresentation(byte[] bitmapBytes) { using (var bitmapRepresentation = new BitmapRepresentation(bitmapBytes)) using (var bmpEx = bitmapRepresentation.CreateBitmap()) using (var result = LayoutContext.CreateBitmap()) { BitmapHelpers.ResizeBitmap(bmpEx, result); return(new BitmapRepresentation(result)); } }
public static BitmapEx CreateBitmap(this IDevice device, ThemeOptions options) { var iconSize = device.IconSize; var result = new BitmapEx(iconSize.Width, iconSize.Height, PixelFormat.Format24bppRgb); if (options.BackgroundBitmapRepresentation == null) { using (var graphics = result.CreateGraphics()) using (var brush = new SolidBrush(options.BackgroundColor)) { graphics.FillRectangle(brush, 0, 0, result.Width, result.Height); } } else { using (var sourceBitmap = options.BackgroundBitmapRepresentation.CreateBitmap()) BitmapHelpers.ResizeBitmap(sourceBitmap, result); } return(result); }
private BitmapEx DrawKey() { var bitmap = LayoutContext.CreateBitmap(); var path = _session.SessionIdentifier.Split('|')[1]; path = path.Substring(0, path.Length - 40); path = DevicePathMapper.FromDevicePath(path); var process = Process.GetProcesses().FirstOrDefault(p => p.Id == _session.ProcessId); if (path == null && process != null) { try { path = process.MainModule.FileName; } catch { } } if (path != null) { var iconRepresentation = _audioSelectLayout._bitmapDownloadService.GetBitmapForExecutable(path).GetAwaiter().GetResult(); using (var iconBmpEx = iconRepresentation.CreateBitmap()) { BitmapHelpers.ResizeBitmap(iconBmpEx, bitmap); } } if (_session.Mute) { DefaultDrawingAlgs.SelectElement(bitmap, GlobalContext.Options.Theme); } return(bitmap); }
private void OnDrawLayout(object sender, DrawEventArgs e) { BitmapEx currentBitmap; lock (_bitmapLock) { currentBitmap = _currentRepresentation.CreateBitmap(); foreach (var element in e.Elements) { var destRect = new Rectangle(_buttonShift.Width + element.Location.X * _individualButtonSize.Width, _buttonShift.Height + element.Location.Y * _individualButtonSize.Height, _individualButtonSize.Width, _individualButtonSize.Height); using (var sourceBitmap = element.BitmapRepresentation.CreateBitmap()) { BitmapHelpers.ResizeBitmap(sourceBitmap, currentBitmap, destRect); element.BitmapRepresentation.Dispose(); } } DisposeHelper.DisposeAndNull(ref _currentRepresentation); _currentRepresentation = new BitmapRepresentation(currentBitmap); } DrawInvoke(new[] { new LayoutDrawElement(new Location(0, 0), currentBitmap) }); }
private void PerformDraw(PlayingInfo playingInfo) { if (_previousRepresentation != playingInfo?.BitmapRepresentation || _prevPlaying != playingInfo?.IsPlaying) { _previousRepresentation = playingInfo?.BitmapRepresentation; _prevPlaying = playingInfo?.IsPlaying ?? false; var bitmap = LayoutContext.CreateBitmap(); if (playingInfo?.BitmapRepresentation != null) { using (var coverBitmap = playingInfo.BitmapRepresentation.CreateBitmap()) { BitmapHelpers.ResizeBitmap(coverBitmap, bitmap, _prevPlaying ? null : BitmapHelpers.GrayColorMatrix); } } else { DefaultDrawingAlgs.DrawText(bitmap, FontService.Instance.AwesomeFontFamily, FontAwesomeRes.fa_headphones, LayoutContext.Options.Theme.ForegroundColor); } DrawInvoke(new[] { new LayoutDrawElement(new Location(0, 0), bitmap, new TransitionInfo(TransitionType.ElementUpdate, TimeSpan.FromSeconds(1))) }); } }
private BitmapEx Draw() { var bitmap = LayoutContext.CreateBitmap(); if (!string.IsNullOrEmpty(_options.Symbol)) { var fontFamily = FontService.Instance.AwesomeFontFamily; DefaultDrawingAlgs.DrawText(bitmap, fontFamily, _options.Symbol, GlobalContext.Options.Theme.ForegroundColor); } else { using (var iconRepresentation = _bitmapDownloadService.GetBitmapForExecutable(_options.Executable).Result) using (var iconBmpEx = iconRepresentation.CreateBitmap()) { BitmapHelpers.ResizeBitmap(iconBmpEx, bitmap); if (_selected) { DefaultDrawingAlgs.SelectElement(bitmap, GlobalContext.Options.Theme); } } } return(bitmap); }
private void PerformDraw(PlayingInfo playingInfo) { byte imageSize = 2; byte textSize = 3; var result = new List <LayoutDrawElement>(); if (playingInfo.IsPlaying != _isPlaying) { _isPlaying = playingInfo.IsPlaying; _playPauseButton.ReplaceText(_isPlaying.Value?FontAwesomeRes.fa_pause:FontAwesomeRes.fa_play); } if (_previousRepresentation != playingInfo?.BitmapRepresentation) { _previousRepresentation = playingInfo?.BitmapRepresentation; using (var bitmap = new BitmapEx(LayoutContext.IconSize.Width * imageSize, LayoutContext.IconSize.Height * imageSize)) { bitmap.MakeTransparent(); if (playingInfo?.BitmapRepresentation != null) { using (BitmapEx coverBitmap = playingInfo.BitmapRepresentation.CreateBitmap()) { BitmapHelpers.ResizeBitmap(coverBitmap, bitmap); } } result.AddRange(BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(imageSize, imageSize), 0, 0, LayoutContext)); } } using (var bitmap = new BitmapEx(LayoutContext.IconSize.Width * textSize, LayoutContext.IconSize.Height)) { var lineWidth = 0.05; bitmap.MakeTransparent(); var title = playingInfo?.Title; DefaultDrawingAlgs.DrawText(bitmap, GlobalContext.Options.Theme.FontFamily, title, LayoutContext.Options.Theme.ForegroundColor); if (playingInfo != null) { using (var graphics = bitmap.CreateGraphics()) using (var brush = new SolidBrush(GlobalContext.Options.Theme.ForegroundColor)) { var rect = new Rectangle(0, (int)(bitmap.Height * (1 - lineWidth)), (int)(bitmap.Width * playingInfo.CurrentPosition.TotalMilliseconds / playingInfo.DurationSpan.TotalMilliseconds), (int)(bitmap.Height * lineWidth)); graphics.FillRectangle(brush, rect); } } result.AddRange(BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(textSize, 1), imageSize, 0, LayoutContext)); } using (var bitmap = new BitmapEx(LayoutContext.IconSize.Width * textSize, LayoutContext.IconSize.Height)) { bitmap.MakeTransparent(); var artist = playingInfo?.Artist ?? string.Empty; var album = playingInfo?.Album ?? string.Empty; var text = $"{artist}\n{album}"; DefaultDrawingAlgs.DrawText(bitmap, GlobalContext.Options.Theme.FontFamily, text, GlobalContext.Options.Theme.ForegroundColor); result.AddRange(BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(textSize, 1), imageSize, 1, LayoutContext)); } DrawInvoke(result); }