Tag: system.drawing

如何在.NET 2.0中打开多帧TIFF图像格式图像?

Image.FromFile(@”path\filename.tif”) 要么 Image.FromStream(memoryStream) 即使源是多帧TIFF文件,两者都只生成一帧的图像对象。 如何加载保留这些帧的图像文件? 逐帧使用Image.SaveAdd方法保存tiff。 它们在其他查看器中工作,但.NET Image方法不会加载这些帧,只有第一个。 这是否意味着无法从我传入位图集合的方法返回多帧TIFF以用作帧?

System.Drawing.Crush来自System.Drawing.Color

我正在为我们公司开发WinForm Printing应用程序。 打印文档时,我需要获取文档上每个Control的System.Drawing.Color属性,并创建一个System.Drawing.Brush对象来绘制它。 有没有办法将System.Drawing.Color值转换为System.Drawing.Brush值? 注意:我已经尝试查看System.Windows.Media.SolidColorBrush()方法,但它似乎没有帮助。

C#在面板上绘图

我正在制定一个日程安排并用面板代表时间段,并且约会更多的是面板。 用户可以向上和向下滚动,以便他们可以看到的范围更早或更晚。 当约会在可见范围的末尾运行时,我希望有一个曲折,表明约会超出了可见范围。 我已经确定了发生这种情况的情况,并且我调用了私有函数drawZigZag(Panel p, int direction); 画它。 日期水平展开,方向-1表示左侧的锯齿形,1表示右侧的锯齿形。 到目前为止,我还没有达到之字形,我只是尝试使用CreateGraphics()和FillPolygon() 。 到目前为止我有: private void drawZigZag(Panel p, int direction) // 1 = right, -1 = left { Graphics g = p.CreateGraphics(); g.FillRectangle(new SolidBrush(Color.FromArgb(0, Color.Black)), p.DisplayRectangle); Point[] points = new Point[4]; points[0] = new Point(0, 0); points[1] = new Point(0, p.Height); points[2] = new Point(p.Width, p.Height); points[3] […]

比较两个Color对象

这个C#,VS2010和.NET 4.0。 我正在尝试比较两个System.Drawing.Color对象。 mStartColor.ToArgb()的值是16777215 。 Color.Transparent.ToArgb()的值是16777215 。 mStartColor Color.Transparent值为True 。 如何为Color对象实现等式? 编辑 感谢大家。 我得到了答案,虽然这对我没有多大意义(请参阅我对蒂姆和戴夫的答案的评论)。 我将蒂姆的post标记为答案,他是第一个回复的人,但戴夫的回答同样有用。

如何在保存图像时找到Generic GDI +错误的原因?

拥有一个在加载和存储图像时可以使用多年的代码,我发现我有一个图像打破了这段代码: const string i1Path = @”c:\my\i1.jpg”; const string i2Path = @”c:\my\i2.jpg”; var i = Image.FromFile(i1Path); i.Save(i2Path, ImageFormat.Jpeg); 例外是: 发生了System.Runtime.InteropServices.ExternalException GDI +中发生了一般错误。 在System.Drawing.Image.Save(String filename,ImageCodecInfo encoder,EncoderParameters encoderParams) 在System.Drawing.Image.Save(String filename,ImageFormat格式) 在 … 据我所知,图像并没有什么特别之处。 它的大小约为250像素,可以在Windows Image Viewer或Paint.NET中打开: (由于上面的图片,在上传到Stack Overflow之后不再产生错误,我把原始图像放在这里 ) 我发现在调用Save方法时 ,目标图像文件是用零字节创建的。 我真的对导致错误的原因一无所知。 我的问题: 你能想到任何阻碍.NET保存图像的特殊事物吗? 有没有办法(除了惊慌失措)缩小这些错误?

File.Delete在之前调用Image.FromFile时失败,尽管复制了加载的图像并破坏了原始图像

更新 我使用下面的解决方案(从流加载图像),但得到新的问题。 img对象是绝对正确的Image类实例,所有字段都填充了正确的值。 但是打电话 img.Save(“path/to/new/image.bmp”); 在它上面导致GDI +的新exception(System.Runtime.InteropServices.ExternalException,在GDI +接口中) – 我收到错误消息但是很好,我不知道如何翻译它。 原始问题 我有C#.NET Framework 2.0的问题 基本上我试图实现: Image img = Image.FromFile(“Path/To/Image.bmp”); File.Delete(“Path/To/Image.bmp”); // Exception, the file is in use! 删除原始文件时,将图像副本保留在内存中非常重要。 我虽然有点奇怪的是.NET仍然锁定硬盘上的文件,尽管它不再需要任何操作(整个图像现在在内存中,不是吗?) 所以我试过这个解决方案: Image img = new Image(Image.FromFile(“Path/To/Image.bmp”)); // Make a copy // this should immiedietaly destroy original loaded image File.Delete(“Path/To/Image.bmp”); // Still exception: the file is in […]

在服务器桌面会话上捕获屏幕

我开发了一个GUI测试框架,可以按计划对我们公司网站进行集成测试。 当某些内容失败时,它会截取桌面的屏幕截图等。 这在专用Windows Server 2008上的登录用户上无人值守。 问题是在我已断开远程桌面会话的桌面上截取屏幕截图。 我得到以下exception: System.ComponentModel.Win32Exception (0x80004005): The handle is invalid at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation) at System.Drawing.Graphics.CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize) at IntegrationTester.TestCaseRunner.TakeScreenshot(String name) in C:\VS2010\IntegrationTester\IntegrationTester\Config\TestCaseRunner.cs:line 144 at IntegrationTester.TestCaseRunner.StartTest() in C:\VS2010\IntegrationTester\IntegrationTester\Config\TestCaseRunner.cs:line 96 TakeScreenshot()方法如下所示: public static void TakeScreenshot(string name) { var bounds = Screen.GetBounds(Point.Empty); […]

选择System.Drawing.Icon的大小?

我有一个图标,有几个不同的尺寸(16px,32px,64px)。 我在它上面调用ToBitmap() ,但它总是返回32px图像。 如何检索64px?

如何在图像上画线?

我想在bmp图像上绘制一条线,该线在C#中使用drawline方法传递给方法 public void DrawLineInt(Bitmap bmp) { Pen blackPen = new Pen(Color.Black, 3); int x1 = 100; int y1 = 100; int x2 = 500; int y2 = 100; // Draw line to screen. e.Graphics.DrawLine(blackPen, x1, y1, x2, y2); } 这给了一个错误。所以我想知道如何在这里包含paint事件(PaintEventArgs e) 并且还想知道在调用drawmethod时如何传递参数? 例 DrawLineInt(Bitmap bmp); 这给出了以下错误“当前上下文中不存在名称’e’”

System.Drawing Out of Memory Exception

我的应用程序图形引擎抛出这些exception。 它们都被空的捕获块消耗掉。 在早期,我发现了一个没有被困的人(我回忆起与笔加宽有关)。 我用try和一个空的catch块包围它。 似乎这些例外对所产生的图纸没有影响。 我已经对此做了一些阅读而没有真正理解或深入了解它。 所以我的问题: 如果可以安全食用,为什么会抛出这些? 和 忽视它们是否安全? 我担心每个人都有一些隐藏的效果。 我有内存泄漏,例如我从未找到过。