jhasty Posted February 23, 2003 Posted February 23, 2003 I am trying to figure out how to draw simple lines on a bitmap in memory, then display the bitmap on a control (probably a PictureBox). I also need to be able to save the memory bitmap to a .bmp file. I'm using VB .NET. I have been completely unable to figure out how to set up the various objects to do this. BitMap? Image? Graphics? I am so lost. If someone could show me a simple example, I think I could figure it out from there. How about an example that would create a bitmap in memory, draw a line on the bitmap, and then show the bitmap on a PictureBox control? Any help would be greatly appreciated. Quote
*Gurus* divil Posted February 23, 2003 *Gurus* Posted February 23, 2003 This example shows creating an in-memory bitmap, drawing a circle on it, then assigning the bitmap to a picturebox. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim b As New Bitmap(100, 100) Dim g As Graphics = Graphics.FromImage(b) g.DrawEllipse(Pens.Red, New RectangleF(0, 0, b.Width, b.Height)) PictureBox1.Image = b 'b.Save("c:\temp.bmp") g.Dispose() End Sub If you uncomment the commented line, the bitmap will be saved to the hard disk. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
chuawenching Posted July 26, 2003 Posted July 26, 2003 Hi Hi.. just wonder i draw a circle in the picturebox1 1) and i want to store the circle in memory (only circle) when i store into bmp... i want to see the circle with transparent backrground... i need to do some image processing? The way on top works, just not sure does it store with the background color or image together? 2) Just wondering, if 1 drag 1 circle... i want to calculate the x,y of the circle... maybe 1 circle with 10 nodes of (x,y) and store in array how can i do that? Any help? Regards, Chua Wen Ching :p Quote
Diablicolic Posted July 28, 2003 Posted July 28, 2003 Divil when I use that code, the Graphics thing in the declaring gets highlighted in red. I don't understand the error but when I check it out it says that "Type Expected"...what does that mean? Quote "Reality is fake, Dreams are for real"
AndreRyan Posted July 29, 2003 Posted July 29, 2003 Does you're project import System.Drawing, if it does change it to System.Drawing.Graphics.FromImage(b). 1) I think you're asking how to make the background transparent? Put b.MakeTransparent(Color.White) before saving, you may also need to save it as a picture format that allows transparency like GIF Quote .Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
*Experts* Volte Posted July 29, 2003 *Experts* Posted July 29, 2003 Divil when I use that code, the Graphics thing in the declaring gets highlighted in red. I don't understand the error but when I check it out it says that "Type Expected"...what does that mean? Are you using VB.NET?? :confused: Quote
chuawenching Posted July 29, 2003 Posted July 29, 2003 Is Andre refering to me or the original poster? Regards, Chua Wen Ching :p Quote
chuawenching Posted July 29, 2003 Posted July 29, 2003 Help This example shows creating an in-memory bitmap, drawing a circle on it, then assigning the bitmap to a picturebox. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim b As New Bitmap(100, 100) Dim g As Graphics = Graphics.FromImage(b) g.DrawEllipse(Pens.Red, New RectangleF(0, 0, b.Width, b.Height)) PictureBox1.Image = b 'b.Save("c:\temp.bmp") g.Dispose() End Sub If you uncomment the commented line, the bitmap will be saved to the hard disk. Any idea how that code works in c#? the b.width - i can't find the width! and i cannot place b into FromImage(b) // invalid arguments C:\WenChing\Store Image in Memory\Form1.cs(94): Argument '1': cannot convert from 'System.Drawing.Bitmap[*,*]' to 'System.Drawing.Image' Any help? Regards, Chua Wen Ching :p Quote
AndreRyan Posted July 29, 2003 Posted July 29, 2003 Bitmap b = New Bitmap(100, 100); Graphics g = Graphics.FromImage(b); g.DrawEllipse(Pens.Red, New RectangleF(0, 0, b.Width, b.Height)); g.Dispose(); //b.MakeTransparent(Color.White); PictureBox1.Image = b; //b.Save("c:\temp.bmp"); I'm not skilled in C#, I have no liking for C syntax but I think this right Quote .Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
chuawenching Posted July 29, 2003 Posted July 29, 2003 Nope it is not right! when i click on b. (intellisense show) and i can't find width! Regards, Chua Wen Ching :p Quote
AndreRyan Posted July 29, 2003 Posted July 29, 2003 (edited) I just checked it in C# and this worked: Bitmap b = new Bitmap(100, 100); Graphics g = Graphics.FromImage(b); g.DrawEllipse(Pens.Red, 0, 0, b.Width, b.Height); g.Dispose(); //b.MakeTransparent(Color.White); this.pictureBox1.Image= b; //b.Save("c:\temp.bmp"); The thing I really hate in C syntax is that it's case sensitive, that's what always gets me, capitals when they should be lowercase. Whats the point of having a variable named Var1 and var1 or New must be new. It's just confusing Edited July 29, 2003 by AndreRyan Quote .Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.