gpt4 book ai didi

asp.net - 尝试将生成的热图保存在 Azure 存储中

转载 作者:行者123 更新时间:2023-12-03 04:47:29 26 4
gpt4 key购买 nike

我有一个热图,当前在独立服务器上运行,我正在将其移植到 Azure 存储。如何将 butmap 文件保存在 Azure 存储中。最初,我的 web.config 文件中有一个条目,它将图像缓存指向花药驱动器(IE)上的直接路径,现在所有内容都将位于存储帐户中的 ~/map_cache 文件夹中。我如何修改它以便在 Azure 中进行本地存储。

protected void Page_Load(object sender, EventArgs e)
{
xxxxxxxdb = new xxxxxxx(ConfigurationManager.AppSettings["xxxxxxx"]);

string imageCachePath = Server.MapPath("/map_cache/HotSpots");
int fileExpirationTime = int.Parse(ConfigurationManager.AppSettings["HotspotImageExpirationTime"]);
Bitmap bitmap;

string requestParam = Page.Request.Params["id"];
string bitmapFileName = Path.Combine(imageCachePath, requestParam + ".png");
if (File.Exists(bitmapFileName) && File.GetCreationTime(bitmapFileName) > DateTime.Now.AddHours(-fileExpirationTime))
{
bitmap = (Bitmap)Image.FromFile(bitmapFileName);
}
else
{
int zoomLevel = requestParam.Length;

double tileX = 0;
double tileY = 0;
for (int index = 0; index < zoomLevel; index++)
{
int digit = int.Parse(requestParam[index].ToString());
tileY += ((digit & 2) / 2) * Math.Pow(2, (zoomLevel - index - 1));
tileX += (digit & 1) * Math.Pow(2, (zoomLevel - index - 1));
}
double pixelXMin = tileX * 256;
double pixelYMin = tileY * 256;
double pixelXMax = (tileX + 1) * 256 - 1;
double pixelYMax = (tileY + 1) * 256 - 1;

double longMin = ((pixelXMin * 360) / (256 * Math.Pow(2, zoomLevel))) - 180;
double longMax = ((pixelXMax * 360) / (256 * Math.Pow(2, zoomLevel))) - 180;
double latMin = Math.Asin((Math.Exp((0.5 - pixelYMin / 256 / Math.Pow(2, zoomLevel)) * 4 * Math.PI) - 1) /
(Math.Exp((0.5 - pixelYMin / 256 / Math.Pow(2, zoomLevel)) * 4 * Math.PI) + 1)) * 180 /
Math.PI;
double latMax = Math.Asin((Math.Exp((0.5 - pixelYMax / 256 / Math.Pow(2, zoomLevel)) * 4 * Math.PI) - 1) /
(Math.Exp((0.5 - pixelYMax / 256 / Math.Pow(2, zoomLevel)) * 4 * Math.PI) + 1)) * 180 /
Math.PI;

double pixelResolution = (Math.Cos(latMax * Math.PI / 180) * 2 * Math.PI * 6378137) / (256 * Math.Pow(2, zoomLevel));
double pixelArea = Math.Pow(pixelResolution, 2);

double maxHotspotDensity = Math.Max(120.0 / zoomLevel, 3.0) / pixelArea;

bitmap = GenerateBlankBitmap();

var accidents = from hs in db.cs_PT_VEGeoDatas
where hs.Latitude <= latMin && hs.Latitude >= latMax
&& hs.Longitude >= longMin && hs.Longitude <= longMax
select new { hs.Latitude, hs.Longitude };

Dictionary<Point, HotSpot> hotSpots = new Dictionary<Point, HotSpot>();
foreach (var accident in accidents)
{
int pixelX, pixelY;
LatLongToPixelXY(accident.Latitude, accident.Longitude, zoomLevel, out pixelX, out pixelY);
pixelX %= 256;
pixelY %= 256;
for (int ix = -doublePixelSize; ix <= doublePixelSize; ix++)
{
for (int iy = -doublePixelSize; iy <= doublePixelSize; iy++)
{
Point point;
bool borderPoint = false;
if (zoomLevel < doublePixelZoomLevel)
{
point = new Point(pixelX, pixelY);
}
else
{
if (pixelX + ix >= 0 && pixelX + ix <= 255 && pixelY + iy >= 0 && pixelY + iy <= 255)
{
point = new Point(pixelX + ix, pixelY + iy);
borderPoint = (ix == -doublePixelSize) || (iy == -doublePixelSize) ||
(ix == doublePixelSize) || (iy == doublePixelSize);
}
else
{
break;
}
}
HotSpot hotSpot;
if (hotSpots.ContainsKey(point))
{
hotSpot = hotSpots[point];
hotSpot.borderPoint &= borderPoint;
hotSpot.count += 1;
}
else
{
hotSpot = new HotSpot { borderPoint = borderPoint, count = 1 };
hotSpots.Add(point, hotSpot);
}
if (zoomLevel < doublePixelZoomLevel)
{
break;
}
}
if (zoomLevel < doublePixelZoomLevel)
{
break;
}
}
}
foreach (var hotspotPixel in hotSpots)
{
double hc = hotspotPixel.Value.count;
double hcDensity = hc / pixelArea;

Color color;
if (!hotspotPixel.Value.borderPoint)
{
color = Color.FromArgb(255, 255,
(int)
Math.Max((maxHotspotDensity - hcDensity) / maxHotspotDensity * 255, 0.0),
0);
}
else
{
color = Color.Black;
}
bitmap.SetPixel(hotspotPixel.Key.X, hotspotPixel.Key.Y, color);
}
bitmap.Save(bitmapFileName);
}

WritePngToStream(bitmap, Response.OutputStream);
}

目前我收到以下错误消息

A generic error occurred in GDI+.

描述:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

异常详细信息:System.Runtime.InteropServices.ExternalException:GDI+ 中发生一般错误。

来源错误:

执行当前 Web 请求期间生成未处理的异常。有关异常来源和位置的信息可以使用下面的异常堆栈跟踪来识别。

堆栈跟踪:

[ExternalException (0x80004005): GDI+ 中发生一般错误。] System.Drawing.Image.Save(字符串文件名,ImageCodecInfo编码器,EncoderParameters编码器参数)+772265 C:\Projects\xxx\xxx\SpeedTrap\HotSpotTileServer.aspx.cs 中的 HotSpotTileServer.Page_Load(对象发送者,EventArgs e):141 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,对象o,对象t,EventArgs e)+25 System.EventHandler.Invoke(对象发送者,EventArgs e)+0 System.Web.UI.Control.LoadRecursive() +71 System.Web.UI.Page.ProcessRequestMain( bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint)+3048

版本信息:Microsoft .NET Framework 版本:4.0.30319; ASP.NET版本:4.0.30319.1

最佳答案

您可以尝试以下三件事:

毫无疑问,我推荐的是最后一个 - 它快速、灵活且可扩展。

关于asp.net - 尝试将生成的热图保存在 Azure 存储中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5668704/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com