c# picture控件中超大图片显示问题

SHYYUNXIA 2008-12-22 11:25:34
pictrue控件中如何显示一个宽度达367000的超大图像,全部显示是不能的.
现在想知道怎么样可以实现panel控件滚动条滚动到哪里,就只绘制相应部分的图片?

或者其他方式可以展示图片的方式也行,只要能把这个图片展示出来.
...全文
1265 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
lyez_192 2012-03-01
  • 打赏
  • 举报
回复
好贴,学习啦!
mlhy20060406 2010-04-17
  • 打赏
  • 举报
回复
好贴,要记录一下
xue12300 2009-12-16
  • 打赏
  • 举报
回复
或者有什么比较好的画图控件么?推荐一下,观注
SHYYUNXIA 2008-12-27
  • 打赏
  • 举报
回复
或者有什么比较好的画图控件么?推荐一下
tsorgy 2008-12-24
  • 打赏
  • 举报
回复
2L 的方法是可以的,如果想自己写个控件的话下面有代码,从Panel继承来,增加Image属性,运行后可以用鼠标拖动图片。。
另外,由于父类是Panel,所以可以容纳其他控件,比如Label,你可以把一个Label拖放到这个DragPictureBox里然后设置背景色为Transparent,从而使这个Label相对于图片框背景透明(由于PictureBox不是容器,所以你无法让一个Label相对于PictureBox 背景透明)

/*
* Copyright (c) 2008 黑色珊瑚::Tsorgy.Utils, Reserved.
*
* Filename: @(#)DragPictureBox.cs
* Create by: TsOrgY
* Email: tsorgy@gmail.com
* Date: 2008/12/24 0:27:04
*
* Classname: DragPictureBox
* Description: 可拖动图片的图片框
*
*/

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;

namespace Tsorgy.Utils {

/// <summary>
/// 可拖动图片的图片框.
/// </summary>
[DefaultProperty("Image")]
public class DragPictureBox : Panel {

// 当前图像显示坐标.
private int _x, _y;
// 临时偏移量.
private int t_x, t_y;

/// <summary>
/// 获取或设置显示在 <see cref="Tsorgy.Utils.DragPictureBox"/> 上的图片.
/// </summary>
[Category("Appearance")]
[Description("显示在 DragPictureBox 上的图片")]
[Localizable(true)]
[DefaultValue(null)]
public Image Image {
get { return _image; }
set {
_image = value;
this.Invalidate();
}
}
private Image _image;

/// <summary>
/// 初始化 <see cref="Tsorgy.Utils.DragPictureBox"/> 类的新实例.
/// </summary>
public DragPictureBox()
: base() {
_image = null;
// 设置双缓冲.
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
}

/// <summary>
/// 引发 <see cref="E:System.Windows.Forms.Control.Paint"></see> 事件.
/// </summary>
/// <param name="e">包含事件数据的 <see cref="T:System.Windows.Forms.PaintEventArgs"></see>.</param>
protected override void OnPaint(PaintEventArgs e) {
base.OnPaint(e);
if (_image != null) {
Graphics g = e.Graphics;
g.DrawImage(_image, _x, _y, _image.Width, _image.Height);
}
}

/// <summary>
/// 引发 <see cref="E:System.Windows.Forms.Control.MouseMove"></see> 事件.
/// </summary>
/// <param name="e">包含事件数据的 <see cref="T:System.Windows.Forms.MouseEventArgs"></see>.</param>
protected override void OnMouseMove(MouseEventArgs e) {
base.OnMouseMove(e);
if (_image != null && e.Button == MouseButtons.Left) {
_x = e.X - t_x;
_y = e.Y - t_y;
// 防止图片拖出边缘.
if (_x > 0)
_x = 0;
else if (_x < this.Width - _image.Width)
_x = this.Width - _image.Width;
if (_y > 0)
_y = 0;
else if (_y < this.Height - _image.Height)
_y = this.Height - _image.Height;
// 重绘.
this.Invalidate(false);
}
}

/// <summary>
/// 引发 <see cref="E:System.Windows.Forms.Control.MouseDown"></see> 事件.
/// </summary>
/// <param name="e">包含事件数据的 <see cref="T:System.Windows.Forms.MouseEventArgs"></see>.</param>
protected override void OnMouseDown(MouseEventArgs e) {
base.OnMouseDown(e);
if (_image != null) {
t_x = e.X - _x;
t_y = e.Y - _y;
}
}
}
}
pcw19910218 2008-12-23
  • 打赏
  • 举报
回复
ding
SHYYUNXIA 2008-12-23
  • 打赏
  • 举报
回复
to net5i

调用BitBlt API函数剪切图片,把图片分块,然后绘制到Panel上即可

可以说说具体怎么做么?
GTX280 2008-12-23
  • 打赏
  • 举报
回复
2楼方法可以试一试
EveryCase 2008-12-23
  • 打赏
  • 举报
回复
ding
poqlk 2008-12-23
  • 打赏
  • 举报
回复
先算出当前窗口位置 设置滚动条 然后哦铜鼓截图的方式把整个大图的那小部分截下来。。 放在你显示的位置
net5i 2008-12-22
  • 打赏
  • 举报
回复
调用BitBlt API函数剪切图片,把图片分块,然后绘制到Panel上即可
不过,这么大图片,我感觉楼主的内存都够呛
ICanUseThisID 2008-12-22
  • 打赏
  • 举报
回复

//pictureBox是放在panel上的
panel.AutoScroll=true;
pictureBox.Location=new Point(0,0);
pictureBox.SizeMode=PictureBoxSizeMode.AutoSize;

110,534

社区成员

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

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

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