Пример #1
0
        void DrawFace(int index, ARGB color, IList <Item> bmp, Bitmap32 target)
        {
            int i = index / bmp.Count;

            index %= bmp.Count;

            ARGBImageData bitmap;

            lock (this)
            {
                Item item = bmp[index];
                bitmap = item.Bitmap.Data;
            }

            for (int n = 0; n < bitmap.Data.Length; n++)
            {
                ARGB pixel = bitmap[n];
                if (pixel.Alpha == 0)
                {
                    continue;
                }

                pixel.Red   = (byte)(pixel.Red * color.Red / 255);
                pixel.Green = (byte)(pixel.Green * color.Green / 255);
                pixel.Blue  = (byte)(pixel.Blue * color.Blue / 255);
                bitmap[n]   = pixel;
            }

            {
                int         x           = (AvatarSize - bitmap.Width) / 2;
                int         y           = (AvatarSize - bitmap.Height) / 2;
                int         w           = bitmap.Width;
                int         h           = bitmap.Height;
                Translation?translation = null;
                switch (i)
                {
                default:
                case 0:     // draw normal;
                    break;

                case 1:     // draw flipped
                    translation = new Translation()
                    {
                        FlipHorizontally = true
                    };
                    break;
                }
                target.Draw(bitmap, x, y, w, h, translation);
                Trace.TraceInformation("DrawFace {0} {1} {2} {3} {4} {5}", index, x, y, w, h, translation);
            }
        }
Пример #2
0
        void DrawNose(int index, IList <Item> bmp, Bitmap32 target)
        {
            int i = index / bmp.Count;

            index %= bmp.Count;

            ARGBImageData bitmap;

            lock (this)
            {
                var item = bmp[index];
                bitmap = item.Bitmap.Data;
            }

            int         x = (AvatarSize - bitmap.Width) / 2;
            int         y = (AvatarSize - bitmap.Height) / 2;
            int         w, h;
            Translation?translation = null;

            switch (i)
            {
            default:
            case 0:     // draw normal;
                w = bitmap.Width;
                h = bitmap.Height;
                break;

            case 1:     // draw streched in center
                w           = bitmap.Width * 3 / 4;
                h           = bitmap.Height * 3 / 4;
                x           = (AvatarSize - w) / 2;
                y           = (AvatarSize - h) / 2;
                translation = new Translation()
                {
                    FlipHorizontally = true
                };
                break;
            }
            target.Draw(bitmap, x, y, w, h, translation);
            Trace.TraceInformation("DrawNose {0} {1} {2} {3} {4} {5}", index, x, y, w, h, translation);
        }
Пример #3
0
        /// <summary>
        /// Updates the texture and scale of the underlying Object3D.
        /// </summary>
        /// <param name="maxWidth">max width in pixels.</param>
        /// <param name="maxHeight">max height in pixels.</param>
        public void Update(int maxWidth = 0, int maxHeight = 0)
        {
            if (Sprite == null)
            {
                throw new ObjectDisposedException("RenderText");
            }

            Trace.TraceInformation("Update text font:{0} size:{1} fg:{2} bg:{3} text:{4}", FontName, FontSize, ForeColor, BackColor, Text);
            var bitmap = Bitmap32.Create(FontName, FontSize, ForeColor, BackColor, Text);

            if ((maxWidth > 0) && (maxHeight > 0))
            {
                if ((bitmap.Width > maxWidth) || (bitmap.Height > maxHeight))
                {
                    var b = new Bitmap32(Math.Min(bitmap.Width, maxWidth), Math.Min(bitmap.Height, maxHeight));
                    b.Draw(bitmap, 0, 0);
                    bitmap.Dispose();
                    bitmap = b;
                }
            }
            Sprite.LoadTexture(bitmap);
            Sprite.Scale = Sprite.ScaleFromSize(bitmap.Width, bitmap.Height);
        }
Пример #4
0
 void Draw(WebData data, int color, int nose, int eyes, int mouth, int face, int rotate)
 {
     using (var stream = new MemoryStream())
         using (var bmp = new Bitmap32(AvatarSize, AvatarSize))
         {
             var faceColor = ARGB.FromHSI(color / 256.0f, 1, 1);
             DrawFace(face, faceColor, faces, bmp);
             DrawEyes(eyes, this.eyes, bmp);
             DrawMouth(mouth, mouths, bmp);
             DrawNose(nose, noses, bmp);
             using (var result = new Bitmap32(AvatarSize, AvatarSize))
             {
                 result.Draw(bmp, 0, 0, new Translation()
                 {
                     Rotation = ((rotate % 16) - 7) * 0.02f
                 });
                 result.Save(stream);
             }
             var msg = WebMessage.Create(data.Method, "Avatar created");
             data.Answer = WebAnswer.Raw(data.Request, msg, stream.GetBuffer(), "image/png");
             data.Answer.AllowCompression = false;
             data.Answer.SetCacheTime(TimeSpan.FromDays(1));
         }
 }