我正在尝试放大.Net WebBrowser控件中加载的网页上的图片。例如,在(100,100)上有一张100%缩放的图片。现在,我希望将缩放设置为200%,并将图片放在WebBrowser控件的左上角。
它几乎起作用了。如果该点在屏幕的左侧,则可以正常工作。但是,如果该点位于屏幕的右侧,则新计算的点不正确。Y总是正确的。只有X给我带来了问题。
任何人都知道ScrollTo是如何与当前缩放因子相关的。或者它也与其他变量有关?我怀疑问题还在于网页的适应与屏幕的大小有关。(在缩放时,它会删除不包含任何信息的网页的左右边缘。之后,它扩大了内容)。我需要真正的缩放缩放只影响内容,而不是布局。缩放时不会导致回流。
public class MyBrowser : WebBrowser
private int _zoom = 100;
public int Zoom
{
set
{
_zoom = value;
//perform zoom
object pvaIn = _zoom;
try
{
this._axIWebBrowser2.ExecWB(
OLECMDID.OLECMDID_OPTICAL_ZOOM,
OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,
ref pvaIn,
IntPtr.Zero);
}
catch (Exception)
{
throw;
}
}
get
{
return _zoom;
}
}
private Point GetCurrentScroll()
{
int scrollX = this.Document.GetElementsByTagName("HTML")[0].ScrollLeft;
int scrollY = this.Document.GetElementsByTagName("HTML")[0].ScrollTop;
return new Point(scrollX, scrollY);
}
public void ZoomOnPoint(int x, int y, int zoomFactor)
{
int currentZoom = this.Zoom;
Point currentScroll = GetCurrentScroll();
//Set new values
this.Zoom = newZoom;
this.Document.Window.ScrollTo(
currentScroll.X + ((x * currentZoom) / zoomFactor), //X is sometimes correct, mostly on the rightside of the screen
currentScroll.Y + y); //Y is correct
}
}发布于 2016-07-25 11:10:11
在WPF中,我将X和Y值与H和V缩放perc相乘,这是可行的:)
https://stackoverflow.com/questions/7967524
复制相似问题