gdi

Create 1bpp mask from image

时间秒杀一切 提交于 2019-11-28 02:18:41
问题 How do you create a 1 bit per pixel mask from an image using GDI in C#? The image I am trying to create the mask from is held in a System.Drawing.Graphics object. I have seen examples that use Get/SetPixel in a loop, which are too slow. The method that interests me is one that uses only BitBlits, like this. I just can't get it to work in C#, any help is much appreciated. 回答1: Try this: using System.Drawing; using System.Drawing.Imaging; using System.Runtime.InteropServices; ... public static

GDI Acceleration In Windows 7 / Drawing To Memory Bitmap

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 01:51:53
问题 My GDI program runs fine on Windows XP but on Windows Vista and 7 it looks pretty terrible due to the lack of GDI hardware acceleration. I recall reading an article a few years back saying that Windows 7 added hardware acceleration to some GDI functions, including BitBlt() function. Supposedly, if you if you draw to a memory bitmap and then use BitBlt() to copy the image to your main window it runs about the same speed as XP. Is that true? If it is true, how do you do it? I'm terrible at

Template matching from a screenshot of a window

烈酒焚心 提交于 2019-11-28 01:43:08
问题 What I've done I have a small template image which is meant to be used to find coordinates of matching subimages within a larger screenshot image. The screenshot itself is captured into a memory DC with the help of BitBlt , then converted into a cv::Mat via GetDIBits , like so: HDC windowDc = GetWindowDC(hwndTarget); HDC memDc = CreateCompatibleDC(windowDc); // ... HBITMAP hbmp = CreateCompatibleBitmap(windowDc, width, height); SelectObject(memDc, hbmp); BITMAPINFOHEADER bi = { sizeof

efficiently acquiring a screenshot of the windows desktop

半腔热情 提交于 2019-11-28 00:28:52
Is there a more efficient way of getting a copy of the windows desktop ( using GDI or any other library ) than the code below HDC dcDesktop; HDC dcMem; HBITMAP hbmpMem; HBITMAP hOriginal; BITMAP bmpDesktopCopy; dcDesktop = GetDC( GetDesktopWindow() ); dcMem = CreateCompatibleDC( dcDesktop ); hbmpMem = CreateCompatibleBitmap( dcMem, m_lWidth, m_lHeight ); BitBlt( dcMem, 0, 0, m_lWidth, m_lHeight, dcDesktop, 0, 0, SRCCOPY ); // Copy the hbmpMem to the desktop copy GetObject(hbmpMem, sizeof(BITMAP), (LPSTR)&bmpDesktopCopy); http://www.codeproject.com/KB/dialog/screencap.aspx This page has a

Heisenbug: WinApi program crashes on some computers

℡╲_俬逩灬. 提交于 2019-11-28 00:11:29
问题 Please help! I'm really at my wits' end. My program is a little personal notes manager (google for "cintanotes"). On some computers (and of course I own none of them) it crashes with an unhandled exception just after start. Nothing special about these computers could be said, except that they tend to have AMD CPUs. Environment: Windows XP, Visual C++ 2005/2008, raw WinApi. Here is what is certain about this "Heisenbug": 1) The crash happens only in the Release version. 2) The crash goes away

A generic error occurred in GDI+

混江龙づ霸主 提交于 2019-11-28 00:09:15
问题 [ExternalException (0x80004005): A generic error occurred in GDI+.] IpitchitImageHandler.Data.ImageRepository.AddNewTempImage(Stream image, String extension, Guid PageId, Guid ImageId, ImageTransformCollection toDoTransforms) +1967 IpitchitImageHandler.Data.ImageRepository.AddNewTempImage(Stream image, String extension, Guid PageId, Guid ImageId) +85 IpitchitWeb.Sell.Controls.UploadImagesSubstep.UploadImages(Object sender, EventArgs e) in F:\Documents and Settings\Vjeran\My Documents\Visual

How to debug GDI Object Leaks?

穿精又带淫゛_ 提交于 2019-11-27 23:17:59
I'm not quite sure how to go about doing this. It is a large app, and we are having GDI object "leaks" on most of our forms. Is there a tool to help out? Is there a tutorial on how to use such a tool? Should I just start deleting code from our forms until I narrow the offender down? (there is ALOT of code). It is pretty rare to exceed the 10,000 object limit for GDI objects only, the garbage collector will take care of them when you don't call their Dispose() method yourself. A much more likely failure mode is exceeding the object limit for windows. Which is very easy to do in Winforms,

c# radial gradient brush effect in GDI and winforms

。_饼干妹妹 提交于 2019-11-27 21:45:19
问题 I have created a c# windows application and written 75% of the code. The program allows the user to create a flow chart, and will shade the flow chart shapes according to their status. I wanted them to become 3d buttons such as from the website Webdesign.org Rather than create a PNG for each button, I wanted to create them in C# using brushes or other technique, such as: // Create solid brush. SolidBrush blueBrush = new SolidBrush(Color.Blue); // Create points that define polygon. PointF

How do I use large bitmaps in .NET?

这一生的挚爱 提交于 2019-11-27 20:15:27
I'm trying to write a light-weight image viewing application. However, there are system memory limitations with .NET. When trying to load large bitmaps ( 9000 x 9000 px or larger, 24-bit), I get a System.OutOfMemoryException. This is on a Windows 2000 PC with 2GB of RAM (of which 1.3GB is used up). It also takes a lot of time to attempt loading the files. The following code generates this error: Image image = new Bitmap(filename); using (Graphics gfx = this.CreateGraphics()) { gfx.DrawImage(image, new Point(0, 0)); } As does this code: Stream stream = (Stream)File.OpenRead(filename); Image

Rotate a point around another point

安稳与你 提交于 2019-11-27 20:10:18
I have a task to draw a specific graphic. As part of this task I need to rotate some dot's on 45 degrees. I've spent already 2 days trying to calculate a formula, but just couldn't get it right. I've been searching all over the place including this particular website, I'm getting very close, but I'm still not there. Here it is: I need to draw 4 different points I have a specific formula to calculate there position, which is out of scope of the question, but here is what I'm getting as a result of it: int radius = 576; int diameter = radius * 2; Point blueA = new Point(561, 273); Point greenB =