i want to copy an image from one blob container to another one. I am using the system.drawing to process an image and watermark it. this is throwing an error. i am new to c# ,copied this code from internet. everything works except for the watermarking activity.
I'm getting the following error when the watermark function is called:
2020-06-03T17:28:31.225 [Error] run.csx(150,17): error CS1069: The type name 'Image' could not be found in the namespace 'System.Drawing'. This type has been forwarded to assembly 'System.Drawing.Common, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly. 2020-06-03T17:28:31.279 [Error] run.csx(150,36): error CS0103: The name 'Image' does not exist in the current context
the objective is that i am trying to create a function app to watermark an image and copy it into another blob storage
can you please let me know how best to incorporate System.Drawing.Common
// i want to copy an image from one blob storage to another and watermark it . for it i am using System.Drawing name space instead it asks me to use System.Drawing.Common'. I am new to c# just copied the code from a previously existing work.
#r "Newtonsoft.Json"
#r "System.Drawing"
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using Microsoft.Extensions.Logging;
public static void Run(Stream myBlob, string name, Stream outputBlob, ILogger log)
{
log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
bool result = IsGoodByModerator(myBlob, name, log);
log.LogInformation("Image Moderation " + (result ? "Passed" : "Failed"));
try{
string watermarkText = "PwC";
WriteWatermark(watermarkText,myBlob,outputBlob);
log.LogInformation("Added watermark and copied successfully");
}
catch(Exception ex)
{
log.LogInformation("Watermark Error: " + ex.ToString());
}
}
//Add following method to add text as watermark on the image
private static void WriteWatermark(string watermarkContent, Stream originalImage, Stream newImage)
{
originalImage.Position = 0;
**using (Image inputImage = Image**// i get an error here**strong text**
.FromStream(originalImage, true))
{
using (Graphics graphic = Graphics
.FromImage(inputImage))
{
Font font = new Font("Georgia", 36, FontStyle.Bold);
SizeF textSize = graphic.MeasureString(watermarkContent, font);
float xCenterOfImg = (inputImage.Width / 2);
float yPosFromBottom = (int)(inputImage.Height * 0.90) - (textSize.Height / 2);
graphic.SmoothingMode = SmoothingMode.HighQuality;
graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphic.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphic.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
StringFormat StrFormat = new StringFormat();
StrFormat.Alignment = StringAlignment.Center;
SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(153, 0, 0, 0));
graphic.DrawString(watermarkContent, font, semiTransBrush2, xCenterOfImg + 1, yPosFromBottom + 1, StrFormat);
SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(153, 255, 255, 255));
graphic.DrawString(watermarkContent, font, semiTransBrush, xCenterOfImg, yPosFromBottom, StrFormat);
graphic.Flush();
inputImage.Save(newImage, ImageFormat.Jpeg);
}
}
}