.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Bitmap drawing

Posted By:      Posted Date: September 02, 2010    Points: 0   Category :.NET Framework
I am trying to draw objects (line, etc) on a Bitmap. However, I have run into some problems: the origin of the bitmap coordinate system is at the top-left corner of the bitmap. How can I have it set to the bottom-left corner? Also, I need to draw some real world objects on this bitmap: how can I transform or map the real world coordinates on the bitmap coordinate space? Any help is really appreciated as I am totally lost on this one.

View Complete Post

More Related Resource Links

Displaying a System.Drawing.Bitmap in a WPF Image control

How would I convert a System.Drawing.Btimap into a comparable WPF image control so I can display in on my WPF window? Thanks

Mouse Drawing in Bitmap and repositioning bitmap

Dear Friends,                  I have made an application similar to this: http://www.bobpowell.net/simpledraw.aspx. But I have made few changes like I have used only the mouse draw option where the drawing is zoomed to specific level with Matrix transformation and I have snapped the mouse to the current mouse coordinates. The programe is working fine. Problem arises when I try to place the same bitmap in X and Y axis many time. After placing bitmap in both the axis once again repositioned the mouse like whenever the mouse is clicked on repositioned bitmaps it draws into the original bitmap and displays the image in all positioned bitmaps. I have solved the mouse back tracking issues.                   The major problem I face here is that when the mouse crosses one bitmap to another bitmap it ticks a continuous line. That is whenever mouse crosses 0th pixel to the last pixel of previous positioned bitmap or from last pixel to 0th pixel of next positoned bitmap. Whereas I need smooth mouse drawing programme with bitmaps positioned many time so that the drawn image should look continuous. I couldnt give code because it is huge.               &n

Unable to cast COM oject of type 'System.__ComObject' to class type of 'System.Drawing.Bitmap' .

 private void DirectXViewer_DragDrop(object sender, DragEventArgs e)


   mousePressedFlag = false;



    Object obj = e.Data.GetData(typeof(Bitmap));





      Bitmap image = (Bitmap)((Bitmap)obj).Clone();

      RenderImage = image;



     catch(Exception ex)








private void DirectXViewer_MouseMove(object sender, MouseEventArgs e)


   if (mousePressedFlag)


    if(cacheBitmap != null)

     this.DoDragDrop(new Bitmap(cacheBitmap), DragDropEffects.Copy);




Hi All,

I try to d

NotSupportedException System.Drawing.Bitmap


I have a VB.Net program which is running on CF MobilePC 2003.  In the form creation logic (generated by VS), the creation of a bitmap on the form (in a PictureBox) gets the following exception:

Me.pbStop.Image = CType(resources.GetObject("pbStop.Image"), System.Drawing.Image)


System.NotSupportedException was unhandled



    at System.Resources.ResourceReader.LoadObjectV2()

System.Drawing.Bitmap.SetResolution is completely broken on Windows 7


Bitmap.SetResolution does nothing on Windows 7. It works fine on XP and Vista. This code demonstrates the problem:


            foreach (string file in Directory.GetFiles(@"C:\Temp\input"))


                string newFile = "";

                using (var bitmap = (Bitmap)Image.FromFile(file))


                    bitmap.SetResolution(200, 200);

                    newFile = Path.Combine(@"C:\Temp\output", Path.GetFileName(file));

                    bitmap.Save(newFile, ImageFormat.Png);


                using (Image image = Image.FromFile(newFile))





Hi there,


 I am doing one task on asp.net graphics. i would like to a form that let the user choose the color code from the color picker.

inside my backend code, i can get the color code and convert to the system.drawing.color.



Dim col As System.Drawing.Color = System.Drawing.ColorTranslator.FromHtml("#9932CC")

 Dim Brush As New SolidBrush(col)


but i have some problem in make this col object to alpha color. as i know the .net code that make the system color to become alpha is wrote as like tat :

gr.DrawString(strWatermarkText, wmFont, New SolidBrush(Color.FromArgb(8, 0, 0, 0)), x, y)


May someone share me how to make the color input from form to become alpha color? thanx in advanced. hope to hear from you all soon 


System.Drawing.Image.Fromfile is not working


I am trying to get the height and width of the image dynamically.  The reason is I am loading multiple images using code, where the image name is from the database. 

Here is my code:

in the ascx page, I have an asp image

<asp:image id="imgInfo" runat="server" /> 


In the code behind

string ImagePath = "~/products/img/" + dataviewImgInfo[0]["imgName"].ToString();

System.Drawing Image imgProd = System.Drawing.Image.FromFile(ImagePath);

if(imgProd.Height > 200)

imgInfo.Height = 100;




imgInfo.Height = 200



WHen I run this page I am getting the folloiwng error

Bitmap FromFile space "file not found"


I am using aspose.slides to create PPTx's. Some of the process involves loading jpg's from another server and including them in the presentation. This works fine in my development environment. When I upload the site to its server, the jpg loading fails.

