system.drawing

Capture screen on server desktop session

痞子三分冷 提交于 2019-11-27 04:15:02
I have developed a GUI test framework that does integrationtesting of our company website on a scheduled basis. When something fails, it'll take a screenshot of the desktop, among other things. This runs unattended on a logged in user on a dedicated Windows Server 2008. The problem is that taking a screenshot on a desktop that I have disconnected my remote desktop session from. I get the following exception: System.ComponentModel.Win32Exception (0x80004005): The handle is invalid at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY,

Manipulating images with .NET Core

霸气de小男生 提交于 2019-11-27 03:52:52
I have updated my project from .NET 4.5 to .NET Core (with ASP.NET Core). I had some very simple code in my previous version that used the bitmap object from System.Drawing to resize an image. As I understand System.Drawing cannot be used in .NET Core because it is not cross platform, but what can be used instead? I have googled this and cannot find anything. The only thing I can find is this post, which has no code on it what so ever. Disclaimer: This is my software. I'm working on a cross-platform 2D Graphics library that runs on .NET Core It's currently alpha but already supports a

OutOfMemoryException: Out of memory - System.Drawing.Graphics.FromImage

余生颓废 提交于 2019-11-27 03:21:50
问题 I get Out of Memory exception when using System.Drawing.Graphics.FromImage (using latest versions of .NET software on Windows 2012 server), ONLY on a very few specific image files . Most of the time the code works fine. Typical answers to above issue indicate that certain resources are not being released. Please consider the following before answering:- This specific image is 34KB in size, is a .JPG image. Server is idle and has over 32GB RAM. If I look at properties of this jpg file, using

Selecting the size of a System.Drawing.Icon?

心已入冬 提交于 2019-11-27 01:57:48
I have a icon which has a few different sizes (16px, 32px, 64px). I am calling ToBitmap() on it, but it is always returning the 32px image. How do I retrieve the 64px one? This is a fairly painful limitation in the ResourceManager class. Its GetObject() method doesn't provide a way to pass extra arguments that would allow selecting the returned icon by size. A workaround is to add the icon to the project instead. Use Project + Add Existing Item, select your .ico file. Select the added icon and change the Build Action property to "Embedded Resource". You can now retrieve the desired icon with

Dynamically resizing font to fit space while using Graphics.DrawString

最后都变了- 提交于 2019-11-27 01:37:37
问题 Does anyone have a tip whereas you could dynamically resize a font to fit a specific area? For example, I have an 800x110 rectangle and I want to fill it with the max size font that would support the entire string I'm trying to display. Bitmap bitmap = new Bitmap(800, 110); using (Graphics graphics = Graphics.FromImage(bitmap)) using (Font font1 = new Font("Arial", 120, FontStyle.Regular, GraphicsUnit.Pixel)) { Rectangle rect1 = new Rectangle(0, 0, 800, 110); StringFormat stringFormat = new

.NET: What does Graphics.DrawImageUnscaled do?

微笑、不失礼 提交于 2019-11-26 23:20:18
问题 It is not well known, that if you draw an image, e.g.: graphics.DrawImage(image, top, left); the image will be scaled. This is because DrawImage looks at the dpi setting of the image (e.g. 72dpi from photoshop), and scales the image to match the destination display (typically 96dpi). If you want to draw an image without any scaling, you must explicitly give DrawImage the size of the image: graphics.DrawImage(img, top, left, img.Width, img.Height); i knew this from years of programming in GDI+

how to draw a line on a image?

寵の児 提交于 2019-11-26 22:59:05
i want to draw a line on a bmp image which is pass into a method using drawline method in C# 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); } this give a error.So i want to know how to include paint event here (PaintEventArgs e ) and also want to know how to pass parameters when we calling drawmethod? example DrawLineInt(Bitmap bmp); this give the following error "The name 'e' does not exist in the current context " "Draw a line on a bmp

C# Drawing on Panels

家住魔仙堡 提交于 2019-11-26 18:34:16
问题 I'm drawing up a day schedule and representing timeslots with panels, and appointments are yet more panels on top. The user is able to scroll up and down so that the range they can see is shifted earlier or later. When an appointment runs off the end of the visible range, I want there to be a zig-zag indicating that the appointment extends beyond the visible bounds. I've identified the case where this occurs, and I call a private function drawZigZag(Panel p, int direction); to draw it. The

A Generic error occurred in GDI+ in Bitmap.Save method

百般思念 提交于 2019-11-26 17:29:39
I am working on to upload and save a thumbnail copy of that image in a thumbnail folder. I am using following link: http://weblogs.asp.net/markmcdonnell/archive/2008/03/09/resize-image-before-uploading-to-server.aspx but newBMP.Save(directory + "tn_" + filename); is causing exception "A generic error occurred in GDI+." I have tried to give permission on folder, also tried to use a new separate bmp object when saving. Edit: protected void ResizeAndSave(PropBannerImage objPropBannerImage) { // Create a bitmap of the content of the fileUpload control in memory Bitmap originalBMP = new Bitmap

Cannot find Bitmap Class in Class Library (.NET Standard)

六月ゝ 毕业季﹏ 提交于 2019-11-26 17:23:17
问题 I want to make a Class Library (.NET Standard) and I'm using System.Drawing, but I get the error: CS0246 C# The type or namespace name 'Bitmap' could not be found (are you missing a using directive or an assembly reference?) I'm using .NET Standard 2.0. 回答1: Update As of last month (May 2018), Microsoft have a production release (previously it was preview/RC) of System.Drawing.Common , a NuGet package which supersedes both versions of the CoreCompat.System.Drawing package. This should be used