123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using PixiEditorDotNetCore3.Models.Tools;
- using System;
- using System.ComponentModel;
- using System.Runtime.InteropServices;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- namespace PixiEditorDotNetCore3.Models.Layers
- {
- public class Layer : BasicLayer
- {
- private WriteableBitmap _layerBitmap;
- public string Name { get; set; }
- public WriteableBitmap LayerBitmap
- {
- get { return _layerBitmap; }
- set
- {
- _layerBitmap = value;
- RaisePropertyChanged("LayerBitmap");
- }
- }
- public Layer(string name,int width, int height)
- {
- Name = name;
- Layer layer = LayerGenerator.Generate(width, height);
- LayerBitmap = layer.LayerBitmap;
- Width = width;
- Height = height;
- }
- public Layer(WriteableBitmap layerBitmap)
- {
- LayerBitmap = layerBitmap;
- Width = (int)layerBitmap.Width;
- Height = (int)layerBitmap.Height;
- }
- public void ApplyPixels(BitmapPixelChanges pixels, Color color)
- {
- LayerBitmap.Lock();
- foreach (var coords in pixels.ChangedCoordinates)
- {
- LayerBitmap.SetPixel(Math.Clamp(coords.X, 0, Width - 1), Math.Clamp(coords.Y, 0, Height - 1),
- color);
- }
- LayerBitmap.Unlock();
- }
-
- public byte[] ConvertBitmapToBytes()
- {
- LayerBitmap.Lock();
- byte[] byteArray = LayerBitmap.ToByteArray();
- LayerBitmap.Unlock();
- return byteArray;
- }
- public byte[] ConvertBitmapToBytes(WriteableBitmap bitmap)
- {
- bitmap.Lock();
- byte[] byteArray = bitmap.ToByteArray();
- bitmap.Unlock();
- return byteArray;
- }
- }
- }
|