gpt4 book ai didi

c# - 基于鼠标滚轮的 2D 图像缩放中出现的白色补丁

转载 作者:太空宇宙 更新时间:2023-11-03 13:09:11 25 4
gpt4 key购买 nike

我们目前在 PlotCube 上使用缩放功能,该功能使用鼠标滚轮放大和缩小二维图像图 (TwoDMode=true)。我们还使用通过缩放选择矩形功能获得的缩放,同样由 ILNumerics 库提供。问题是,当我们使用鼠标滚轮充分放大/缩放 2D 图像时,图像上开始出现白色补丁(我认为这与 View 剪切 Pane 有关)。当我们使用缩放选择矩形功能进行大量放大时,不会发生这种情况。

这个问题有解决办法吗?还是我们必须自己实现鼠标滚轮缩放(通过捕获鼠标滚轮事件并相应地更改限制)。

这是一些示例代码,将其弹出到基本应用程序(Windows 窗体或 WPF)中。 ILPanel 实例应称为 iLPanel 并将其停靠到整个主窗口或父窗口内容。在窗口“加载”事件期间调用方法“IlPanelOnLoad()”。

private void IlPanelOnLoad()
{
ilPanel.Scene = PlotImageTest();
var pc = ilPanel.Scene.First<ILPlotCube>();
pc.DataScreenRect = new RectangleF(0.15f, 0.10f, 0.80f, 0.70f);

ilPanel.Scene.Configure();
ilPanel.Refresh();
}

private ILScene PlotImageTest()
{
var scene = new ILScene();

// the data to show comes from a predefined
// example dataset contained in ILNumerics
ILArray<float> A = ILMath.tosingle(ILSpecialData.terrain["0:240;0:240"]);
// we fetch to min and max values for tight limits
float min, max;
A.GetLimits(out min, out max);

// Create the surface
ILSurface surface = new ILSurface(A);
surface.Wireframe.Visible = false; // for fast rendering
surface.Markable = false;

// scene setup: add a plotcube in 2D mode...
var plotCube = scene.Add(new ILPlotCube(twoDMode: true) {
// add a surface to the plot cube
Children = {
surface
},
// configure the datascreen rect. This makes the plotcube
// content fill the whole panel area
DataScreenRect = new RectangleF(0.13f, 0.13f, 0.74f, 0.74f),
// configure the plot cube limits to show no margins
Limits = {
XMin = 0, YMin = 0, ZMin = min,
XMax = A.S[1] - 1, YMax = A.S[0] - 1, ZMax = max + 1
}
});

return scene;
}

最佳答案

必须快速创建一个修复程序供我们自己使用,这里是:

    private void IlPanelOnLoad()
{
...

var plotCube = GetPlotCube();
if (plotCube != null)
{
plotCube.MouseWheel += OnPlotCubeMouseWheelEvent;
}
}


#region MouseWheel Zoom

const float scaleFactor = 0.05f; // 5% scaling, Adjust this to get faster/slower scaling
const float WHEEL_DELTA = 120.0f; // One mouse wheel notch

void OnPlotCubeMouseWheelEvent(object sender, ILMouseEventArgs mea)
{
if (mea.Clicks == 0) // Only when no buttons pressed at the same time
{
var plotCube = sender as ILPlotCube;
if (plotCube != null)
{
// + or - a scaleFactor change per wheel mouse notch
float zoomFactor = 1 - ((float)mea.Delta) / WHEEL_DELTA * scaleFactor;
ILLimits ilLimits = plotCube.Limits;
ApplyScaleFactor(zoomFactor, ilLimits);
ilPanel.Refresh();
}
}
mea.Cancel = true; // Stop mouse wheel event default behaviour
}

private void ApplyScaleFactor(float zoomFactor, ILLimits ilLimits)
{
// delta here is nothing to do with wheel mouse delta
float delta = ilLimits.WidthF * zoomFactor / 2f;
ilLimits.XMin = ilLimits.CenterF.X - delta;
ilLimits.XMax = ilLimits.CenterF.X + delta;
delta = ilLimits.HeightF * zoomFactor / 2f;
ilLimits.YMin = ilLimits.CenterF.Y - delta;
ilLimits.YMax = ilLimits.CenterF.Y + delta;
}

private void ApplyScaleFactorHasWhitePatches(float zoomFactor, ILLimits ilLimits)
{
ilLimits.Update(ilLimits.CenterF, zoomFactor);
}

#endregion MouseWheel Zoom

我们获取 PlotCube 鼠标滚轮事件并自行处理。为了停止默认行为,我们设置了鼠标事件“取消”标志。如果您使用 ILLimits“更新”方法来获取缩放比例,您将获得当前行为,请参阅“ApplyScaleFactorHasWhitePatches()”方法。我认为这是由于缩放比例也缩放了 Z 轴的限制。我们的解决方案只是缩放 X 轴和 Y 轴的限制。也许,作为 ILNumerics 源代码中的修复,他们可以检查是否设置了 2D 标志,如果设置了则不缩放 Z 轴限制。

关于c# - 基于鼠标滚轮的 2D 图像缩放中出现的白色补丁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29796486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com