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

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...