Click here to Skip to main content
15,908,013 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
Stream stream = new MemoryStream(pict6);

// Stopwatch stopwatch = new Stopwatch();
// stopwatch.Start();
string path = context.Server.MapPath("~/Image/watermark_with_whiteoutline_Stroke2with35%_1200X950.png");

Bitmap _watermarkImage = new Bitmap(path); // watermark image
Bitmap _baseImage = new Bitmap(stream);
Bitmap bmpToSave = new Bitmap(1200, 950);
using (Graphics g = Graphics.FromImage(bmpToSave))
{
g.DrawImage(_baseImage, 0, 0, 1200, 950);
g.Save();
g.Dispose();
}

//Draw the watermark offset 10 pixels from the left and 10 pixels from the top of the base image.
Graphics canvas = Graphics.FromImage(bmpToSave);
canvas.DrawImage(_watermarkImage, new Point(50, 50));
canvas.Save();

bmpToSave.Save(context.Response.OutputStream, ImageFormat.Jpeg);


//clean up

bmpToSave.Dispose();
canvas.Dispose();
_baseImage.Dispose();


The above code works perfectly in webform.. But i want to return as base64string after done watermark.. i guess need to get canvas to byte. if i get byte then i can use Convert.ToBase64String(byte);

But how to get byte from canvas?
Posted
Updated 28-Sep-15 9:45am
v2

1 solution

The question and your problem is not clear. And the purpose of using base64 representation of your image (or anything else) is also not clear.

Anyway, you save an image to a memory stream or temporary file, then take all the memory content using one of Convert.ToBase64String methods:
https://msdn.microsoft.com/en-us/library/system.convert.tobase64string%28v=vs.110%29.aspx[^].

See also:
https://msdn.microsoft.com/en-us/library/system.drawing.image.save%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.io.memorystream%28v=vs.110%29.aspx[^].

—SA
 
Share this answer
 
Comments
CPallini 28-Sep-15 19:18pm    
5.
Sergey Alexandrovich Kryukov 28-Sep-15 19:57pm    
Thank you, Carlo.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900