C#分割图片问题?急

pbooter 2005-12-13 11:27:51
请问在winform中,如何实现将调入pictureBox中的图片分割成几块,然后分别存储成图片的功能?分不够再加
...全文
393 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
大可山人 2006-01-17
  • 打赏
  • 举报
回复
效率较低的一种,是使用
g.DrawImage(yourImage, destRect, srcRect, GraphicsUnit.Pixel);
较高的方式则使用读取内存指针,使用不安全代码。据你的需要,前者完全可以满足你的要求了。
pupo 2005-12-19
  • 打赏
  • 举报
回复
因为用的抓屏,所以PictureBox的SizeMode属性需设置成AutoSize
而且图片所在窗体必须在最上层
pupo 2005-12-19
  • 打赏
  • 举报
回复
[System.Runtime.InteropServices.DllImportAttribute ( "gdi32.dll" ) ]
private static extern bool BitBlt (
IntPtr hdcDest , // 目标 DC的句柄
int nXDest ,
int nYDest ,
int nWidth ,
int nHeight ,
IntPtr hdcSrc , // 源DC的句柄
int nXSrc ,
int nYSrc ,
System.Int32 dwRop // 光栅的处理数值
) ;

private void button1_Click(object sender, System.EventArgs e)
{
try
{
string file = null;
Bitmap bmp = null;
IntPtr dc1 = IntPtr.Zero;
IntPtr dc2 = IntPtr.Zero;
int row = 2, col = 2;

int left = 0, top =0 , width = 0, height = 0;
for(int i=0; i<row; i++)
{
left = 0;
top = i * ((int)(this.pictureBox1.Height / row));
for(int j=0; j<col; j++)
{
file = @"c:\"+ i.ToString() + j.ToString() +".bmp";
if (j == col-1)
width = this.pictureBox1.Width - ((int)(this.pictureBox1.Width / col)) * j;
else
width = (int)(this.pictureBox1.Width / col);

if (i == row-1)
height = this.pictureBox1.Height - ((int)(this.pictureBox1.Height / row)) * i;
else
height = (int)(this.pictureBox1.Height / row);

Graphics g1 = this.pictureBox1.CreateGraphics();
bmp = new Bitmap(width, height, g1);
Graphics g2 = Graphics.FromImage(bmp);
dc1 = g1.GetHdc();
dc2 = g2.GetHdc();


BitBlt (dc2 , 0 , 0 , width , height , dc1 , left , top , 13369376 ) ;
g1.ReleaseHdc(dc1) ;
g2.ReleaseHdc(dc2) ;
g1.Dispose();
g2.Dispose();
bmp.Save(file, System.Drawing.Imaging.ImageFormat.Bmp);

left += width;

}
}

}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}

}
Aallonlin 2005-12-19
  • 打赏
  • 举报
回复
Bitmap bb = (Bitmap)Image.FromFile("...");
Bitmap sepbitmap1= bb.Clone(new System.Drawing.Rectangle(0,0,20,20),System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
zhangjinzhicn 2005-12-19
  • 打赏
  • 举报
回复
调用缩略图水印组件wsImage3.5
pbooter 2005-12-19
  • 打赏
  • 举报
回复
急啊!
ChengKing 2005-12-13
  • 打赏
  • 举报
回复
???

PictureBox是不能分块的,可以用多个PictureBox显示一个分割后的图片.

请看:
http://blog.csdn.net/ChengKing/archive/2005/11/06/524162.aspx
下面第六个.

111,119

社区成员

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

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

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