Watermarking image position[asp.net] - 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
);

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.

The current code doesn't place the watermark at the top left, it places at the top right.
To place it at the top left, you use:
int xPosOfWm = 10;
int yPosOfWm = 10;
To position the watermark horisontally at the left, center and right:
int xPosOfWm = 10;
int xPosOfWm = (phWidth - wmWidth) / 2;
int xPosOfWm = (phWidth - wmWidth) - 10;
To position the watermark vertically at the top, middle and bottom:
int yPosOfWm = 10;
int yPosOfWm = (phHeight - wmHeight) / 2;
int yPosOfWm = (phHeight - wmHeight) - 10;
Just combine one horisontal with one vertical to get any combination that you want.

Related

Problems keeping orthographic projection proportional using Qt/OpenGL

I am having a difficult time understanding what values I should use in the call I make to QMatrix4x4::ortho(left, right, bottom, top, near, far).
Specifically, I don't understand the documentation for the values for left,right,bottom, and top. I have a working demo that can draw the OpenGL monkey with a projection matrix. I set up the demo so that when I hit 'O' on the keyboard, it switches the projection matrix from perspective to orthographic. The perspective projection works well in that it keeps the model's aspect ratio constant (i.e. it doesn't stretch in width or height). Here's the function that gets called when either the 'O' or 'P' key gets called and updates m_proj. It's a bit of a hot mess as you can see I've tried a bunch of ideas and none of them really works the way I would like.
Thanks for any insight that would help me understand this. Other helpful details: my view eye is at z=2 facing center (0,0,0) with up being (0,1,0).
void AppGLScene::setProjectionMatrix(void)
{
m_projectionMatrix.setToIdentity();
float windowWidth = rect().width();
float windowHeight = rect().height();
float left, right, bottom, top;
float aratio = (float) windowWidth / (float) windowHeight;
qDebug() << "win wid, win hei" << windowWidth << windowHeight;
// I modify the vertical FOV in an attempt to keep the size of the
// model the same as the vertical size of the window changes.
//
float vFov = 90 * ((float)windowHeight / m_initialWinHeight);
qDebug() << "vFov" << vFov;
switch (m_proj)
{
case PROJ_PERSP:
m_projectionMatrix.perspective(vFov, qreal(windowWidth)/qreal(windowHeight), 0.5, 40);
break;
case PROJ_ORTHO:
default:
// left = rect().x();
// right = rect().x() + rect().width();
// bottom = rect().y();
// top = rect().y() + rect().height();
if (windowWidth > windowHeight)
{
left = -(3.0 - ((float)windowHeight/(float)windowWidth));
right = -left;
bottom = -3.0;
top = 3.0;
}
else
{
left = -3.0;
right = 3.0;
bottom = -(3.0 - ((float)windowWidth/(float)windowHeight));
top = -bottom;
}
qDebug() << "l r b t = " << left << right << bottom << top;
m_projectionMatrix.ortho(left, right, bottom, top, 0.5, 40);
// m_projectionMatrix.ortho(-3.0, 3.0, -3.0, 3.0, 0.5, 40);
// m_projectionMatrix.ortho(-aratio, aratio, -aratio, aratio, 0.5, 40);
break;
}
}
To avoid stretching your objects in either direction, you need to have (right - left) / (top - bottom) match the aspect ratio of the window. Which in your case you can ensure by having right be the value of top multiplied by the aspect ratio.
It looks like you want to use the range [-3.0, 3.0] for the shorter window dimension, and adjust the longer one accordingly. The above then translates into:
if (windowWidth > windowHeight)
{
top = 3.0f;
bottom = -top;
right = top * aratio;
left = -right;
}
else
{
right = 3.0f;
left = -right;
top = right / aratio;
bottom = -top;
}
Note that right / top = aratio for both cases.

Scrollbar scroll 'size'

How would I, instead of 'scrolling' as much height as I want, a fixed height?
I.e a div is 50px high and each time I scroll down I want to go down 50px instead of just 'stopping' where you want.
Thanks in advance.
You can override scrolling of the div in such a way:
$("#scrollableContainer").scroll(function(e) {
//measure how far are you from the top of the scrollable container
var top = $("#scrollableContainer").scrollTop();
var scrollIncrement = 50; //50px
if (top % scrollIncrement!= 0) {
var delta;
//calculate delta you need to align the position with
if(e.detail > 0) {
//scroll down
delta = ((top / scrollIncrement) + 1) * scrollIncrement) - top;
}else {
//scroll up
delta = ((top / scrollIncrement) - 1) * scrollIncrement) - top;
}
$("#scrollableContainer").scrollTop(delta);
}
});

How can I combine animations in onFrame?

