2013-02-10 85 views
-2

我想按照這個article,很容易實現text over image,現在我的問題是上面提到的文章中的圖片水印放入10像素從左所以如何將圖像放置在右上角,頂部中間,中間左側,中間,中間右側和相似處。水印圖像位置[asp.net]

這裏是它是如何放置到右上角:

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

grWatermark.DrawImage(
    imgWatermark, 
    new Rectangle(
    xPosOfWm, yPosOfWm, 
    wmWidth, wmHeight 
), 
    0, 0, 
    wmWidth, wmHeight, 
    GraphicsUnit.Pixel, 
    imageAttributes 
); 

回答

0

的問題是,你將不得不計算出你的形象的高度和寬度第一

計算原始圖像的高度和寬度

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

現在計算要放置在它

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

右上角

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); 

同樣可以阿洛斯計算其他圖像。

0

當前的代碼不會在左上方放置水印,它將放置在右上角。

要將其放在左上角,您可以使用:

int xPosOfWm = 10; 
int yPosOfWm = 10; 

要在左,中,右horisontally定位水印:

int xPosOfWm = 10; 

int xPosOfWm = (phWidth - wmWidth)/2; 

int xPosOfWm = (phWidth - wmWidth) - 10; 

在頂部垂直定位水印,中間和底部:

int yPosOfWm = 10; 

int yPosOfWm = (phHeight - wmHeight)/2; 

int yPosOfWm = (phHeight - wmHeight) - 10; 

只需將一個水平線與一個垂直線組合即可獲得任意組合你想要的東西。