我有一些代码,它采用带有透明度的灰度图像的png,并尝试创建具有给定背景颜色的新图像(从数据库中查找)并将原始图像叠加在其上以创建图像高光和阴影所需的颜色.代码在ASP.NET上下文中运行,但我认为这不相关.
代码在我的本地计算机上运行良好,但是当它部署到我们的UAT服务器时,它会产生意想不到的结果.在UAT上,它创建了一个正确大小的图像,但阴影/高亮区域似乎在每个维度上缩小了20%.所以我看的主要图像最初为5x29,输出图像为5x29,但阴影区域为4x23.2(第24行略有不同,但主要是背景颜色,所以我假设它正在进行一些插值调整大小).
我失败的代码如下:
private byte[] GetImageData(CacheKey key)
{
byte[] imageData;
using (Image image = Image.FromFile(key.FilePath))
using (Bitmap newImage = new Bitmap(image.Width, image.Height))
{
using (Graphics graphic = Graphics.FromImage(newImage))
{
using (SolidBrush brush = new SolidBrush(ColorTranslator.FromHtml(key.BackgroundColour)))
{
graphic.FillRectangle(brush, 0, 0, image.Width, image.Height);
}
graphic.DrawImage(image, 0, 0);
/*
The following lines see if there is a transparency mask to create final
transparency. It does this using GetPixel and SetPixel and just modifying
the alpha of newImage with the alpha of mask. I …Run Code Online (Sandbox Code Playgroud)