/// <summary> /// Draws rectangle on bitmap /// </summary> /// <param name="layer">Layer to operate on</param> /// <param name="coordinates">Starting pixel coordinate</param> /// <param name="color">Rectangle color</param> private async void RectangleAsync(Layer layer, Coordinates coordinates, Color color) { WriteableBitmap wb = layer.LayerBitmap; _toolIsExecuting = true; WriteableBitmap writeableBitmap = wb.Clone(); while (Mouse.LeftButton == MouseButtonState.Pressed || Mouse.RightButton == MouseButtonState.Pressed) { //Two lines below are responsible for clearing last rectangle (on mouse move), to live show rectangle on bitmap wb.Clear(); wb.Blit(new Rect(new Size(layer.Width, layer.Height)), writeableBitmap, new Rect(new Size(layer.Width, layer.Height)), WriteableBitmapExtensions.BlendMode.Additive); //Those ifs are changing direction of rectangle. In other words: flips rectangle on X and Y axis when needed if (coordinates.X > _activeCoordinates.X && coordinates.Y > _activeCoordinates.Y) { wb.DrawRectangle(_activeCoordinates.X, _activeCoordinates.Y, coordinates.X, coordinates.Y, color); } else if (coordinates.X < _activeCoordinates.X && coordinates.Y < _activeCoordinates.Y) { wb.DrawRectangle(coordinates.X, coordinates.Y, _activeCoordinates.X, _activeCoordinates.Y, color); } else if (coordinates.Y > _activeCoordinates.Y) { wb.DrawRectangle(coordinates.X, _activeCoordinates.Y, _activeCoordinates.X, coordinates.Y, color); } else { wb.DrawRectangle(_activeCoordinates.X, coordinates.Y, coordinates.X, _activeCoordinates.Y, color); } await Task.Delay(_asyncDelay); } _toolIsExecuting = false; }
public void DrawPlate() { int colWidth = m_xPixelRange / m_cols; int rowHeight = m_yPixelRange / m_rows; int x1; int x2; int y1; int y2; m_plateBitmap.Lock(); m_plateBitmap.Clear(); for (int r = 0; r < m_rows; r++) { for (int c = 0; c < m_cols; c++) { x1 = (c * colWidth); x2 = x1 + colWidth; y1 = (r * rowHeight); y2 = y1 + rowHeight; m_plateBitmap.DrawRectangle(x1, y1, x2, y2, Colors.Black); if (m_selected[r, c]) { m_plateBitmap.FillRectangle(x1 + 2, y1 + 2, x2 - 2, y2 - 2, Colors.Red); } } } m_plateBitmap.Unlock(); }
public void ExpandingObjects_execute() { writeableBmp.Clear(); using (writeableBmp.GetBitmapContext()) { for (int i = 0; i < amount; i++) { expandingObject[i].expand(); switch (selected_obj) { case "ellipse": writeableBmp.DrawEllipse(expandingObject[i].xPos - expandingObject[i].Radius / 2, expandingObject[i].yPos - expandingObject[i].Radius / 2, expandingObject[i].xPos + expandingObject[i].Radius / 2, expandingObject[i].yPos + expandingObject[i].Radius / 2, expandingObject[i].Color); break; case "filled ellipse": writeableBmp.FillEllipse(expandingObject[i].xPos - expandingObject[i].Radius / 2, expandingObject[i].yPos - expandingObject[i].Radius / 2, expandingObject[i].xPos + expandingObject[i].Radius / 2, expandingObject[i].yPos + expandingObject[i].Radius / 2, expandingObject[i].Color); break; case "rectangle": writeableBmp.DrawRectangle(expandingObject[i].xPos - expandingObject[i].Radius / 2, expandingObject[i].yPos - expandingObject[i].Radius / 2, expandingObject[i].xPos + expandingObject[i].Radius / 2, expandingObject[i].yPos + expandingObject[i].Radius / 2, expandingObject[i].Color); break; case "filled rectangle": writeableBmp.FillRectangle(expandingObject[i].xPos - expandingObject[i].Radius / 2, expandingObject[i].yPos - expandingObject[i].Radius / 2, expandingObject[i].xPos + expandingObject[i].Radius / 2, expandingObject[i].yPos + expandingObject[i].Radius / 2, expandingObject[i].Color); break; } } } writeableBmp.Blit(new Rect(new Size(68, 42)), writeableBmp, new Rect(new Size(68, 42)), WriteableBitmapExtensions.BlendMode.Mask); }
private static void RenderAndSaveToFile(int size) { var widthStrip = size * size; var writeableBitmap = new WriteableBitmap(widthStrip, size, 96, 96, PixelFormats.Bgra32, null); writeableBitmap.Clear(Color.FromArgb(byte.MaxValue, 0, 0, 0)); for (var sliceIndex = 0; sliceIndex < size; sliceIndex++) { DrawLayer(writeableBitmap, size, sliceIndex); } var encoder = new PngBitmapEncoder(); encoder.Frames.Add( BitmapFrame.Create(new FormatConvertedBitmap(writeableBitmap, PixelFormats.Bgr24, null, 0))); var resultPng = $"LUT{size}.png"; using (var file = File.Open(resultPng, FileMode.Create)) { encoder.Save(file); Console.WriteLine("File saved: " + resultPng); } }
/// <summary> /// 实现图形接口的绘图逻辑 /// </summary> /// <param name="bitmap"></param> public void Draw(WriteableBitmap bitmap) { bitmap.Clear(); for (int i = 0; i < _width; i++) { for (int j = 0; j < _height; j++) { int x = _net[i, j].Position.X.ToDisplayUnits(); int y = _net[i, j].Position.Y.ToDisplayUnits(); // 绘制弹性连线 double dLeft; double dDown; if (i > 0 && (dLeft = (_net[i, j].Position - _net[i - 1, j].Position).Length()) / _gridSize < _factor) { byte colorRow = dLeft > _gridSize ? (byte)((int)(255 - (dLeft - _gridSize) / ((_factor - 1) * _gridSize) * 200)) : (byte)255; bitmap.DrawLineAa( x, y, _net[i - 1, j].Position.X.ToDisplayUnits(), _net[i - 1, j].Position.Y.ToDisplayUnits(), Color.FromArgb(colorRow, 0, 0, 0)); } if (j > 0 && (dDown = (_net[i, j].Position - _net[i, j - 1].Position).Length()) / _gridSize < _factor) { byte colorCol = dDown > _gridSize ? (byte)((int)(255 - (dDown - _gridSize) / ((_factor - 1) * _gridSize) * 200)) : (byte)255; bitmap.DrawLineAa( x, y, _net[i, j - 1].Position.X.ToDisplayUnits(), _net[i, j - 1].Position.Y.ToDisplayUnits(), Color.FromArgb(colorCol, 0, 0, 0)); } // 绘制点 bitmap.FillEllipseCentered(x, y, 2, 2, Colors.Black); } } }
/// <summary> /// Draws the collection of <see cref="IGraphicLine"/>s and <see cref="IGraphicPolygon"/>s /// to the screen. /// </summary> public async Task Draw(IEnumerable <IGraphicLine> lines, IEnumerable <IGraphicPolygon> polygons) { try { await _mainDispatcher.InvokeAsync(() => { _bitmap.Clear(); foreach (var gline in lines) { _bitmap.DrawLine( gline.Point1.X , gline.Point1.Y , gline.Point2.X , gline.Point2.Y , _colorCache[gline.Color] ); } foreach (var gpoly in polygons) { var points = new int[gpoly.Points.Count * 2 + 2]; for (int i = 0, c = 0; i < points.Length - 2; i += 2, c++) { var p = gpoly.Points[c]; points[i] = p.X; points[i + 1] = p.Y; } var first = gpoly.Points.First(); points[^ 2] = first.X;
/// <summary> /// Draws random shapes. /// </summary> private void DrawShapes(WriteableBitmap writeableBmp) { // Wrap updates in a GetContext call, to prevent invalidation and nested locking/unlocking during this block using (writeableBmp.GetBitmapContext()) { // Init some size vars int w = writeableBmp.PixelWidth - 2; int h = writeableBmp.PixelHeight - 2; int w2 = w >> 1; int h2 = h >> 1; // Clear writeableBmp.Clear(); // Fill Shapes for (int i = 0; i < shapeCount; i++) { // Random polygon int[] p = new int[rand.Next(5, 10) * 2]; for (int j = 0; j < p.Length; j += 2) { p[j] = rand.Next(w); p[j + 1] = rand.Next(h); } writeableBmp.FillPolygon(p, GetRandomColor()); } // Invalidates on exit of Using block } }
public void FrameEvents(WriteableBitmap surface) { if (user.CurrentHealth <= 0 && currentworldtype == WorldType.dungeon) { dead = true; } if (dead == true) { deathOperations(surface); } if (!pause) { gameEngineTick(); surface.Clear(); CurrentWorld.DrawStage(surface); CurrentWorld.GameTick(); foreach (Enemy enemy in CurrentWorld.GameEnemies) { enemy.Draw(surface); } user.Draw(surface); shareEnemiesWithUser(); } else { tryTogglePause(); } }
private void DrawImage() { using (writeableBmp.GetBitmapContext()) { writeableBmp.Clear(Colors.White); foreach (var cell in Cells) { // swap here to prevent additional loop cell.SwapIsAlive(); if (!cell.IsAlive) { continue; } var position = cell.Position; var lowerRight = new Point(position.X * PIXEL_SIZE, position.Y * PIXEL_SIZE); var upperLeft = new Point(lowerRight.X - (PIXEL_SIZE - 1), lowerRight.Y - (PIXEL_SIZE - 1)); writeableBmp.DrawRectangle((int)upperLeft.X, (int)upperLeft.Y, (int)lowerRight.X, (int)lowerRight.Y, Colors.Red); } } }
private void Shrink_Tick(object sender, EventArgs e) { if (Bass.BASS_ChannelIsActive(wispManager.StreamHandle) == BASSActive.BASS_ACTIVE_PLAYING) { SpectrumActivationCount++; if (wispManager.BPM_Avaliable && wispManager.CurrentBPM.BPM > 0) { Application.Current.Dispatcher.Invoke(() => { LogoShrinkAnimation.Begin(); }, DispatcherPriority.DataBind); } if (SpectrumActivationCount >= 4) { SpectrumActivationCount = 0; float[] buffer = new float[2048]; Bass.BASS_ChannelGetData(wispManager.StreamHandle, buffer, (int)BASSData.BASS_DATA_FFT2048); ShowSpectrum(100, 2000, 250, buffer); } } Application.Current.Dispatcher.Invoke(() => { using (spectrumWritableBitmap.GetBitmapContext()) { spectrumWritableBitmap.Clear(Color.FromArgb(0, 0, 0, 0)); } spectrum.Update(); spectrum.Draw(); }, DispatcherPriority.Render); }
void rightButton_Click(Object sender, RoutedEventArgs e) { BackgroundWorker backgroundWorker = new BackgroundWorker(); backgroundWorker.WorkerSupportsCancellation = true; wallsLabel.Visibility = Visibility.Visible; wallsCounter++; if (wallsCounter >= walls.Count) { wallsCounter = 0; } wallsLabel.Content = CheckWall(); backgroundWorker.DoWork += new DoWorkEventHandler((state, arg) => { List <string[, ]> walls = new List <string[, ]>(); walls.Add(this.walls[wallsCounter]); int sizeX = 0; int sizeY = 0; for (int i = 0; i < walls.Count; i += 2) { int mSizeX = (walls[i].GetLength(0) + 1) * size; if (i + 1 < walls.Count) { mSizeX += (walls[i + 1].GetLength(0) + 1) * size; } if (mSizeX > sizeX) { sizeX = mSizeX; } sizeY += (walls[i].GetLength(1) + 1) * size; } WriteableBitmap simulationBitmap = BitmapFactory.New(sizeX, sizeY); simulationBitmap.Clear(Colors.White); Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { canvas.Width = sizeX; canvas.Height = sizeY; })); Draw(walls, simulationBitmap, size); simulationBitmap.Freeze(); Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { image.Source = simulationBitmap; })); }); backgroundWorker.RunWorkerAsync(); }
void OnDraw() { using (gameboardBmp.GetBitmapContext()) { gameboardBmp.Clear(); DrawBackground(); DrawGameBoard(); if (hexGame.ShowGhost) { DrawPiece(hexGame.GhostPiece, GetPieceColor(hexGame.CurrentPiece.PieceType, true), GetPieceColor(hexGame.CurrentPiece.PieceType, true, true)); } DrawPiece(hexGame.CurrentPiece, GetPieceColor(hexGame.CurrentPiece.PieceType, false), GetPieceColor(hexGame.CurrentPiece.PieceType, true)); } using (previewBmp.GetBitmapContext()) { previewBmp.Clear(); DrawPiecePreview(); } }
public BitmapSurface(PixelEditorSurface owner) { this.owner = owner; bitmap = BitmapFactory.New(owner.PixelWidth, owner.PixelHeight); bitmap.Clear(Colors.Transparent); RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.NearestNeighbor); }
private void CompositionTarget_Rendering(object sender, EventArgs e) { writeableBmp.Clear(); //Untergrund wird gecleared BitmapSettings(); //Der Hintergrund wird schwarz und die Verfolgungslinie / Umlaufbahn-Punkte werden gezeichnet if (world.CelestrialBodies.Count > 0) { if (AnimationRunning) //Ist True, wenn Benutzer auf START drückt { for (int i = 0; i < CalculationsPerFrame; i++) //Führt Berechnung je nach eingestellter Animationsgeschwindigkeit unterschiedlich oft durch { world.GameTick(Δt); //Berechnung wird mit Δt einmal durchgeführt if (TestingIsActive) //Wenn der Benutzer einen Test durchführt, dann ist TestingIsActive = true { if (StopIfFullCircle()) //Stoppt die Berechnung nach vollendung einer Umdrehung { i = CalculationsPerFrame; } } } TimePassed = (float)((world.CalculatedTime) / 3600 / 24); txt_TimePassed.Text = TimePassed.ToString() + " d"; //gibt die verstrichene Zeit aus ShowSelectedBodyInformation(); //zeigt die Daten des gewählten Körpers } Check_If_MaxCalculations_Can_Be_Achieved(); //Checkt ob genug Rechenleistung verfügbar ist world.DrawWorld(writeableBmp, width, height, ZoomFaktor); //Zeichnet alle Körper der "Welt" } }
private void Draw() { if (this.points != null && this.writeableBmp != null) { // Wrap updates in a GetContext call, to prevent invalidation and nested locking/unlocking during this block using (writeableBmp.GetBitmapContext()) { writeableBmp.Clear(); if (ChkShowPoints.IsChecked.Value) { DrawPoints(); } if (RBBezier.IsChecked.Value) { DrawBeziers(); } else if (RBCardinal.IsChecked.Value) { DrawCardinal(); } // Invalidates on exit of using block } } }
public void ClearScreen() { using (writeableBmp.GetBitmapContext()) { writeableBmp.Clear(Colors.Transparent); } }
public MainWindow() { wysokosc = 50; szerokosc = 50; InitializeComponent(); inBitmap = new WriteableBitmap((int)InImage.Width, (int)InImage.Height, 96, 96, PixelFormats.Bgr32, null); outBitmap = new WriteableBitmap((int)outImage.Width, (int)outImage.Height, 96, 96, PixelFormats.Bgr32, null); inBitmap.Clear(Color.FromRgb(255, 255, 255)); outBitmap.Clear(Color.FromRgb(255, 255, 255)); InImage.Source = inBitmap; outImage.Source = outBitmap; dane = new Dane(szerokosc, wysokosc); dane.WczytajPrzyklady(); int[][] przyklady = dane.PobierzPrzyklady(); maszyny = new MaszynaLiniowa[szerokosc * wysokosc]; zapalonePiksele = new int[szerokosc * wysokosc]; aktualnyPrzyklad = 0; for (int i = 0; i < szerokosc * wysokosc; i++) { maszyny[i] = new MaszynaLiniowa(i, szerokosc * wysokosc, 2, przyklady, dane.PobierzLiczbePrzykladow()); zapalonePiksele[i] = 0; } Parallel.For(0, szerokosc * wysokosc, i => { maszyny[i].UczMaszyne(); }); //Image a = new Image(); //PixelFormat pf = new PixelFormat(); //JpegBitmapDecoder jpg = new JpegBitmapDecoder(new Uri("test.jpg"),BitmapCreateOptions.None,BitmapCacheOption.Default); //a.Source = System.Windows.Media.Imaging.BitmapSource.Create(100, 100, 72, 72, pf, jpg.Palette, jpg.Frames); }
public void RefreshGrido() { //Grido.Children.Clear(); writeableBmp.Clear(); Text_GenCounter.Text = $"Поколение: {GenerationCounter}"; int Resolution = game.CellSize; Color color = Colors.LightGray; bool Condition; for (int x = 0; x < game.Cols; x++) { for (int y = 0; y < game.Rows; y++) { if (EnableFutureView) { color = FutureViewColor(x, y); } Condition = game.Field[x, y] || color == LifeStateColor; if (Condition) { int realX = x * Resolution; int realY = y * Resolution; writeableBmp.FillRectangle(realX, realY, realX + Resolution - 1, realY + Resolution - 1, color); } } } }
private void render() { if (renderTarget != null) { renderTarget.Lock(); renderTarget.Clear(); controller.Render(renderTarget); renderTarget.Unlock(); textCanvas.Children.Clear(); foreach (var t in controller.PendingText) { TextBlock tb = new TextBlock(); tb.Text = t.Item1; if (t.Item5) { tb.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); Canvas.SetLeft(tb, t.Item2.X - tb.DesiredSize.Width / 2); } else { Canvas.SetLeft(tb, t.Item2.X); } Canvas.SetTop(tb, t.Item2.Y); tb.FontFamily = t.Item4.FontFamily; tb.Foreground = t.Item3.Brush; tb.Background = Brushes.Transparent; tb.FontStyle = t.Item5 ? FontStyles.Italic : FontStyles.Normal; textCanvas.Children.Add(tb); } controller.PendingText.Clear(); } }
public void Clear() { using (bmp.GetBitmapContext()) { bmp.Clear(Colors.Black); } }
public void RedrawScreen(List <Figure> listFig, int index, Canvas canvas) { // canvas.Children.Clear(); // gridFigure.AddFigure(canvas); // foreach (Line ln in centerLines) // canvas.Children.Add(ln); // if (OptionMode.mode == Mode.modeCursor) // DrawFirstAndLastRectangle(); // for (int i = FigureList.Count -1 ; i >=0; i--) // { // FigureList[i].AddFigure(canvas); //можно не перерисовывать каждый раз // if (AllRectanglesOn && i == ChosenFigure) // { // FigureList[i].DrawAllRectangles(); // } // } // if (OptionMode.mode == Mode.modeFigure || OptionMode.mode == Mode.modeTatami || OptionMode.mode == Mode.modeRunStitch // || OptionMode.mode == Mode.modeSatin) // { // DrawInvisibleRectangles(canvas); // } // for (int i = 0; i < listPltFigure.Count; i++) // { // listPltFigure[i].AddFigure(canvas); // } canvas.Children.Clear(); canvas.Children.Add(gridBMP); WriteableBitmap bmp = BitmapFactory.New(1600, 900); bmp.Clear(Colors.Transparent); Color lineColor; for (int i = 0; i < listFig.Count; i++) { if (listFig[i].points.Count > 0) { if (i == index) { lineColor = OptionColor.colorActive; } else { lineColor = OptionColor.colorInactive; } List <Point> pts = listFig[i].points; for (int j = 0; j < pts.Count - 1; j++) { bmp.DrawLineBresenham((int)pts[j].X, (int)pts[j].Y, (int)pts[j + 1].X, (int)pts[j + 1].Y, lineColor); } } } DrawModeRectangles(listFig, bmp); mainBMP = new Image { Stretch = Stretch.None, Source = bmp }; canvas.Children.Add(mainBMP); }
private void Dpt_Tick(object sender, EventArgs e) { if (_writeableBmp == null || _writeableBmp.Height == 1) { _writeableBmp = BitmapFactory.New(581, 442); } GraphImage.Source = _writeableBmp; using (_writeableBmp.GetBitmapContext()) { _writeableBmp.Clear(); //Sensor 2 var q2Arr = _q2.ToArray(); var p2 = new List <int>(); for (var index = 0; index < q2Arr.Count(); index++) { var v = q2Arr[index]; p2.Add(index); p2.Add((442 - v - 600)); } //Sensor 1 var p1 = new List <int>(); var q1Arr = _q1.ToArray(); for (var index = 0; index < q1Arr.Count(); index++) { if (q1Arr.Length > index) { var v = q1Arr[index]; p1.Add(index); p1.Add(442 - (v - 600)); } } try { drawGrid(); _writeableBmp.DrawPolyline(p1.ToArray(), Colors.Green); _writeableBmp.DrawPolyline(p2.ToArray(), Colors.Red); //update Mean values tbkMeanThermal1.Text = "S1: " + q1Arr.Average().ToString(CultureInfo.InvariantCulture); tbkMeanThermal2.Text = "S2: " + q2Arr.Average().ToString(CultureInfo.InvariantCulture); _writeableBmp.DrawLine(0, (int)((int)442 - (q1Arr.Average() - 600)), 581, (int)((int)442 - (q1Arr.Average() - 600)), Colors.DarkSeaGreen); _writeableBmp.DrawLine(0, (int)((int)442 - (q2Arr.Average() - 600)), 581, (int)((int)442 - (q2Arr.Average() - 600)), Colors.IndianRed); //thermal gate _writeableBmp.DrawLine(0, 442 - (ThermalG1 - 600), 581, 442 - (ThermalG1 - 600), Colors.DarkOliveGreen); _writeableBmp.DrawLine(0, 442 - ThermalG2 - 600, 581, 442 - ThermalG2 - 600, Colors.DarkRed); //update current values tbkThermalR1.Text = "S1: " + _q1.Peek().ToString(CultureInfo.InvariantCulture); tbkThermalR2.Text = "S2: " + _q2.Peek().ToString(CultureInfo.InvariantCulture); } catch (Exception) { } } }
public void Render(IViewport viewport, IEnumerable <ILayer> layers) { if (targetBitmap == null || targetBitmap.PixelWidth != (int)target.ActualWidth || targetBitmap.PixelHeight != (int)target.ActualHeight) { target.Arrange(new Rect(0, 0, viewport.Width, viewport.Height)); if (target.ActualWidth <= 0 || target.ActualHeight <= 0) { return; } target.Children.Clear(); target.Children.Add(InitializeBitmap((int)target.ActualWidth, (int)target.ActualHeight)); } targetBitmap.Clear(Colors.White); foreach (var layer in layers) { if (layer.Enabled && layer.MinVisible <= viewport.Resolution && layer.MaxVisible >= viewport.Resolution) { RenderLayer(targetBitmap, viewport, layer); } } target.Arrange(new Rect(0, 0, viewport.Width, viewport.Height)); }
private void DetectMarkers(WriteableBitmap bmp) { // Init. here because the captureSource.VideoCaptureDevice.DesiredFormat getter is not reliable and throws an Exception if (!isInit) { // Init AR arDetector.Initialize(bmp.PixelWidth, bmp.PixelHeight, Game.Camera.Near, Game.Camera.Far, new List <Marker> { slarMarker }); isInit = true; } // Detect var dr = arDetector.DetectAllMarkers(bmp); // Reused for marker highlighting bmp.Clear(); ViewportOverlay.Source = bmp; if (dr.HasResults) { var transformation = Balder.Math.Matrix.CreateTranslation(0, -5, 0) * Balder.Math.Matrix.CreateRotationX(90) * dr[0].Transformation.ToBalder(); Game.SetWorldMatrix(transformation); // Highlight detected markers var txt = String.Empty; foreach (var r in dr) { bmp.DrawQuad((int)r.Square.P1.X, (int)r.Square.P1.Y, (int)r.Square.P2.X, (int)r.Square.P2.Y, (int)r.Square.P3.X, (int)r.Square.P3.Y, (int)r.Square.P4.X, (int)r.Square.P4.Y, Colors.Red); txt += String.Format("{0}.Confidence = {1:0.00} ", r.Marker.Name, r.Confidence); } } }
protected BaseTool(WorldViewModel worldViewModel) { _wvm = worldViewModel; _preview = new WriteableBitmap(1, 1, 96, 96, PixelFormats.Bgra32, null); _preview.Clear(); _preview.SetPixel(0, 0, 127, 0, 90, 255); }
public Media(string filepath, MediaType type) { this.LoadedBehavior = MediaState.Manual; this.UnloadedBehavior = MediaState.Manual; this.Source = new Uri(filepath); //this.Open (new Uri (filename)); // if ScrubbingEnabled is true move correctly shows selected frame, but cursor won't work any more... //this.ScrubbingEnabled = true; this.Pause(); this.filepath = filepath; this.type = type; this.filepath = filepath; this.type = type; inputFile = new MediaFile { Filename = this.filepath }; using (var engine = new Engine()) { engine.GetMetadata(inputFile); } if (type == MediaType.VIDEO) { sampleRate = inputFile.Metadata.VideoData.Fps; string frameSize = inputFile.Metadata.VideoData.FrameSize; string[] tokens = frameSize.Split('x'); int.TryParse(tokens[0], out width); int.TryParse(tokens[1], out height); } else if (type == MediaType.AUDIO) { string[] tokens = inputFile.Metadata.AudioData.SampleRate.Split(' '); double.TryParse(tokens[0], out sampleRate); } // add grid grid = new Grid(); grid.MouseDown += OnMouseDown; grid.MouseUp += OnMouseUp; grid.MouseMove += OnMouseMove; // add video Grid.SetColumn(this, 0); Grid.SetRow(this, 0); grid.Children.Add(this); // add overlay if (type == MediaType.VIDEO) { overlayImage = new Image(); overlayBitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgra32, null); overlayBitmap.Clear(Colors.Transparent); overlayImage.Source = overlayBitmap; Grid.SetColumn(overlayImage, 0); Grid.SetRow(overlayImage, 0); grid.Children.Add(overlayImage); } }
public override WriteableBitmap PreviewTool() { var bmp = new WriteableBitmap(_wvm.Brush.Width + 1, _wvm.Brush.Height + 1, 96, 96, PixelFormats.Bgra32, null); bmp.Clear(); if (_wvm.Brush.Shape == BrushShape.Square || _wvm.Brush.Height <= 1 || _wvm.Brush.Width <= 1) { bmp.FillRectangle(0, 0, _wvm.Brush.Width, _wvm.Brush.Height, Color.FromArgb(127, 0, 90, 255)); } else if (_wvm.Brush.Shape == BrushShape.Left) { bmp.DrawLine(0, 0, _wvm.Brush.Width, _wvm.Brush.Height, Color.FromArgb(127, 0, 90, 255)); } else if (_wvm.Brush.Shape == BrushShape.Right) { bmp.DrawLine(0, _wvm.Brush.Height, _wvm.Brush.Width, 0, Color.FromArgb(127, 0, 90, 255)); } else { bmp.FillEllipse(0, 0, _wvm.Brush.Width, _wvm.Brush.Height, Color.FromArgb(127, 0, 90, 255)); } _preview = bmp; return(_preview); }
private void Draw(WriteableBitmap writeableBmp) { if (this.points != null && writeableBmp != null) { ReloadRandomPoints(); // Wrap updates in a GetContext call, to prevent invalidation and nested locking/unlocking during this block using (writeableBmp.GetBitmapContext()) { writeableBmp.Clear(); DrawPoints(writeableBmp); //DrawBeziers(writeableBmp); // DrawCardinal(writeableBmp); //if (ChkShowPoints.IsChecked.Value) //{ // DrawPoints(); //} //if (RBBezier.IsChecked.Value) //{ // DrawBeziers(); //} //else if (RBCardinal.IsChecked.Value) //{ // DrawCardinal(); //} } } }
/// <summary> /// Generates bitmap ready to work with /// </summary> /// <param name="bitmapWidth">Width of bitmap.</param> /// <param name="imageHeight">Height of bitmap.</param> /// <returns></returns> private static WriteableBitmap GenerateBitmap(int bitmapWidth, int imageHeight) { WriteableBitmap bitmap = BitmapFactory.New(bitmapWidth, imageHeight); bitmap.Clear(System.Windows.Media.Colors.Transparent); return(bitmap); }
/// <summary> /// Draws circle on bitmap. /// </summary> /// <param name="layer">Layer to operate on.</param> /// <param name="coordinates">Starting pixel coordinates.</param> /// <param name="color">Circle color.</param> private async void CircleAsync(Layer layer, Coordinates coordinates, Color color) { WriteableBitmap wb = layer.LayerBitmap; //Basically does the same like rectangle method, but with different shape _toolIsExecuting = true; WriteableBitmap bitmap = wb.Clone(); while (Mouse.LeftButton == MouseButtonState.Pressed || Mouse.RightButton == MouseButtonState.Pressed) { wb.Clear(); wb.Blit(new Rect(new Size(layer.Width, layer.Height)), bitmap, new Rect(new Size(layer.Width, layer.Height)), WriteableBitmapExtensions.BlendMode.Additive); if (coordinates.X > _activeCoordinates.X && coordinates.Y > _activeCoordinates.Y) { wb.DrawEllipse(_activeCoordinates.X, _activeCoordinates.Y, coordinates.X, coordinates.Y, color); } else if (coordinates.X < _activeCoordinates.X && coordinates.Y < _activeCoordinates.Y) { wb.DrawEllipse(coordinates.X, coordinates.Y, _activeCoordinates.X, _activeCoordinates.Y, color); } else if (coordinates.Y > _activeCoordinates.Y) { wb.DrawEllipse(coordinates.X, _activeCoordinates.Y, _activeCoordinates.X, coordinates.Y, color); } else { wb.DrawEllipse(_activeCoordinates.X, coordinates.Y, coordinates.X, _activeCoordinates.Y, color); } await Task.Delay(_asyncDelay); } _toolIsExecuting = false; }