Beispiel #1
0
        public Bitmap ToBitmap()
        {
            JImage j = this;
            Bitmap b = new Bitmap(j.Size.Width, j.Size.Height);

            foreach (JImageLayer layer in j.Layers)
            {
                int width  = b.Size.Width;
                int height = b.Size.Height;
                int hi     = 0;
                while (hi < height)
                {
                    int wi = 0;
                    while (wi < width)
                    {
                        JImagePixel jip = layer.Pixels.Find(x => x.Position.x == wi && x.Position.y == hi);
                        Color       c   = new Color();
                        if (jip != null)
                        {
                            c = Color.FromArgb(jip.Color.Alpha, jip.Color.Red, jip.Color.Green, jip.Color.Blue);
                        }
                        else
                        {
                            c = Color.FromArgb(layer.DefaultColor.Alpha, layer.DefaultColor.Red, layer.DefaultColor.Green, layer.DefaultColor.Blue);
                        }
                        b.SetPixel(wi, hi, c);
                        wi++;
                    }
                    hi++;
                }
            }
            return(b);
        }
Beispiel #2
0
        public static JImage FromBitmap(Bitmap g, string Comment = "")
        {
            JImage j = new JImage()
            {
                Size = new JImageSize()
                {
                    Height = g.Height,
                    Width  = g.Width
                },
                // not sure on how to
                Transparancy = true,
                Version      = "1.0",
                Comment      = Comment
            };
            JImageLayer l = new JImageLayer()
            {
                DefaultColor = new JImageColor()
                {
                    Blue  = 0,
                    Alpha = 0,
                    Green = 0,
                    Red   = 0
                },
            };

            List <JImagePixel> p = new List <JImagePixel>();

            int width  = g.Width;
            int height = g.Height;
            int hi     = 0;

            while (hi < height)
            {
                int wi = 0;
                while (wi < width)
                {
                    Color c = g.GetPixel(wi, hi);
                    p.Add(new JImagePixel()
                    {
                        Position = new JImagePixelPosition()
                        {
                            x = wi,
                            y = hi
                        },
                        Color = new JImageColor()
                        {
                            Alpha = c.A,
                            Blue  = c.B,
                            Green = c.G,
                            Red   = c.R
                        }
                    });
                    wi++;
                }
                hi++;
            }
            l.Pixels = p;
            j.Layers = new List <JImageLayer>()
            {
                l
            };
            return(j);
        }