Пример #1
0
        public override string ToHtml(out int width, out int height)
        {
            var resizeW = (int)Math.Ceiling((double)Image.Width / PixelSize);
            var resizeH = (int)Math.Ceiling((double)Image.Height / PixelSize);
            var bitmap = new LockBitmap(ResizeImage(resizeW, resizeH));
            bitmap.LockBits();
            width = resizeW * PixelSize;
            height = resizeH * PixelSize;
            var html = new StringBuilder(String.Format("<div style=\"overflow:hidden;width:{0}px;height:{1}px;\">",
                                                       width,
                                                       height));

            for (var y = 0; y < bitmap.Height; y++)
            {
                for (var x = 0; x < bitmap.Width; x++)
                {
                    var color = bitmap.GetPixel(x, y);
                    html.Append(String.Format("<div style=\"width:{0}px;height:{0}px;background:#{1:X2}{2:X2}{3:X2};float:left\"><b></b></div>", PixelSize, color.R, color.G, color.B));
                }
                // html.Append("<div style=\"clear:both;\"></div>");
            }

            return html.Append("</div>").ToString();
        }
Пример #2
0
        public override string ToHtml(out int width, out int height)
        {
            var resizeW = (int)Math.Ceiling((double)Image.Width / PixelSize);
            var resizeH = (int)Math.Ceiling((double)Image.Height / PixelSize);
            var bitmap = new LockBitmap(ResizeImage(resizeW, resizeH));
            bitmap.LockBits();
            width = resizeW * PixelSize;
            height = resizeH * PixelSize;
            var html = new StringBuilder(String.Format("<table width=\"{0}\" height=\"{1}\" cellpadding=0 cellspacing=0>",
                                                       width,
                                                       height));

            for (var y = 0; y < bitmap.Height; y++)
            {
                html.Append("<tr>");
                for (var x = 0; x < bitmap.Width; x++)
                {
                    var color = bitmap.GetPixel(x, y);
                    html.Append(String.Format("<td bgcolor=\"#{0:X2}{1:X2}{2:X2}\"><b></b></td>", color.R, color.G, color.B));
                }
                html.Append("</tr>");
            }

            return html.Append("</table>").ToString();
        }