I'm new to the .NET world and I'm having a problem uploading images to the site. I am using a function to add the watermark in the photo as it is sent but apparently Azure no longer accepts the use of System.Drawing.Bitmap. I tried to find some alternative but I could not, any suggestions? Here is the code:
private void AdicionarMarcaDagua(HttpPostedFileBase arquivo, string caminhoTemp, string caminhoFotos, string caminhoThumbs, int id)
{
string Copyright = "www.vidaideal.com";
Image imgPhotoTemp = Image.FromFile(caminhoTemp + arquivo.FileName);
int novaAltura = 600;
int novaLargura = 800;
Bitmap novaImagem = new Bitmap(novaLargura, novaAltura);
Graphics g = Graphics.FromImage((Image)novaImagem);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(imgPhotoTemp, 0, 0, novaLargura, novaAltura);
g.Dispose();
novaImagem.Save(caminhoTemp + id +"_" + arquivo.FileName);
imgPhotoTemp.Dispose();
Image imgPhoto = Image.FromFile(caminhoTemp + id + "_" + arquivo.FileName);
int phWidth = imgPhoto.Width;
int phHeight = imgPhoto.Height;
Bitmap bmPhoto = new Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
Image imgWatermark = new Bitmap(Server.MapPath("~/Images/Layout/") + "\watermark-color.png");
int wmWidth = imgWatermark.Width;
int wmHeight = imgWatermark.Height;
grPhoto.SmoothingMode = SmoothingMode.AntiAlias;
grPhoto.DrawImage(imgPhoto, new Rectangle(0, 0, phWidth, phHeight), 0, 0, phWidth, phHeight, GraphicsUnit.Pixel);
int[] sizes = new int[] { 16, 14, 12, 10, 8, 6, 4 };
Font crFont = null;
SizeF crSize = new SizeF();
for (int i = 0; i < 7; i++)
{
crFont = new Font("Verdana", sizes[i], FontStyle.Bold);
crSize = grPhoto.MeasureString(Copyright, crFont);
if ((ushort)crSize.Width < (ushort)phWidth)
break;
}
int yPixlesFromBottom = (int)(phHeight * .05);
float yPosFromBottom = ((phHeight - yPixlesFromBottom) - (crSize.Height / 2));
float xCenterOfImg = (phWidth / 2);
StringFormat StrFormat = new StringFormat();
StrFormat.Alignment = StringAlignment.Center;
SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(153, 0, 0, 0));
grPhoto.DrawString(Copyright, crFont, semiTransBrush2, new PointF(xCenterOfImg + 1, yPosFromBottom + 1), StrFormat);
SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(153, 255, 255, 255));
grPhoto.DrawString(Copyright, crFont, semiTransBrush, new PointF(xCenterOfImg, yPosFromBottom), StrFormat);
Bitmap bmWatermark = new Bitmap(bmPhoto);
bmWatermark.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
Graphics grWatermark = Graphics.FromImage(bmWatermark);
ImageAttributes imageAttributes = new ImageAttributes();
ColorMap colorMap = new ColorMap();
colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
ColorMap[] remapTable = { colorMap };
imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
float[][] colorMatrixElements = {
new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
new float[] {0.0f, 0.0f, 0.0f, 0.3f, 0.0f},
new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}
};
ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);
int xPosOfWm = ((phWidth - wmWidth) - 10);
int yPosOfWm = 10;
grWatermark.DrawImage(imgWatermark, new Rectangle(xPosOfWm, yPosOfWm, wmWidth, wmHeight), 0, 0, wmWidth, wmHeight, GraphicsUnit.Pixel, imageAttributes);
imgPhoto = bmWatermark;
grPhoto.Dispose();
grWatermark.Dispose();
imgPhoto.Save(caminhoFotos + id + "_" + arquivo.FileName, ImageFormat.Jpeg);
imgPhoto.Dispose();
imgWatermark.Dispose();
GerarThumb(caminhoFotos, arquivo, caminhoThumbs, id);
}
I tried to find in Azure itself some documentation about it but I could not find it, I saw something about using Blob but at first I want to avoid the use of this resource because it increases the monthly cost of operation without necessity.
The .NET that is being used is 4.7.1 Full, C # language with MVC 5.