Create New Account
help
DrawImage anomaly with small bitmaps .NET Framework I've been using a small bitmap buffer to my code on a terminal services connection. When I do that, for some reason the DrawImage call adds what looks like some anti-aliasing artifacts around any sharp edges, seemingly regardless Does anyone have any idea how I can prevent this? Right now I'm using BitBlt directly, but that seems like an ugly hack. (The same code is at http: / / rafb using System; using System.Windows.Forms; using System.Drawing; using System.Runtime.InteropServices; namespace ExampleApp { class Example : Form { [DllImport("gdi32.dll")] static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos for (int i = 0; i < 100; i++) offscreen.SetPixel(i, i, Color.Black); e.Graphics.DrawImage(offscreen, 0, 0); e.Graphics.DrawLine(new Pen(Color.Black), 50, 0, Width + 50, Width VB.NET. Subscribe to the RSS feeds provided and never miss a new article. keywords: DrawImage, anomaly, with, small, bitmaps description: I've been using a small bitmap buffer to do
problem converting an indexed8 tiff image to a 24bit image. When I convert it with DrawImage or for example DrawImageUnscaledAndClipped it drops the RGB with one. For example (255, 255, 255 g.PixelOffsetMode = Drawing2D.PixelOffsetMode.Half ' g.PageUnit = GraphicsUnit.Pixel ' g.SmoothingMode = Drawing2D.SmoothingMode.None g.DrawImage(image, 0, 0, image.Width, image.Height) image24.Save(filename & "2.png") Catch image24 = Nothing be anything wrong with the tiff files or is there a bug in the Bitmap class? Regards, Linus I suggest that you create a 24bpp image with the same width and source and set the resolution to match the original source tiff's resolution. Use the DrawImage method with the Point argument(i.e., DrawImage(image, new Point(0, 0)). You should get an unscaled bitblt that unpacks the 8bpp source to a 24bpp image. The tiff specification is complex. Perhaps same palette when using another 3rd party library or program? Hi, I can't get Drawimage(image, new point(0, 0)) to work. All I get is a black image. I just copies one point). But I think the problem isn't the scaling or using DrawImage, the problem occurs when I LOAD the image. Regards, Linus On Mar 31, 5:37
Graphics.FromImage (1) System.EventArgs (1) EventArgs (1) Hi Michael, Try this: - -- -- -- -- -- -- -- -- -- -- -- --CODE STARTS- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - Public Class Form1 Dim img As Bitmap Dim WithEvents pd As Printing.PrintDocument '-1- API CALL TO BITBLT SetLastError: = True, CharSet: = Runtime.InteropServices.CharSet.Unicode, ExactSpelling: = True, CallingConvention: = Runtime.InteropServices.CallingConvention.StdCall)> _ Graphics.FromImage(MyImage) Dim dc1 As IntPtr = g1.GetHdc() Dim dc2 As IntPtr = g2.GetHdc() 'BitBlt is an API Call as defined above at -1- BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, (Me.ClientRectangle.Height), dc1, 0, 0, 13369376) g1.ReleaseHdc dc1) g2.ReleaseHdc(dc2) Return MyImage End Function Private Shared Function BitBlt(ByVal hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As x As Integer = e.MarginBounds.X Dim y As Integer = e.MarginBounds.Y e.Graphics.DrawImage(img, x, y) e.HasMorePages = False End Sub End Class - -- -- -- -- -- -- -- -- -- -- -- -- --CODE ENDS- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- The following article provides another approach: http: / / www.codeproject.com / useritems / MCLFormPrintControl.asp STARTS- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - Dim img As Bitmap Dim WithEvents pd As Printing.PrintDocument '-1- API CALL TO BITBLT 'Function to convert the form to an image Function CaptureForm1() As Bitmap Dim g1 As
The Mighty BitBlt .NET Framework / * BitBlt.cs C# code using P / Invoke I have good reasons to use P / Invoke to get access to the Win32 API function BitBlt(). But I have trouble understanding the workings of it. Below is a small, compilable and Bitmap I alter slightly and copy it to the screen, four times. Twice with Graphics.Drawimage(), twice with BitBlt() (so fast!). The first attempt in the left-top corner with DrawImage() poses no problem. The second attempt next to it with BitBlt() shows an Empty Black Square. Then I copy part of the screen to the in memory Bitmap. When I copy the in-memory Bitmap back to the screen with BitBlt(), only the part copied from the screen shows. The rest is black. This you see
Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace NetSchoolPlus { / / / Note: / / / This is the class that allow us to invoke Native API to capture Desktop Image / / / <summary> / / / This class shall keep the GDI32 APIs used in our program. / / / < / summary> public class PlatformInvokeGDI32 { / / SRCCOPY : Native Type = ENUM, thus set to original value, refer MSDN for more info region Class Variables public const int SRCCOPY = 13369376; #endregion #region Class Functions<br> [DllImport("gdi32.dll", EntryPoint = "DeleteDC")] public static extern IntPtr DeleteDC(IntPtr hDc); [DllImport gdi32.dll", EntryPoint = "DeleteObject")] public static extern IntPtr DeleteObject(IntPtr hDc); [DllImport("gdi32.dll", EntryPoint = "BitBlt")] public static extern bool BitBlt(IntPtr hdcDest, int xDest, int yDest, int wDest, int hDest, IntPtr hdcSource, int xSrc, int dll", EntryPoint = "SelectObject")] public static extern IntPtr SelectObject(IntPtr hdc, IntPtr bmp); #endregion } / / / <summary> / / / This class shall keep the User32 APIs used in our program. / / / < / summary> public class PlatformInvokeUSER32 { #region Class