gdi

crop image to 4:3 aspect ratio c#

僤鯓⒐⒋嵵緔 提交于 2019-12-02 11:48:21
问题 I'm having a tough time wrapping my head around how to figure out the math for cropping any image that has a higher aspect ratio than 4:3 to 4:3. For example, I may have some images that are 16:9 that I I want resized and then cropped to 4:3. The resize bit I already have working, but it's maintaining the same aspect ratio. I know I need to use Graphics.DrawImage() But I'm not entirely sure what the parameters should be nor how I derive those parameters. Here's what I do know: var dimension =

Draw line rotated at an angle over bitmap

孤人 提交于 2019-12-02 11:47:27
问题 I am drawing a line from centre of png image to top in below code: private string ProcessImage(string fileIn) { var sourceImage = System.Drawing.Image.FromFile(fileIn); var fileName = Path.GetFileName(fileIn); var finalPath = Server.MapPath(@"~/Output/" + fileName); int x = sourceImage.Width / 2; int y = sourceImage.Height / 2; using (var g = Graphics.FromImage(sourceImage)) { g.DrawLine(new Pen(Color.Black, (float)5), new Point(x, 0), new Point(x, y)); } sourceImage.Save(finalPath); return @

How are GDI objects selected and destroyed by SelectObject function

安稳与你 提交于 2019-12-02 09:38:08
问题 As I am new to Visual C++, this might be a very basic question related to selecting a GDI object. The following code snippet draws a light grey circle with no border. cPen pen(PS_NULL, 0, (RGB(0,0,0))); dc.SelectObject(& pen); CBrush brush (RGB (192,192,192)); dc.SelectObject (&brush); dc.Ellipse(0,0, 100,100); All I understand from the code snippet is first an Object of Pen is created, and its a NULL Pen which would make the border disappear, the brush then creates a Circle of grey color,

Sharing GDI handles between processes in Windows CE 6.0

白昼怎懂夜的黑 提交于 2019-12-02 07:48:21
I know that GDI handles are unique and process specific in 'Big Windows' but do they work the same way in Windows CE 6.0? For example: I've got a font management service that several other services and applications will be using. This service has a list of valid fonts and configurations for printing and displaying; CreateFontIndirect() has been called on each of them. When one of these client applications requests a particular font (and configuration), can I return it the appropriate HFONT? If not, is there a safe/valid way to duplicate the handle, ala DuplicateHandle for Kernel handles. The

Get the colour of the screen's current colour filter

有些话、适合烂在心里 提交于 2019-12-02 07:02:00
问题 The following code SETS the colour filter of the screen to a specific colour. How can I instead GET the colour of the screen? [DllImport("GDI32.dll")] private unsafe static extern bool SetDeviceGammaRamp(IntPtr hdc, void* ramp); private static IntPtr hdc; public unsafe bool SetLCDbrightness(Color c) { short red = c.R; short green = c.G; short blue = c.B; Graphics gg = Graphics.FromHwnd(IntPtr.Zero); hdc = gg.GetHdc(); short* gArray = stackalloc short[3 * 256]; short* idx = gArray; short

Intersecting GraphicsPath objects

情到浓时终转凉″ 提交于 2019-12-02 06:29:08
问题 How can I intersect two (.NET) GraphicsPath objects? 回答1: Are you trying to get the area enclosed by two different paths? That is a Region , not a path: var rgn1 = new Region(path1); var intersection = rgn1.Intersect(path2); rgn1.Dispose(); If that is not what you mean, you will have to provide more information. 来源: https://stackoverflow.com/questions/503376/intersecting-graphicspath-objects

Get all windows which overlap my window

爷,独闯天下 提交于 2019-12-02 05:41:56
I want to find all windows which entirely or partly overlap my window (are on top of it). As a special case, if I have two window handles (hWnd1 and hWnd2), I want to find if hWnd2 partly or completely overlaps hWnd1. The windows in question are desktop windows (not children/siblings in the same process). Iterate the windows that might overlap yours by repeatedly calling GetWindow(), using GW_HWNDPREV. Use GetWindowRect() to check if such a window actually overlap yours. There's no shortcut for two known windows, just check if GetWindow() returns hWnd2 while iterating. 来源: https:/

crop image to 4:3 aspect ratio c#

元气小坏坏 提交于 2019-12-02 05:28:18
I'm having a tough time wrapping my head around how to figure out the math for cropping any image that has a higher aspect ratio than 4:3 to 4:3. For example, I may have some images that are 16:9 that I I want resized and then cropped to 4:3. The resize bit I already have working, but it's maintaining the same aspect ratio. I know I need to use Graphics.DrawImage() But I'm not entirely sure what the parameters should be nor how I derive those parameters. Here's what I do know: var dimension = (double)bigSide/smallSide if(dimension > 1.4) { Graphics.DrawImage(resImage, new Rectangle(?, ?, ?, ?)

Qt: QPainter + GDI in the same widget?

不想你离开。 提交于 2019-12-02 04:30:37
I'm trying to use the method described here to use a QPainter and GDI calls on the same widget. Unfortunately this tutorial seem to have been written on an earlier version of Qt and now it does not work. I set the WA_PaintOnScreen flag and reimplement paintEngine() to return NULL. Then on the paintEvent() I create a QPainter, use it and then use some GDI calls to paint a bitmap. The GDI calls work fine but the QPainter does nothing. I get the following error on the console: QPainter::begin: Paint device returned engine == 0, type: 1 Is this simply not supported anymore? how can I do it? I've

What is the best way to resize a Bitmap in Windows?

假装没事ソ 提交于 2019-12-02 04:16:15
So, I am working on a text editor. I use double buffering to paint on to the screen. So basically I have an offscreen bitmap, which I paint on, and then copy it to the screen. Now, when the window for the text editor resizes, I need to resize the offscreen bitmap as well. So what would be a good way to resize the bitmap? I was thinking to maybe delete the old object and create a new bitmap using CreateCompatibleBitmap , but I'm wondering if it's the correct way to do it. Language : C++ using Win32 API Using CreateCompatibleBitmap will work, and then you'll want to call BitBlt on it to copy the