ByteScout Watermarking SDK - ASP.NET - Add Watermark Image From Stream - ByteScout

ByteScout Watermarking SDK – ASP.NET – Add Watermark Image From Stream

  • Home
  • /
  • Articles
  • /
  • ByteScout Watermarking SDK – ASP.NET – Add Watermark Image From Stream

How to add watermark image from stream in ASP.NET with ByteScout Watermarking SDK

Tutorial on how to add watermark image from stream in ASP.NET

The sample shows steps and algorithm of how to add watermark image from stream and how to make it work in your ASP.NET application. What is ByteScout Watermarking SDK? It is the powerful SDK can apply high quality visible and semivisible watermarks into PNG, JPG, BMP pictures and TIFF scans. Doznes of presets are available, multiple watermarks can be applied. Can add logo based watermark from image, can adjust font size, font family, colors. It can help you to add watermark image from stream in your ASP.NET application.

Fast application programming interfaces of ByteScout Watermarking SDK for ASP.NET plus the instruction and the code below will help you quickly learn how to add watermark image from stream. In order to implement the functionality, you should copy and paste this code for ASP.NET below into your code editor with your app, compile and run your application. Detailed tutorials and documentation are available along with installed ByteScout Watermarking SDK if you’d like to dive deeper into the topic and the details of the API.

Free trial version of ByteScout Watermarking SDK is available on our website. Documentation and source code samples are included.

Try it today: Get 60 Day Free Trial or sign up for Web API

Default.aspx
      
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="HelloWorld._Default" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <h2> Welcome to ASP.NET! </h2> <p> To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>. </p> <p> You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409" title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>. </p> </asp:Content>

Try it today: Get 60 Day Free Trial or sign up for Web API

Default.aspx.cs
      
