Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
375 views
in Technique[技术] by (71.8m points)

Watermarking image position[asp.net]

I'm trying to follow this article and it was easy to implement text over image and now my problem is in the above mentioned article the image watermark was placed 10 pixels from left so how do I place image similarly to top right,top middle,middle left, center,middle right and similary to bottom.

Here is how it was placed to the top right corner :

int xPosOfWm = ((phWidth - wmWidth)-10);
int yPosOfWm = 10;

grWatermark.DrawImage(
  imgWatermark,
  new Rectangle(
    xPosOfWm, yPosOfWm,
    wmWidth, wmHeight
  ),
  0, 0,
  wmWidth, wmHeight,
  GraphicsUnit.Pixel,
  imageAttributes
);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The problem is that you will have to calculate your image height and width first

calculate the original Image height and width

Image oImage="path";
var oheight=oImage.Height;
var oWidth=oImage.width;

Now Calculate the Image which you want to place over it

var WmImage="path";
var wWheight=WmImage.Height;
var wWidth=WmoImage.width;

top-right

var left=oWidth-wWidth-10;
var top=oheight-10;
//draw the wate mark image on thse point
oImage.DrawImage(imgWatermark,new Rectangle(left,top,wmWidth,
wmHeight),0,0,wmWidth,wmHeight,GraphicsUnit.Pixel,imageAttributes);

similarly you can calculate for other images alos.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...