/// <summary> /// Constructs a blank document (zero layers) of the given width and height. /// </summary> /// <param name="width"></param> /// <param name="height"></param> public Document(int width, int height) { this.width = width; this.height = height; this.Dirty = true; this.updateRegion = new Vector<Rectangle>(); layers = new LayerList(this); SetupEvents(); userMetaData = new NameValueCollection(); Invalidate(); }
override protected Image Load() { int layerPosition = 0; int colorOffset = 0; var document = Document.FromStream(Reader.BaseStream); Console.WriteLine("Width : " + document.Width); Console.WriteLine("height : " + document.Height); var image = new Image(document.Width, document.Height, ImageBaseType.Rgb); // Is it the best type ? image.Filename = Filename; PaintDotNet.LayerList layers = document.Layers; Console.WriteLine("#layers: " + layers.Count); foreach (PaintDotNet.Layer readLayer in layers) { try { Console.WriteLine(readLayer.Name); var layer = new Layer(image, readLayer.Name, document.Width, document.Height, ImageType.Rgba, (readLayer.Opacity / 255) * 100, // 100 what means ? LayerModeEffects.Normal); Console.WriteLine("11"); image.AddLayer(layer, layerPosition++); Console.WriteLine("1"); var rgn = new PixelRgn(layer, 0, 0, document.Width, document.Height, true, false); var buf = new byte[document.Width * document.Height * 4]; var color_conv_ary = new byte[4]; int lastPixelConverted = 0; colorOffset = 0; var surf = (readLayer as BitmapLayer).Surface; for (int row = 0; row < document.Height; row++) { var memory = surf.GetRow(row); var bitmapBytes = memory.ToByteArray(); lastPixelConverted = 0; colorOffset = 0; for (int col = 0; col < document.Width * 4; col++) { color_conv_ary[colorOffset++] = bitmapBytes[col]; // Console.WriteLine("ColorOffset = " + colorOffset); if (colorOffset >= 4) { var tmpArray = FromBGRAToRGBA(color_conv_ary); for (int j = 0; j < colorOffset; j++) { // buf[row * document.Height + (lastPixelConverted++)] = tmpArray[j]; buf[(row * document.Width * 4) + (lastPixelConverted++)] = tmpArray[j]; /* Console.WriteLine("Scritto il byte[" + ((row * * document.Width * 4) + (lastPixelConverted-1)) + "] : " + * tmpArray[j]);*/ } colorOffset = 0; } // buf[row * document.Height + col] = bitmapBytes[col]; //0x7F; } // Console.WriteLine(memory.Length); } // Console.ReadLine(); rgn.SetRect(buf, 0, 0, document.Width, document.Height); layer.Flush(); } catch (Exception e) { Console.WriteLine("Exception : " + e.Message + " - " + e.StackTrace); } } // missing colormap, mcolor and background Console.WriteLine("2"); /* var surface = (layers[0] as BitmapLayer).Surface; * var memory1 = surface.GetRow(13); * var bytes = memory1.ToByteArray(); * Console.WriteLine("length: " + bytes.Length);*/ return(image); }