I am trying to access jpg's on the other server by:

   oFS = New FileStream(sFile, FileMode.Open, FileAccess.Read)

This causes an access violation error when run from the server.

I also boiled the code down to reading the file directly:

   oImg = System.Drawing.Bitmap.FromFile(sFilePath)

This causes a file not found error.

We have narrowed the problem down to the fact that the File Path has a space in it. How does one solve this problem (while still keeping the space, there is a lot of legacy data)? I have tried replacing the space with %20 or +. I have tried using Server.UrlEncode. The error message always comes back with the encoding in place (like no decoding

Bitmap to Image Control - ImageUrl


 This is my first attempt at using the drawing features of asp.net.  I just want to start simple, and create a single color bar based on a value for a single graph.  I wrote this so far, but I can't figure out how to take the bitmap I just created, and apply it to the Image Control. Do I have to save the file first, and then reload it.

Plus, my box keeps coming out pure black, I trying to fill the box with a color. 

This is part of a web custom control, in which I dynamically created an Image Control. I want to apply the bitmap I made to the image control. 


Dim imgGoogle As Image
imgGoogle = New Image
imgGoogle.ImageAlign = ImageAlign.AbsMiddle
imgGoogle.ImageUrl = cs.GetWebResourceUrl(rsType, "ice5software.BotCatcher.Google.gif")
Private Sub DrawBarGraph_Google(ByVal BarValue As Integer)

	Dim objBitmap As System.Drawing.Bitmap
	Dim objGraphics As S

Windows With C++: Drawing with Direct2D


In this article, the author shows you how to draw with Direct2D by introducing Direct2D's color structure and its various types of brushes.

Kenny Kerr

MSDN Magazine September 2009

Office 2003: Host an Interactive Visio Drawing Surface in .NET Custom Clients


Microsoft Office Visio 2003 introduces a new drawing component that allows you to embed an interactive drawing surface into your application's user interface. You can drive the Visio drawing component from events in your host application or with data from a Web Service and an ADO.NET data adapter. The Visio drawing component supports the rich Visio application programming model, giving you control over how graphics are used and displayed on the drawing surface. This article explains how to embed the Visio drawing component into a C#-based Windows Forms client app that retrieves data from the Fabrikam 2.0 Web Service.

Mai-lan Tomsen Bukovec and Blair Shaw

MSDN Magazine December 2003

encoding/decoding a string to/from bitmap


I have two methods:

Encode - takes a string, converts it to array of bytes, uses bytes to specify colors, creates a color and sets a pixel based on bytes

Decode - takes a pixel, retrieves color (R,G,B) bytes and converts them to characters, that produces a string which was previously encoded

I'm using two for loops (img height/width) to specify position and access pixels

The issue is that once display (Control Panel\Appearance and Personalization\Display) changes to anything other then "Smaller - 100%",
bytes have different values during decoding, thus different string is produced (corrupted).

If the setting is set to "Smaller - 100%" the results are normal.

What can I do to avoid that problem?

Thanks in advance

Writing Bitmap to Response.OutputStream - Generic Error Occured in GDI+



This is what I'm trying to do when I get the error on the server (it works on my local machine):

System.Drawing.Image image = System.Drawing.Image.FromFile(filepath);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image); 

Response.ContentType = "image/bmp";
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);

I don't think it can be a permissions problem because this works on the server:

System.Drawing.Image image = System.Drawing.Image.FromFile(filepath);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image);

Response.ContentType = "image/jpeg";
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

So how do I get this to work for a bitmap?


EventType clr20r3, P1 devenv.exe, P2 9.0.30729.1, P3 488f2b50, P4 system.drawing, P5, P6 488

Hi,I am facing a strange issue in Visual Studio 2008 Standard SP1, when using WPF Designer (even without using the Designer tab, only XAML tab). Visual Studio crashes very often, without any apparent reason, and in various ways, for example: exits instantly, the IDE displays corrupted UI, when begining compiling it stops responding.There are two new Event Log entries after this: EventType clr20r3, P1 devenv.exe, P2 9.0.30729.1, P3 488f2b50, P4 system.drawing, P5, P6 4889dec2, P7 33d, P8 18, P9 system.outofmemoryexception, P10 NIL. .NET Runtime version 2.0.50727.3053 - Fatal Execution Engine Error (7A2E0F92) (0)Worth mentioning:- computer has Windows XP SP3 with the latest updates installed- it crashes on other computer types too- the project has quite a large number of UserControls - it appears that if opening a XAML file with the XML editor instead, it works ok- on other WPF projects it also works okDoes anyone have an ideea why is this happening and solutions? Thanks

how to create a Bitmap with size(20000,30000) in c#

hi how to create a BitMap with size (20000,30000) using C#

WPF - Drawing the connected lines shape

I want something to draw like in WPF   ___________________________                                        |                                        |                                        | __________________________ | | | ___________________________                                         |                                         |                                         | ___________________________          
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend