Hello all,
I'm doing an analog gauge.
I was asked to draw gauge nail over the image.
I feel clueless.
Can any one help me out.
Thanks in advance.
Sunil Varma
1. Drawing to Bitmap using C++ MFC dll
Hello,
I have a C# WinForms application and C++ MFC dll. The MFC library exports
methods for drawing to HDC. Is it possible to store HDC of a
System.Drawing.Bitmap in C++ MFC dll and then call dll's methods to draw to
this Bitmap without passing HDC with every method call?
I have already used this dll in MFC application earlier and HDC obtained
with GetSafeHDC() method worked fine.
It seems like there is no error in .NET too, but the result is empty bitmap.
------------------------------------------------------------------------------------------
I have a PictureBox named canvasPictureBox on the main form and the form has
these member variables:
Bitmap canvasBitmap;
Graphics canvasG;
IntPtr canvasHDC;
The bitmap canvasBitmap is created in Form_Load event and so are canvasG and
canvasHDC variables.
...
canvasBitmap = new Bitmap(canvasPictureBox.Width, canvasPictureBox.Height);
canvasG = Graphics.FromImage(canvasBitmap);
canvasG.Clear(SystemColors.Window);
canvasHDC = canvasG.GetHdc();
...
Then I pass canvasHDC as parameter to C++ MFC dll method declared as:
[DllImport(@"shpdb.dll", CharSet=CharSet.Ansi)]
public static extern UInt32 SHPDB_SetDrawParams(Int32 nCID, IntPtr hDC,
float zoom, float x, float y, Int32 clipLeft, Int32 clipTop, Int32 clipRight,
Int32 clipBottom);
...
resUINT = SHPDB.SHPDB_SetDrawParams(nCID, canvasHDC, 1, 0, 0, 0, 0,
canvasPictureBox.Width, canvasPictureBox.Height);
...
This method stores HDC handle in library for later usage. As my application
runs, it calls other dll methods which performs GDI drawing - they use HDC
previously stored in dll with method SHPDB_SetDrawParams. I do not call any
canvasG (GDI+) methods for drawing.
The off-screen bitmap is drawn in PictureBox Paint event:
private void canvasPictureBox_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImageUnscaled(canvasBitmap, 0, 0);
}
It seems ok, but the result is empty bitmap.
Can you help me with solving this task? What am I doing wrong?
2. Copy pixel data from System.Drawing.Bitmap - CSharp/C#
3. Transparency problem drawing bitmap
I am creating a custom user control and I am having problems with setting
the transparent color of the bitmap. Here is my code...
protected override void OnPaint( PaintEventArgs e )
{
System.Drawing.Imaging.ImageAttributes imageAttributes = new
System.Drawing.Imaging.ImageAttributes();
imageAttributes.SetColorKey(Color.FromArgb(231, 231, 231),
Color.FromArgb(231, 231, 231), ColorAdjustType.Bitmap);
Point ulCorner1 = new Point(0, 0);
Point urCorner1 = new Point(GetBitmapSize().Width, 0);
Point llCorner1 = new Point(0, GetBitmapSize().Height);
Point[] destPara1 = {ulCorner1, urCorner1, llCorner1};
Rectangle srcRect = new Rectangle( 0, 0, GetBitmapSize().Width,
GetBitmapSize().Height);
e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
e.Graphics.DrawImage(m_SelectedImage, destPara1, srcRect,
GraphicsUnit.Pixel, imageAttributes);
}
I want the specified RGB color (231, 231, 231) to be transparent, but it
isn't. What am I doing wrong? I thought imageAttributes.SetColorKey() was
supposed to do this.
-dh
4. System.Drawing.Bitmap alpha - CSharp/C#
Hi, i'm programmatically writing some text on the picture box. Every thing goes fine. Now for some reason I want to first write that text onto a bitmap and the set it as a source (picture property) of the picturebox. As soon as I use this bitmap approach the text quality is badly effected, specially the smaller text, big font are a little bit ok. What can be the reason? Thanks, Abubakar.
6. How to convert System.Drawing.BitMap to Byte[]? - CSharp/C#