Pan videoSourcePlayer Aforge
Я использую videoSourcePlayer от Aforge. У меня есть код для увеличения и уменьшения масштаба, который работает, но теперь я хочу панорамировать после увеличения. так что я хочу, чтобы после увеличения масштаба вы могли щелкнуть по месту, и панорамирование поместит местоположение, по которому вы щелкнете, в центр экрана. вот мой код:
private void VideoSourcePlayer_Paint( object sender, PaintEventArgs e )
{
if ( !Visible )
{
return;
}
// is it required to update control's size/position
if ( ( needSizeUpdate ) || ( firstFrameNotProcessed ) )
{
UpdatePosition( );
needSizeUpdate = false;
}
lock ( sync )
{
Graphics g = e.Graphics;
Rectangle rect = this.ClientRectangle;
Pen borderPen = new Pen( borderColor, 1 );
// draw rectangle
g.DrawRectangle( borderPen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1 );
if ( videoSource != null )
{
if ( ( currentFrame != null ) && ( lastMessage == null ) )
{
int width = (int)(this.Width * this.zoomFactor);
int height = (int)(this.Height * this.zoomFactor);
float x = (rect.Width < width) ? (this.zoomPosition.X * (-1) * (this.zoomFactor - 1)) : (rect.Width - width) / 2;
float y = (rect.Height < height) ? (this.zoomPosition.Y * (-1) * (this.zoomFactor - 1)) : (rect.Height - height) / 2;
if (Panflag == true && zoomFactor >1)
{
width = (int)(this.Width* this.zoomFactor);
height = (int)(this.Height * this.zoomFactor);
x = (rect.Width < width) ? this.PanPosition.X * (-1) * (this.PanFactor - 1) : (rect.Width - width) / 2;
y = (rect.Height < height) ? this.PanPosition.Y * (-1) * (this.PanFactor - 1) : (rect.Height - height) / 2;
}
else
{
this.PanPosition.X =(int) x;
this.PanPosition.Y =(int) y;
this.PanFactor = this.zoomFactor;
}
Bitmap frame = ( convertedFrame != null ) ? convertedFrame : currentFrame;
if ( keepRatio )
{
double ratio = (double) frame.Width / frame.Height;
Rectangle newRect = rect;
if ( rect.Width < rect.Height * ratio )
{
newRect.Height = (int) ( rect.Width / ratio );
}
else
{
newRect.Width = (int) ( rect.Height * ratio );
}
newRect.X = ( rect.Width - newRect.Width ) / 2;
newRect.Y = ( rect.Height - newRect.Height ) / 2;
g.DrawImage(currentFrame, x, y, width, height);
// g.DrawImage( frame, newRect.X + 1, newRect.Y + 1, newRect.Width - 2, newRect.Height - 2);
}
else
{
// draw current frame
g.DrawImage(currentFrame, x, y, width, height);
// draw current frame
// g.DrawImage( frame, rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2);
}
firstFrameNotProcessed = false;
}
else
{
// create font and brush
SolidBrush drawBrush = new SolidBrush( this.ForeColor );
g.DrawString( ( lastMessage == null ) ? "Connecting ..." : lastMessage,
this.Font, drawBrush, new PointF( 5, 5 ) );
drawBrush.Dispose( );
}
}
borderPen.Dispose( );
}
}
public void Pan(Point PanPoint)
{
this.PanPosition = PanPoint;
this.PanFactor = 1;
}
проблема, которую я имею, состоит в том, что после того, как я увеличил масштаб и попытался панорамировать, это не помещает местоположение, на которое я щелкаю, в центре моего videoSourcePlayer.