Beispiel #1
0
 public async Task LoadPSD(StorageFile file, IList <LayerModel> ls, Action <int, int> d = null)
 {
     using (var stream = await file.OpenStreamForReadAsync())
     {
         var psd = new ConsoleApp1.Mpsd2()
         {
             encode = encoding
         };
         psd.load(stream);
         d?.Invoke(psd.head.width, psd.head.height);
         foreach (var layer in psd.layerdata)
         {
             int             w = layer.Width, h = layer.Height;
             WriteableBitmap b = null;
             if (w > 0 && h > 0)
             {
                 b = new WriteableBitmap(w, h);
                 var bt = layer.getBGRA(w, h);
                 b.PixelBuffer.AsStream().Write(bt, 0, bt.Length);
             }
             ls.Insert(0, new LayerModel()
             {
                 Name    = layer.Name,
                 IsShow  = layer.Visable,
                 IsEdit  = layer.Editable,
                 Opacity = layer.Alpha / 255d,
                 X       = (double)layer.Left,
                 Y       = (double)layer.Top,
                 Bitmap  = b
             });
         }
     }
 }
Beispiel #2
0
        public void SavePSD(Stream stream, IList <LayerModel> ls, int w, int h)
        {
            var psd = new ConsoleApp1.Mpsd2()
            {
                encode = encoding
            };

            psd.head = ConsoleApp1.Mpsd2.Head.Create(w, h);
            var tt = new Task <ConsoleApp1.Mpsd2.Layer> [ls.Count];

            for (int i = 0; i < ls.Count; i++)
            {
                var item = ls[i];
                if (item.Bitmap == null)
                {
                    tt[i] = ConsoleApp1.Mpsd2.Layer.CreateAsync(item.Name, (int)item.X, (int)item.Y,
                                                                0, 0, (byte)(item.Opacity * 255d), item.IsShow, item.IsEdit, new MemoryStream());
                }
                else
                {
                    var b  = item.Bitmap;
                    var sm = b.PixelBuffer.AsStream();//Handled = The function evaluation was disabled because of an out of memory exception.
                    if (item.X == Rect.Empty.X)
                    {
                        throw null;
                    }
                    if (item.Name.Length > 255)
                    {
                        item.Name = item.Name.Substring(0, 255);
                    }
                    //if (item.Name.Length == 0) item.Name = ".";
                    tt[i] = ConsoleApp1.Mpsd2.Layer.CreateAsync(item.Name, (int)item.X, (int)item.Y,
                                                                b.PixelWidth, b.PixelHeight, (byte)(item.Opacity * 255d), item.IsShow, item.IsEdit, sm);
                }
            }
            var ttt = Task.WhenAll(tt).GetAwaiter().GetResult();

            for (int i = 0; i < ttt.Length; i++)
            {
                psd.layerdata.Insert(0, ttt[i]);
            }
            stream.SetLength(0);
            psd.save(stream);
        }