Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

resize image and add watermark c#

void waterMarkOnBottomRight(Image img, Image watermarkImage, string saveFileName)
    {
        double imageHeightBrand = Convert.ToDouble(watermarkImage.Height);
        double imageWidthBrand = Convert.ToDouble(watermarkImage.Width);
        double ratioBrand = imageWidthBrand / imageHeightBrand;

        double imageHeightBild = Convert.ToDouble(img.Height); //height of the image to watermark
        double imageWidthBild = Convert.ToDouble(img.Width);
        var imageWidthTmpBranding = imageWidthBild * 0.2; //the watermark width, but only 20% size of the image to watermark
        var imageHeightTmpBranding = imageWidthTmpBranding / ratioBrand; //height of watermark, preserve aspect ratio
        int imageWidthBranding = Convert.ToInt32(imageWidthTmpBranding); //convert in into int32 (see method below)
        int imageHeightBranding = Convert.ToInt32(imageHeightTmpBranding);

        int watermarkX = (int)(imageWidthBild - imageWidthBranding); // Bottom Right
        int watermarkY = (int)(imageHeightBild - imageHeightBranding);

        using (Graphics g = Graphics.FromImage(img)) 
            g.DrawImage(watermarkImage,
                new Rectangle(watermarkX, watermarkY, imageWidthBranding, imageHeightBranding),
                new Rectangle(0, 0, (int)imageWidthBrand, (int)imageHeightBrand),
                GraphicsUnit.Pixel);
        img.Save(saveFileName);
    }
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# summary angle brackets 
Csharp :: c# compare 2 binary files 
Csharp :: Thread.Sleep() without freezing the UI 
Csharp :: afaik 
Csharp :: number to string ef example c# 
Csharp :: C# console out restore 
Csharp :: c# extend array 
Csharp :: c# download to string 
Csharp :: return every digit on a string c# 
Csharp :: jsonconvert serializeobject and jsonconvert deserialize to list 
Csharp :: c# odd or even 
Csharp :: f# set function how to ignore duplicates 
Csharp :: linq conditionnally add where clause 
Csharp :: c# place all keys in dictionary into array 
Csharp :: c# sort word 
Csharp :: user input in c# 
Csharp :: cqrs design pattern .net core 
Csharp :: wpf xaml group of buttons 
Csharp :: c# read only file used by other app 
Csharp :: unity variable in editor limit value 
Csharp :: TTTTTTTTTTTTTTTTTTTTESTTT 
Csharp :: connection string of bulk insert with csv in c# 
Csharp :: ow-to-return-http-500-from-asp-net-core-rc2-web-api 
Csharp :: how to if i enter 1 go to this program C# 
Csharp :: how to call method in different project in c# visual studio 
Csharp :: universities in greece 
Csharp :: draw table in console c# 
Csharp :: c# loop array back 
Csharp :: c sharp or operator in if statement 
Csharp :: get multi-selected rows gridcontrol devexpress 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =