[Winform]截取鼠标附近的图片

wangchao1982 2009-04-24 05:56:53
标题:[Winform]截取鼠标附近的图片
描述:在一个pictureBox上,获取以鼠标所在位置为中心的图片矩形块(假如正方形的边长为2x).然后现实在另一个图片框里
...全文
118 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzuomin 2009-04-24
  • 打赏
  • 举报
回复
呵呵,代码随便改,只要您喜欢
lishuhua19820919 2009-04-24
  • 打赏
  • 举报
回复
楼上的我觉得改成,鼠标单击事件就更好了,楼主可以参考楼上代码修改下。
wzuomin 2009-04-24
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Image source = null;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
source = new Bitmap(PictureBox1.Width, PictureBox1.Height);
OpenFileDialog ofd = new OpenFileDialog { Filter = "Image|*.jpg;*.bmp;*.png" };
if (ofd.ShowDialog() == DialogResult.OK)
{
using (Graphics g = Graphics.FromImage(source))
{
using (Image img = Image.FromFile(ofd.FileName))
{
g.DrawImage(img, new Rectangle(0, 0, source.Width, source.Height), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel);
}
}
PictureBox1.Image = source;
}
else
{
this.Close();
}

}

private void PictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (source != null)
{
if (e.X >= 10 && e.X <= PictureBox1.Width - 10)
{
if (e.Y >= 10 && e.Y <= PictureBox1.Height - 10)
{
using (Graphics g = PictureBox2.CreateGraphics())
{
g.DrawImage(source, new Rectangle(0, 0, PictureBox2.Width, PictureBox2.Height), new Rectangle(e.X - 10, e.Y - 10, 20, 20), GraphicsUnit.Pixel);
}
using (Graphics g = PictureBox1.CreateGraphics())
{
g.DrawImage(source, 0, 0);
g.DrawRectangle(Pens.White, new Rectangle(e.X - 10, e.Y - 10, 20, 20));
}
}
}
}

}
}
}
wzuomin 2009-04-24
  • 打赏
  • 举报
回复
Winform窗体放置PictureBox1、PictureBox2两个控件


Public Class Form1

Private source As Bitmap = Nothing

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
source = New Bitmap(PictureBox1.Width, PictureBox1.Height)
Dim ofd As New OpenFileDialog With {.Filter = "Image|*.jpg;*.bmp;*.png"}
If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
Using g As Graphics = Graphics.FromImage(source), img As Image = Image.FromFile(ofd.FileName)
g.DrawImage(img, New Rectangle(0, 0, source.Width, source.Height), New Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel)
End Using
PictureBox1.Image = source
Else
Me.Close()
End If
End Sub

Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If source IsNot Nothing Then
If e.X >= 10 AndAlso e.X <= PictureBox1.Width - 10 Then
If e.Y >= 10 AndAlso e.Y <= PictureBox1.Height - 10 Then
Using g As Graphics = PictureBox2.CreateGraphics
g.DrawImage(source, New Rectangle(0, 0, PictureBox2.Width, PictureBox2.Height), New Rectangle(e.X - 10, e.Y - 10, 20, 20), GraphicsUnit.Pixel)
End Using
Using g As Graphics = PictureBox1.CreateGraphics
g.DrawImage(source, 0, 0)
g.DrawRectangle(Pens.White, New Rectangle(e.X - 10, e.Y - 10, 20, 20))
End Using
End If
End If
End If
End Sub

End Class
格拉 2009-04-24
  • 打赏
  • 举报
回复
wangchao1982 2009-04-24
  • 打赏
  • 举报
回复
关键是我不知道从哪里下手
格拉 2009-04-24
  • 打赏
  • 举报
回复
应该不难吧
内容概要:本文档是一份全面的《Linux命令手册大全》,系统性地整理了日常运维与开发中常用的Linux命令,按实际应用场景分为22个类别,涵盖文件操作、文本处理、系统管理、网络配置、安全防火墙、容器虚拟化等核心领域。每个命令均提供简洁的作用说明和典型用法示例,并标注权限要求(如root或普通用户)、发行版差异及注意事项,部分内容还包含延伸工具和最佳实践建议。附录中提供了常见故障排查流程和高危命令警示,帮助用户高效、安全地使用Linux系统。; 适合人群:具备基本Linux使用经验的开发者、运维工程师和技术支持人员,尤其适合工作1-3年需提升实操能力的技术人员;也适合作为资深用户的速查参考手册。; 使用场景及目标:①快速查找并掌握各类Linux命令的标准用法;②解决实际工作中遇到的系统管理、性能调优、网络诊断等问题;③学习命令组合与管道技巧以提高自动化效率;④规避高危操作风险,规范生产环境操作行为。; 阅读建议:此资源以实用为导向,建议结合具体工作场景查阅,优先掌握高频命令及其组合用法,同时注意区分发行版差异和权限约束。初学者应配合实验环境动手练习,进阶用户可重点关注附录中的排查流程与性能观测技巧。

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