using System; using System.Drawing; using System.IO; using System.Web.UI; using Bytescout.Watermarking; using Bytescout.Watermarking.Presets; namespace HelloWorld { public partial class _Default : Page { protected void Page_Load(object sender, EventArgs e) { // Create Watermarker instance Watermarker waterMarker = new Watermarker(); // Initialize library waterMarker.InitLibrary("demo", "demo"); // Set input file name string inputFilePath = MapPath("my_sample_image.jpg"); // Create sample input stream Stream inputStream = new FileStream(inputFilePath, FileMode.Open); // Create image from stream Image image = new Bitmap(inputStream); // Add image to apply watermarks to waterMarker.AddInputFile(image); // Create watermark TextFitsPage preset = new TextFitsPage(); preset.Text = "Bytescout Watermarking"; preset.TextColor = Color.Aqua; preset.Transparency = 25; // Add watermark to Watermarker waterMarker.AddWatermark(preset); // Clear http output Response.Clear(); // Set the content type to JPEG Response.ContentType = "image/jpeg"; // Add content type header Response.AddHeader("Content-Type", "image/jpeg"); // Set the content disposition Response.AddHeader("Content-Disposition", "inline;filename=my_sample_image.jpg"); // Set Response.OutputStream as result image destination waterMarker.OutputOptions.OutputStream = Response.OutputStream; // Execute watermarking waterMarker.Execute(0); // Cleanup image.Dispose(); inputStream.Dispose(); Response.End(); } } }

Try it today: Get 60 Day Free Trial or sign up for Web API

Default.aspx.designer.cs
      
//------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ namespace HelloWorld { public partial class _Default { } }

Try it today: Get 60 Day Free Trial or sign up for Web API

Global.asax.cs
      
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Security; using System.Web.SessionState; namespace HelloWorld { public class Global : System.Web.HttpApplication { void Application_Start(object sender, EventArgs e) { // Code that runs on application startup } void Application_End(object sender, EventArgs e) { // Code that runs on application shutdown } void Application_Error(object sender, EventArgs e) { // Code that runs when an unhandled error occurs } void Session_Start(object sender, EventArgs e) { // Code that runs when a new session is started } void Session_End(object sender, EventArgs e) { // Code that runs when a session ends. // Note: The Session_End event is raised only when the sessionstate mode // is set to InProc in the Web.config file. If session mode is set to StateServer // or SQLServer, the event is not raised. } } }

Try it today: Get 60 Day Free Trial or sign up for Web API

HelloWorld.csproj
      
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProductVersion> </ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{093FF804-2B76-4771-9F40-505B76ED3CAE}</ProjectGuid> <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids> <OutputType>Library</OutputType> <AppDesignerFolder>Properties</AppDesignerFolder> <RootNamespace>HelloWorld</RootNamespace> <AssemblyName>HelloWorld</AssemblyName> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <UseIISExpress>false</UseIISExpress> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> <Reference Include="Bytescout.Watermarking, Version=3.0.0.194, Culture=neutral, PublicKeyToken=f7dd1bd9d40a50eb, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>C:\Program Files\Bytescout Watermarking SDK\net4.00\Bytescout.Watermarking.dll</HintPath> </Reference> <Reference Include="Microsoft.CSharp" /> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Core" /> <Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Web.Extensions" /> <Reference Include="System.Xml.Linq" /> <Reference Include="System.Drawing" /> <Reference Include="System.Web" /> <Reference Include="System.Xml" /> <Reference Include="System.Configuration" /> <Reference Include="System.Web.Services" /> <Reference Include="System.EnterpriseServices" /> <Reference Include="System.Web.DynamicData" /> <Reference Include="System.Web.Entity" /> <Reference Include="System.Web.ApplicationServices" /> </ItemGroup> <ItemGroup> <Content Include="my_sample_image.jpg"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> <Content Include="Default.aspx" /> <Content Include="Global.asax" /> <Content Include="Web.config" /> <Content Include="Web.Debug.config"> <DependentUpon>Web.config</DependentUpon> </Content> <Content Include="Web.Release.config"> <DependentUpon>Web.config</DependentUpon> </Content> </ItemGroup> <ItemGroup> <Compile Include="Default.aspx.cs"> <DependentUpon>Default.aspx</DependentUpon> <SubType>ASPXCodeBehind</SubType> </Compile> <Compile Include="Default.aspx.designer.cs"> <DependentUpon>Default.aspx</DependentUpon> </Compile> <Compile Include="Global.asax.cs"> <DependentUpon>Global.asax</DependentUpon> </Compile> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Site.Master.cs"> <DependentUpon>Site.Master</DependentUpon> <SubType>ASPXCodeBehind</SubType> </Compile> <Compile Include="Site.Master.designer.cs"> <DependentUpon>Site.Master</DependentUpon> </Compile> </ItemGroup> <ItemGroup /> <ItemGroup> <Content Include="Site.Master" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" /> <ProjectExtensions> <VisualStudio> <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}"> <WebProjectProperties> <UseIIS>False</UseIIS> <AutoAssignPort>True</AutoAssignPort> <DevelopmentServerPort>1745</DevelopmentServerPort> <DevelopmentServerVPath>/</DevelopmentServerVPath> <IISUrl> </IISUrl> <NTLMAuthentication>False</NTLMAuthentication> <UseCustomServer>False</UseCustomServer> <CustomServerUrl> </CustomServerUrl> <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile> </WebProjectProperties> </FlavorProperties> </VisualStudio> </ProjectExtensions> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> </Target> <Target Name="AfterBuild"> </Target> --> </Project>

Try it today: Get 60 Day Free Trial or sign up for Web API

HelloWorld.sln
      
Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld", "HelloWorld.csproj", "{093FF804-2B76-4771-9F40-505B76ED3CAE}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {093FF804-2B76-4771-9F40-505B76ED3CAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {093FF804-2B76-4771-9F40-505B76ED3CAE}.Debug|Any CPU.Build.0 = Debug|Any CPU {093FF804-2B76-4771-9F40-505B76ED3CAE}.Release|Any CPU.ActiveCfg = Release|Any CPU {093FF804-2B76-4771-9F40-505B76ED3CAE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal

Try it today: Get 60 Day Free Trial or sign up for Web API

Site.Master.cs
      
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace HelloWorld { public partial class SiteMaster : System.Web.UI.MasterPage { protected void Page_Load(object sender, EventArgs e) { } } }

Try it today: Get 60 Day Free Trial or sign up for Web API

Site.Master.designer.cs
      
//------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ namespace HelloWorld { public partial class SiteMaster { /// <summary> /// HeadContent control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.ContentPlaceHolder HeadContent; /// <summary> /// MasterPageScriptManager control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.ScriptManager MasterPageScriptManager; /// <summary> /// HeadLoginView control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.LoginView HeadLoginView; /// <summary> /// HeadHomeLink control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.HtmlControls.HtmlAnchor HeadHomeLink; /// <summary> /// HeadAboutLink control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.HtmlControls.HtmlAnchor HeadAboutLink; /// <summary> /// MainContent control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.ContentPlaceHolder MainContent; } }

Try it today: Get 60 Day Free Trial or sign up for Web API

Web.Debug.config
      
<?xml version="1.0"?> <!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 --> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <!-- In the example below, the "SetAttributes" transform will change the value of "connectionString" to use "ReleaseSQLServer" only when the "Match" locator finds an atrribute "name" that has a value of "MyDB". <connectionStrings> <add name="MyDB" connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> </connectionStrings> --> <system.web> <!-- In the example below, the "Replace" transform will replace the entire <customErrors> section of your web.config file. Note that because there is only one customErrors section under the <system.web> node, there is no need to use the "xdt:Locator" attribute. <customErrors defaultRedirect="GenericError.htm" mode="RemoteOnly" xdt:Transform="Replace"> <error statusCode="500" redirect="InternalError.htm"/> </customErrors> --> </system.web> </configuration>

Try it today: Get 60 Day Free Trial or sign up for Web API

Web.Release.config
      
<?xml version="1.0"?> <!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 --> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <!-- In the example below, the "SetAttributes" transform will change the value of "connectionString" to use "ReleaseSQLServer" only when the "Match" locator finds an atrribute "name" that has a value of "MyDB". <connectionStrings> <add name="MyDB" connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> </connectionStrings> --> <system.web> <compilation xdt:Transform="RemoveAttributes(debug)" /> <!-- In the example below, the "Replace" transform will replace the entire <customErrors> section of your web.config file. Note that because there is only one customErrors section under the <system.web> node, there is no need to use the "xdt:Locator" attribute. <customErrors defaultRedirect="GenericError.htm" mode="RemoteOnly" xdt:Transform="Replace"> <error statusCode="500" redirect="InternalError.htm"/> </customErrors> --> </system.web> </configuration>

Try it today: Get 60 Day Free Trial or sign up for Web API

Web.config
      
<?xml version="1.0"?> <!-- For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <connectionStrings> <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" /> </connectionStrings> <system.web> <compilation debug="true" targetFramework="4.0" /> <authentication mode="Forms"> <forms loginUrl="~/Account/Login.aspx" timeout="2880" /> </authentication> <membership> <providers> <clear/> <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /> </providers> </membership> <profile> <providers> <clear/> <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/> </providers> </profile> <roleManager enabled="false"> <providers> <clear/> <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" /> <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" /> </providers> </roleManager> </system.web> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </configuration>

Try it today: Get 60 Day Free Trial or sign up for Web API

MORE INFORMATION

Get 60 Day Free Trial or Visit ByteScout Watermarking SDK page

Explore ByteScout Watermarking SDK documentation

WEB API VERSION

Sign Up for free Web API key

Explore Web API Documentation

Tutorials:

prev
next