gdi

JPEG 2000 support in C#.NET

*爱你&永不变心* 提交于 2019-11-27 04:31:07
It seems that .NET can't open JP2 (Jpeg 2000) files using the GDI library. I've searched on google but can't find any libraries or example code to do this. Anybody got any ideas? I don't really want to pay for a library to do it unless I have to.. Seems like we can do it using FreeImage (which is free) FIBITMAP dib = FreeImage.LoadEx("test.jp2"); //save the image out to disk FreeImage.Save(FREE_IMAGE_FORMAT.FIF_JPEG, dib, "test.jpg", FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYNORMAL); //or even turn it into a normal Bitmap for later use Bitmap bitmap = FreeImage.GetBitmap(dib); Rowland Shaw I was

How do I use large bitmaps in .NET?

扶醉桌前 提交于 2019-11-27 04:25:52
问题 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

SetPixel is too slow. Is there a faster way to draw to bitmap?

此生再无相见时 提交于 2019-11-27 04:17:21
I have a small paint program that I am working on. I am using SetPixel on a bitmap to do that drawing of lines. When the brush size gets large, like 25 pixels across there is a noticeable performance drop. I am wondering if there is a faster way to draw to a bitmap. Here is a bit of the background of the project: I am using bitmaps so that I can utilise layers, like in Photoshop or The GIMP. Lines are being drawn manually because this will eventually use graphics tablet pressure to alter the size of the line over its length. The lines should eventually be anti-aliaced/smoothed along the edges.

Use native HBitmap in C# while preserving alpha channel/transparency

淺唱寂寞╮ 提交于 2019-11-27 03:39:19
问题 Let's say I get a HBITMAP object/handle from a native Windows function. I can convert it to a managed bitmap using Bitmap.FromHbitmap(nativeHBitmap) , but if the native image has transparency information (alpha channel), it is lost by this conversion. There are a few questions on Stack Overflow regarding this issue. Using information from the first answer of this question (How to draw ARGB bitmap using GDI+?), I wrote a piece of code that I've tried and it works. It basically gets the native

Find out number of icons in an icon resource using Win32 API

本小妞迷上赌 提交于 2019-11-27 02:57:10
问题 I have an *.ico file that contains multiple icons in different sizes linked to my executable as a resource. I use this resource to set my application's icon with RegisterClassEx() , i.e.: wcx.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); In addition to that, I'd also like to convert all the single icons in this resource to ARGB pixel arrays. This should be possible by using GetDIBits() on the bitmap returned by GetIconInfo() . However, there is one problem: I need to find out the

How can I find what font was actually used for my CreateFont call?

倾然丶 夕夏残阳落幕 提交于 2019-11-27 02:41:00
问题 In Windows, the CreateFontIndirect() call can silently substitute compatible fonts if the requested font is not requested. The GetObject() call does not reflect this substitution; it returns the same LOGFONT passed in. How can I find what font was actually created? Alternately, how can I force Windows to only return the exact font requested? 回答1: In Windows, the CreateFontIndirect() call can silently substitute compatible fonts if the requested font is not requested. The GetObject() call does

How would I load a PNG image using Win32/GDI (no GDI+ if possible)? [closed]

主宰稳场 提交于 2019-11-27 01:35:27
Is it possible to load a PNG from a file into an HBITMAP using Win32 GDI functions? If not, what would be the lightest solution without using external libraries (like libpng)? You can use the Windows Imaging Component to load PNG files (on Windows XP SP2 and later). See MSDN Magazine for an introduction on how to use the API and my blog post for a code sample that loads a PNG from an IStream and converts it to an HBITMAP. There is no need to use Windows Imaging Component, GDI+ or PNG library. You can use Icon functionality. Add new icon (ICO_PNG) to VC project resources with custom Width and

Graphics.DrawString vs TextRenderer.DrawText?Which can Deliver Better Quality

﹥>﹥吖頭↗ 提交于 2019-11-27 01:04:12
TextRenderer is based on GDI and Graphics.DrawString is based on GDI+.Which of these functions can deliver better quality text while drawing text on an image. Just my 2 cents: I always use Graphics.DrawString, except when I need to do custom painting for my (Windows Forms) controls. For example in a listbox that has OwnerDraw set, if I attach a DrawItem event handler that fully paints items, including item text. Or in a custom control I have to paint myself. In an application that uses Visual Styles on an OS that supports it and has it enabled, text drawn with Graphics.DrawString looks "off"

[译]Windows 中的 2D 绘图 API

走远了吗. 提交于 2019-11-26 21:43:05
原文链接 : 2D Drawing APIs in Windows 背景知识 : Windows 图形编程 在 Windows 7 操作系统中,微软花费了很大的力气构建了一套新的 2D 绘图 API。我们称之为 Direct2D ,隶属于 DirectX 家族。这个 API 的开发填补了 Windows 图形平台的一些缺陷。其中非常重要的一点就是普通的 2D 程序渲染不再缺乏硬件加速。而在 Windows Vista 中,我们知道 GDI 是无法进行硬件加速的。微软寄望于开发的这个 API 具备很多现代特性。比如支持抗锯齿和 Alpha Blend 的 2D 渲染,和其它现代图形 API 交互,服务器端渲染,诸如此类。 为了方便理解微软为何开发 Direct2D ,我们先来回顾一下当初开发 Windows 时的历史。最初的渲染系统叫做 GDI (图形设备接口),今天仍然存在。它最初为 16 位 Windows 写就,随后升级到 32 位 Windows (Windows 95 和 Windows NT)。因为 GDI 是为很久以前那些计算能力低下的计算机而开发的,所以它并没有诸如抗锯齿之类的特性,大多数 API 亦不支持 Alpha 通道。 在 Windows 95 期间,DirectX 发布了第一版。DirectDraw 是其中最早的组件之一。当初的本意是在硬件加速启用的情况下

efficiently acquiring a screenshot of the windows desktop

烈酒焚心 提交于 2019-11-26 21:42:04
问题 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