- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个 Winforms 应用程序,用户使用它来获取基于区域的屏幕截图。我想要一个小的预览 Pane ,但我不知道该怎么做。到目前为止,我尝试在鼠标移动时重新创建一个位图,但它太慢了,无法使用。所以我想如果我使用预定义的图像(整个屏幕的屏幕截图)并根据鼠标位置将其移动到图片框内,以便您可以放大查看屏幕(以选择您想要拍摄的精确像素屏幕截图更容易)。我不确定如何实现它,我对绘图也很陌生,所以我会向您展示我现在拥有的东西。
private void falseDesktop_MouseMove(object sender, MouseEventArgs e)
{
zoomBox.Image = showZoomBox(e.Location);
zoomBox.Invalidate();
}
private Image showZoomBox(Point curLocation)
{
int x = 0;
int y = 0;
if (curLocation.X - 12 <= 0)
{
x = curLocation.X - 12;
}
else
{
x = curLocation.X;
}
if (curLocation.Y - 11 <= 0)
{
y = curLocation.Y - 11;
}
else
{
y = curLocation.Y;
}
Point start = new Point(curLocation.X - 12, curLocation.Y - 11);
Size size = new Size(24, 22);
Rectangle rect = new Rectangle(start, size);
Image selection = cropImage(falseDesktop.Image, rect);
return selection;
}
private static Image cropImage(Image img, Rectangle cropArea)
{
if (cropArea.Width != 0 && cropArea.Height != 0)
{
Bitmap bmpImage = new Bitmap(img);
Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);
bmpImage.Dispose();
return (Image)(bmpCrop);
}
return null;
}
编辑:
这是一个像要求的模型:
这个图像的黑色部分是一个面板,当然文本是一个标签,你看到图像的区域(堆栈溢出)将是图片框(称为 zoomBox)zoomBox 顶部的线将是指南,两条线相交的地方就是鼠标位置。希望这是一个更好的帮助,可以帮助您理解我的问题。
可能有助于解释我的问题的另一件事是表单实际上用“虚假桌面”填满了整个屏幕。它是一个图片框,当按下“printscreen”时,它会覆盖整个屏幕并显示桌面屏幕截图。所以我希望这个小“预览 Pane ”基本上是鼠标所在位置的放大。
最佳答案
这有点慢,但值得一试:
它是单个文件中的 WInForms 应用程序,显示“实时”缩放的工作原理。它不会绘制十字线等,这取决于您。
关键部分:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Imaging;
static class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
public class Form1 : Form {
private Bitmap _myImage = new Bitmap(@"C:\Users\Public\Pictures\Sample Pictures\LightHouse.jpg");
private int _scale = 10; // keep this < 15
private PictureBox pboxMain;
private PictureBox pboxZoom;
private System.ComponentModel.IContainer components;
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
pboxMain.Image = _myImage;
}
private void pboxMain_MouseMove(object sender, MouseEventArgs e) {
try {
Rectangle rc = new Rectangle(
new Point(e.X - _scale, e.Y - _scale),
new Size(_scale * 2, _scale * 2));
pboxZoom.Image = _myImage.Clone(rc, PixelFormat.DontCare);
}
catch (OutOfMemoryException ex) {/* ignore... */}
}
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent() {
this.pboxMain = new PictureBox();
this.pboxZoom = new PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pboxMain)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pboxZoom)).BeginInit();
this.SuspendLayout();
this.pboxMain.Dock = DockStyle.Fill;
this.pboxMain.Location = new System.Drawing.Point(0, 0);
this.pboxMain.Name = "pboxMain";
this.pboxMain.Size = new System.Drawing.Size(767, 435);
this.pboxMain.TabIndex = 0;
this.pboxMain.TabStop = false;
this.pboxMain.MouseMove += new MouseEventHandler(this.pboxMain_MouseMove);
this.pboxZoom.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))),
((int)(((byte)(255)))), ((int)(((byte)(192)))));
this.pboxZoom.BorderStyle = BorderStyle.FixedSingle;
this.pboxZoom.Location = new System.Drawing.Point(12, 12);
this.pboxZoom.Name = "pboxZoom";
this.pboxZoom.Size = new System.Drawing.Size(106, 83);
this.pboxZoom.SizeMode = PictureBoxSizeMode.StretchImage;
this.pboxZoom.TabIndex = 1;
this.pboxZoom.TabStop = false;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(767, 435);
this.Controls.Add(this.pboxZoom);
this.Controls.Add(this.pboxMain);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.pboxMain)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pboxZoom)).EndInit();
this.ResumeLayout(false);
}
}
关于c# - 如何截屏 "preview"窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4325654/
我有 ADT 版本 23.0.4 并安装了 Android 5.0 的 SDK 平台。 我读到 Android 5.0 Lolipop 的 API 级别为 21。但是在 Eclipse 的“新建应用程
视频,电子表格和文档支持在云端硬盘中预览其内容。我正在开发一个Google云端硬盘应用程序,我希望它支持预览其内容,因此Google云端硬盘中是否有任何api可以设置预览缩略图或将其嵌入其中?例如,在
似乎预览停止在Xcode 12上运行!尝试预览SwiftUI文件模板并出现以下错误。任何想法如何解决这一问题?试图清理构建文件夹,删除派生数据并重新启动Xcode无济于事! 在Catalina 10.
我有一个需要预览网络摄像头视频的 Directshow 应用程序,当用户单击“录制”时,它需要开始将视频捕获到文件中。 为此,我创建了一个 Capture Graph,PREVIEW 引脚连接到 RE
我构建了一个人脸检测应用程序,我从 onPreviewFrame 获取帧,进行人脸检测,然后在 surfaceView 上方的 Canvas 上绘制一个圆圈。问题是当 Camera.StartPrev
要遵循哪些准则才能在 CKAN 数据预览工具上很好地预览数据?我正在 CKAN 工作,一直在上传数据或将其链接到外部网站。有些可以很好地预览,有些则不能。我一直在网上研究机器可读性,但找不到任何与 C
我看到其他人在 Xcode 11 和 12 中使用 SwiftUI Previews 发布了问题,但在其他地方没有看到这个问题。 在 Xcode 11 中运行的旧项目在 Xcode 12 中加载,无论
从上一个 Android Studio 2.0 预览升级到 Preview 5 后,我在从 android.support.wearable 导入时遇到了问题> 包。 主应用和 Wear 应用的构建和
我正在使用 Visual Studio 2013 预览版,并且我正在尝试在我的应用程序中使用更少的文件。但是我在右 Pane 中收到编译错误。你可以看看它。有人可以帮我吗? 最佳答案 您必须使用“Un
我已经找到并阅读了这个 tutorial .确实很好!我故意使用“阅读”这个词。早知道就不来这里问了。 现在:我试图将我读过的内容插入到我的应用程序中。我需要带有静态图像和相机预览控件的不同叠加层。我
我正在分别在Jenkins-X的“预览”和“jx-staging”中使用“jx预览”和“jx升级”命令部署服务。 我想删除与使用jx命令部署的特定微服务关联的资源(如部署,服务,pv和pvc等)。 因
我正在 Visual Studio 11 Developer Preview 中编写应用程序,在应用程序与 reader 一起运行一段时间后出现此错误。InputStreamOptions = Inp
今天我对我的 AOSP 存储库执行了一个repo sync,然后我收到了一些错误。这些是我从终端收到的: From https://android.googlesource.com/platform/
我正在使用 IntelliJ IDEA 2021.2.3 和 JDK 17。我有 Java 17 中的代码片段 pom.xm 4.0.0 org.example funct
我正在使用 IntelliJ IDEA 2021.2.3 和 JDK 17。我有 Java 17 中的代码片段 pom.xm 4.0.0 org.example funct
我在网页上有一个dropzone.js实例,具有以下选项: autoProcessQueue:false uploadMultiple:true parallelUploads:20 maxFiles
有关PowerShell Copy-Item命令的快速问题。我想知道您是否具有目录结构,并且想要覆盖另一个目录结构,是否有一种方法可以在“预览”模式下运行Copy-Item命令。它会将覆盖的文件从目录
我正在尝试实现一个 REST 服务(或者甚至是单个 Servlet),它允许我快速“预览”传入文件(包含单个文件的多部分请求)。 这个想法是在数据库中解析并存储进入服务的潜在巨大文件的前几行。 我面临
如何创建这样的圆形/椭圆形或圆角相机预览(中间的圆应该是相机预览)? 伦敦图像代表带有按钮和 View 的其余 UI,因此它必须是可见的,这就是为什么我不能使用像添加 android:backgrou
我有一个 WPF 文本框,并执行以下操作 输入文本“12345” 在 3 和 4 之间移动光标(使用箭头或鼠标点击) 输入 0(因此文本现在为“123045”) 哪个事件/事件参数可以告诉我在位置 4
我是一名优秀的程序员,十分优秀!