使用pan& amp;流式传输大图像Zoom&注解

时间:2013-08-25 20:39:57

标签: c# asp.net openlayers

我有500MB大小的图像我希望在ASP.net中显示此图像,如带缩放和平移功能的地图。我为此找到了OpenLayers,但任何人都可以使用任何框架/库共享任何工作示例,以在ASP.net中实现此功能

2 个答案:

答案 0 :(得分:0)

我建议制作一些较小的图像(Mipmapping http://en.wikipedia.org/wiki/Mipmap)或/并将它们剪成较小的部分。 (Slice up an image into tiles

想一想,你看不到500mb数据的所有像素。只转移你实际看到的内容。

答案 1 :(得分:0)

我找到了一个我想和你分享的答案。这是代码

private static void Split(string fileName, int width, int height)
{
    using (Bitmap source = new Bitmap(fileName))
    {
        bool perfectWidth = source.Width % width == 0;
        bool perfectHeight = source.Height % height == 0;

        int lastWidth = width;
        if (!perfectWidth)
        {
            lastWidth = source.Width - ((source.Width / width) * width);
        }

        int lastHeight = height;
        if (!perfectHeight)
        {
            lastHeight = source.Height - ((source.Height / height) * height);
        }

        int widthPartsCount = source.Width / width + (perfectWidth ? 0 : 1);
        int heightPartsCount = source.Height / height + (perfectHeight ? 0 : 1);

        for (int i = 0; i < widthPartsCount; i++)
            for (int j = 0; j < heightPartsCount; j++)
            {
                int tileWidth = i == widthPartsCount - 1 ? lastWidth : width;
                int tileHeight = j == heightPartsCount - 1 ? lastHeight : height;
                using (Bitmap tile = new Bitmap(tileWidth, tileHeight))
                {
                    using (Graphics g = Graphics.FromImage(tile))
                    {
                        g.DrawImage(source, new Rectangle(0, 0, tile.Width, tile.Height), new Rectangle(i * width, j * height, tile.Width, tile.Height), GraphicsUnit.Pixel);
                    }

                    tile.Save(string.Format("{0}-{1}.png", i + 1, j + 1), ImageFormat.Png);
                }
            }
    }
}