BitBlt函数在C#中如何引用?

ABC1964 2008-07-07 10:59:36
我想将打印内容写入JPG文件中,但不知BitBlt函数在C#中如何引用?或者有别的办法也行,拜托了。
...全文
310 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ABC1964 2008-07-08
  • 打赏
  • 举报
回复
// PrintEventArgs e
想用Graphics g1 = e.Graphics;代替您的Graphics g1 = this.CreateGraphics();
但结果e:\1.bmp是空白,为什么呢?在e.Graphics中画图像都可以,就是考不到Image中。
ABC1964 2008-07-08
  • 打赏
  • 举报
回复
谢谢,非常感谢,
确实是保存了this窗口的内容,但打印预览的内容无法保存。
非常想在“打印预览”按钮上,把打印的内容保存为BMP,有招吗?
lovefootball 2008-07-07
  • 打赏
  • 举报
回复
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code
);
lovefootball 2008-07-07
  • 打赏
  • 举报
回复

Graphics g1 = this.CreateGraphics();
Image MyImage = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height, g1);
Graphics g2 = Graphics.FromImage(MyImage);
IntPtr dc1 = g1.GetHdc();
IntPtr dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
MyImage.Save(@"e:\1.bmp", ImageFormat.Bmp);
ABC1964 2008-07-07
  • 打赏
  • 举报
回复
非常感谢您的回帖,软件也通过了编译,但生成的2.jpg是空的。
代码如下,请您再帮我看看。
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code
);

private void PrintToFile(string name, PrintPageEventArgs e)
{
Bitmap bm1 = new Bitmap("c:\\1.jpg");
Graphics g1 = Graphics.FromImage(bm1); //这仅是测试,实为 g1 = e.Graphics; 两者生成的2.jpg都是空的。
IntPtr dc1 = g1.GetHdc();

Bitmap bm2 = new Bitmap(810, 1150);
Graphics g2 = Graphics.FromImage(bm2);
IntPtr dc2 = g2.GetHdc();

bool ll = false;
ll=BitBlt(dc2, 0, 0, 810, 1150, dc1, 0, 0, 13369376); // ll=true;
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);

bm2.Save("c:\\2.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

bm1.Dispose();
bm2.Dispose();

}

110,042

社区成员

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

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

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