My goal is to make the wave segments move from the bottom of the screen to the top, while animating the wave. The code I'm using to make the wave comes from paperjs.org:
http://paperjs.org/tutorials/animation/creating-animations/#animating-path-segments
Ideally, I'd like to close the path with points that stay anchored to the bottom left and right of the viewport. This is so I can fill the wave with a solid color.
Simply add points to your path before and after the for-loop that generates your evenly distributed segments:
path.add(new Point(0, 1) * view.size);
// Add 5 segment points to the path spread out
// over the width of the view:
for (var i = 0; i <= amount; i++) {
path.add(new Point(i / amount, 1) * view.size);
}
path.add(new Point(1, 1) * view.size);
This will give you points anchored to the bottom of your view. To account for the new segments, change the for loop in the onFrame function to read:
for (var i = 1; i <= amount+1; i++) {

How do I allow a user to smoothly resize elements in Flex 3

I have a Flex 3 app that has elements that a user can add to the main canvas then resize and reposition.
There are 3 key functions I am using for the resize which are as follows:
When the resize begins:
private function startResize(event:MouseEvent):void
{
RESIZE_START_MOUSE_X = event.localX;
RESIZE_START_MOUSE_Y = event.localY;
RESIZE_START_WIDTH = this.width;
RESIZE_START_HEIGHT = this.height;
RESIZE_START_X = this.x;
RESIZE_START_Y = this.y;
RESIZE_BOUND = calculateResizeBound(event);
addEventListener(MouseEvent.MOUSE_MOVE, resizeMouseHandler);
isResizing = true;
}
When the resize is complete:
private function endResize():void
{
RESIZE_START_MOUSE_X = -1;
RESIZE_START_MOUSE_Y = -1;
RESIZE_START_WIDTH = this.width;
RESIZE_START_HEIGHT = this.height;
RESIZE_START_X = -1;
RESIZE_START_Y = -1;
RESIZE_BOUND = '';
removeEventListener(MouseEvent.MOUSE_MOVE, resizeMouseHandler);
isResizing = false;
}
Whilst the user is resizing:
private function resizeMouseHandler(event:MouseEvent):void
{
var deltaX:Number = event.localX - RESIZE_START_MOUSE_X;
var deltaY:Number = event.localY - RESIZE_START_MOUSE_Y;
if (RESIZE_BOUND.indexOf('T') > -1)
//We are fixing the top so move the bottom edge
{
this.height = RESIZE_START_HEIGHT + deltaY;
}
if (RESIZE_BOUND.indexOf('B') > -1)
//We are fixing the bottom so move the top edge
{
this.y = RESIZE_START_Y + deltaY;
this.height = RESIZE_START_HEIGHT - deltaY;
}
if (RESIZE_BOUND.indexOf('L') > -1)
//We are fixing the left so move the right edge
{
this.width = RESIZE_START_WIDTH + deltaX;
}
if (RESIZE_BOUND.indexOf('R') > -1)
//We are fixing the right so move the left edge
{
this.x = RESIZE_START_X + deltaX;
this.width = RESIZE_START_WIDTH - deltaX;
}
}
There is another function referenced in these called calculateResizeBound(). What this does is return a string indicating which edge / corner should remain fixed during the resize. Eg 'TL' means that the top left corner should stay fixed, 'BR' means bottom right, 'L' means just the left edge etc etc
When the resize starts from the 'normal' position, ie the top left corner stays fixed, everything works great. Similarly with the left or top edges fixed. However for the bottom and right cases, I need to reposition the element at the same time as resizing it since all the co-ordinates are calculated from the top left.
The problem that I have is that when it does this, the resize is not smooth, it keeps jumping up and down slightly as you resize it. Not only that but when you resize from the 'normal' edges the cursor position remains fixed relative to the fixed edge / corner however from one of the other edges, you can see it start to drift away from the edge / corner as you resize.
With this kind of thing, it is easy to get the + / - of the different bits of the calculation muddled but since the resize is working in the correct direction each time, I assume I have these correct.
So presumably the problem is coming from the simultaneous moving and resizing but I can't find a work-around for it. Any thoughts / suggestions would be much appreciated
Doug McCune has an awesome Resize wrapper that you can use to resize elements. Then you just need to add a mover on it. See the blog post for code/sample: http://dougmccune.com/blog/2007/08/17/my-360flex-slides-and-code/

How can I have a sliding menu div that doesn't move unless the page is scrolled down past a certain point

I have a menu div that I want to slide down so it's always visible, but I want it to be positioned under my title div. I don't want it to move until the top of the menu hits the top of the screen and then stay in place. Basically I want a sliding menu with a maximum height it can slide to.
I think I understand what you're talking about—we used a similar technique on The King with jQuery. Here's how:
///// CONFIGURATION VARIABLES:
var name = "#rightsidebar";
var menu_top_limit = 241;
var menu_top_margin = 20;
var menu_shift_duration = 500;
var menuYloc = null;
///////////////////////////////////
$(window).scroll(function()
{
// Calculate the top offset, adding a limit
offset = menuYloc + $(document).scrollTop() + menu_top_margin;
// Limit the offset to 241 pixels...
// This keeps the menu out of our header area:
if(offset < menu_top_limit)
offset = menu_top_limit;
// Give it the PX for pixels:
offset += "px";
// Animate:
$(name).animate({top:offset},{duration:menu_shift_duration,queue:false});
});
(Hat tip to #soyrex who wrote this code.)
Slashdot does this. Check it out at, for example, http://tech.slashdot.org/tech/08/10/22/1246200.shtml
You may be able to lift the technique from their site.

Resources