gdi+

C# paint program flickering

99封情书 提交于 2020-01-12 08:28:57
问题 I'm trying to make a simple paint program in C#, but it keeps flickering when I'm drawing, like I need some kind of double buffering, but I don't know how to do it. I am drawing on a Panel and I'm using a Bitmap to store the graphics. Here's my code: public partial class Form1 : Form { private Bitmap drawing; private bool leftDown = false; private int prevX; private int prevY; private int currentX; private int currentY; public Form1() { InitializeComponent(); drawing = new Bitmap(panel1.Width

c# DrawString - measure bounding boxes for each character

蹲街弑〆低调 提交于 2020-01-12 07:40:11
问题 Before I pass a string to Graphics.DrawString(), I'd like to know exactly where each character will be - not just it's offset and width, but its exact bound box with ascent/descent figured in so that I can do collision detection at the character level rather than using the entire line-height that Graphics.MeasureString() is giving me. I can't seem to find any examples for this that accurately return the bounding box for each character. How can this be done in c#/GDI+ ? Ideally, I'd like to

Rendering graphics in C#

喜欢而已 提交于 2020-01-10 14:38:22
问题 Is there another way to render graphics in C# beyond GDI+ and XNA? (For the development of a tile map editor.) 回答1: SDL.NET is the solution I've come to love. If you need 3D on top of it, you can use Tao.OpenGL to render inside it. It's fast, industry standard (SDL, that is), and cross-platform. 回答2: Yes, I have written a Windows Forms control that wraps DirectX 9.0 and provides direct pixel level manipulation of the video surface. I actually wrote another post on Stack Overflow asking if

gdi+ Graphics::DrawImage really slow~~

主宰稳场 提交于 2020-01-10 07:17:19
问题 I am using a GDI+ Graphic to draw a 4000*3000 image to screen, but it is really slow. It takes about 300ms. I wish it just occupy less than 10ms. Bitmap *bitmap = Bitmap::FromFile("XXXX",...); //-------------------------------------------- // this part takes about 300ms, terrible! int width = bitmap->GetWidth(); int height = bitmap->GetHeight(); DrawImage(bitmap,0,0,width,height); //------------------------------------------ I cannot use CachedBitmap, because I want to edit the bitmap later.

Creating GDI+ bitmaps in memory and then saving as png

情到浓时终转凉″ 提交于 2020-01-10 04:19:26
问题 I am new to C++ and been having trouble with writing a function using the GDI+ library to create a new bitmap in memory ( so not opening/reading an existing bitmap); then drawing on the bitmap; before saving it to png. In particular, I am having problems with the bitmap creation and saving code. I am constrained to using codeblocks and I can't use visual studios, even if I wanted to. The code is as follows: #include "drawImage.h" #include <windows.h> #include <objidl.h> #include <gdiplus.h>

Winforms: How to speed up Invalidate()?

时光总嘲笑我的痴心妄想 提交于 2020-01-09 19:08:54
问题 I'm developing a retained mode drawing application in GDI+. The application can draw simple shapes to a canvas and perform basic editing. The math that does this is optimized to the last byte and is not an issue. I'm drawing on a panel that is using the built-in Controlstyles.DoubleBuffer. Now, my problem arises if I run my app maximized on a big monitor (HD in my case). If I try to draw a line from one corner of the (big) canvas to the diagonally opposite other, it will start to lag and the

Extending the list of supported image formats in GDI+

笑着哭i 提交于 2020-01-09 11:10:31
问题 To quote the documentation for the System.Drawing.Imaging namespace The Encoder class enables users to extend GDI+ to support any image format. Yet I can find no documentation, examples or anything else that explains how I'd go about implementing my own custom file format -- most searches return lots of information on passing EncoderParameters, but nothing on implementing our own Encoders? Ideally, I'd love to be able to implement this in C#, but I am prepared to dust off my ATL if needs be :

Drawing on the Desktop using C#

烈酒焚心 提交于 2020-01-06 20:20:14
问题 I'm trying to draw a rectangle right on the desktop using C#. After finding some solutions and I got these: using System; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; namespace Test { public partial class Form1 : Form { [DllImport("User32.dll")] public static extern IntPtr GetDC(IntPtr hwnd); [DllImport("User32.dll")] static extern int ReleaseDC(IntPtr hwnd, IntPtr dc); public Form1() { InitializeComponent(); } private void Form1_Load(object sender,

How to construct a GDI+ Bitmap object from a Device-Dependent HBITMAP

泪湿孤枕 提交于 2020-01-06 05:24:06
问题 I want to use GDI+ method Image::Save() to save a DDB to a file in the following scenario: HBITMAP hBitmap = CreateCompatibleBitmap(hDC, 200, 200) ; ... //hBitmap is a DDB so I need to pass an HPALETTE Gdiplus::Bitmap(hBitmap, ???HPALETTE??? ).Save(L"file.png", ...) ; The problem is that Bitmap constructor asks for an HPALETTE when the bitmap is not a device-independent bitmap. Where do I get the necessary HPALETTE from? FOLLOWUP: One of the answers suggests passing NULL as the HPALETTE

GDI+ library causes “error C2760: syntax error: unexpected token 'identifier', expected 'type specifier'” in VS2017 when compiled for XP

冷暖自知 提交于 2020-01-06 05:09:08
问题 I'm trying to include the following definitions for GDI+ into my Win32 C++ project that is compiled under Visual Studio 2017: #include <objidl.h> #include <gdiplus.h> #pragma comment (lib,"Gdiplus.lib") I need to compile this project to support Windows XP. So in the project properies I selected: Platform Toolset as Visual Studio 2017 - Windows XP (v141_xp) : But when I compile it the GDI+ library gives me this: 1>c:\program files (x86)\microsoft sdks\windows\v7.1a\include\objbase.h(239):