|
I have a Bitmap that has loaded in a map. When I click on the map (bitmap), I want to draw a filled circle at that point. I understand how to do it with a PictureBox or something that I can get a Graphics object for/from it, but I can't for the life of me figure out how to do the same with a bitmap.
Is there a way to do this? I'm sure there is, I just haven't figured it out yet. So, if any of you could help me out by pointing me in the correct direction, code fragments, or whatever, I'd really appreciate it.
Thanks a bunch!
Mike
|
|
|
|
|
Graphics g = Graphics.FromImage(bmp);
g.DrawLine(...);
g.Dispose();
"Well, I wouldn't say I've been missing it, Bob." - Peter Gibbons
|
|
|
|
|
Heath,
Thanks for responding.
I tried that and got the following error:
An unhandled exception of type 'System.Exception' occurred in system.drawing.dll
Additional information: A Graphics object cannot be created from an image that has an indexed pixel format.
Any ideas?
Thanks again,
Mike
|
|
|
|
|
Well, my first suggestion would be to read the docs (especially about Image and Bitmap ). My second suggestion, having said that, it to save the indexed image to a MemoryStream using a different <codepixelformat< code=""> then read it back in and get the <code>Graphics object from that. There are many other ways you can do this, too.
"Well, I wouldn't say I've been missing it, Bob." - Peter Gibbons
|
|
|
|
|
Hi Heath!
Thanks again for replying. To start off, as if you probably couldn't tell, this is my first foray into doing much of anything with graphics. Lots of middle/backend programming with next to nothing in the UI department for the last 8 years.
That being said, what docs are you talking about? I've read the documentation that Microsoft has written on the Image and Bitmap classes but they're rather thin when you don't know much about using graphics in general. Are there other places that have better documentation? If so, please point me to them!
Also, I will look into the MemoryStream option, but I have one question: you say to save the indexed image (BTW what is that? I just thought I was loading a BMP file! There's different types of BMPs?) using a different ...?? I get the last part (at least in theory) but what different thing am I to use?
Thanks again for the advice. It really does help.
|
|
|
|
|
Yeah, the Microsoft .NET documentation. This documentation is what I've used and don't know much about graphics either, but these is *very* basic drawing routines - not much documentation is needed.
The Bitmap</code class does not equate to a .bmp file. It adds a few methods and properties to the <code>Image class for bitmap images. All image formats (i.e., JPEG, GID, PNG, BMP, RGB, etc.) that I'm aware of are technically bitmaps - a map of bits essentially. Most formats basically have an (A)RGB value for each bit (the whole of which makes up the bitmap). Index images basically have a palette of colors that are indexed and the image contains a mapping of pixels <-> palette index. That's a very basic description of both of those things, but that covers the gist of it.
BTW, there are different kinds of .bmp files (remember, this is not exclusive to the Bitmap class). The difference is the way the bitmaps are encoded in the file. There's Windows and OS/2 encodings that I know of. This is a similar concept to video files, just like an AVI can have different encodings (MPEG4, DivX, etc.).
"Well, I wouldn't say I've been missing it, Bob." - Peter Gibbons
|
|
|
|
|
Thanks Heath. You've added to my knowledge base and that's great.
I did get things to work, but not in the place that I want it. Now that I know it works like you said, it's just a matter of figuring out how to do it in the OnMouseXxx functions.
Thanks for you help and input!
Mike
|
|
|
|
|
If a method doesn't give you a Graphics object, you can always get one for a particular control by using Control.CreateGraphics() . In this case, though, you must call Graphics.Dispose() when you're done with it. In event handlers like OnPaint() that give you one, it will clean it up for you so *never* call Graphics.Dipose() at that time.
"Well, I wouldn't say I've been missing it, Bob." - Peter Gibbons
|
|
|
|
|
Thanks Heath!!
I hadn't gotten far enough in the documentation to figure this out. One of those cases where you have to get something done and reading documentation (or anything else other than getting the thing done) is frowned upon.
I tried it and this works beautifully! Thanks again.
|
|
|
|
|
Okay. Here's what I've tried. I was successful on doing the simple and easy way that Heath suggested in just having a Graphics g = Graphics.FromImage(bmp) and drawing on the bitmap when in the On_Paint() method of the class I'm working on.
To simplify things for myself, I've changed the Bitmap to an Image and loaded it in from the BMP file and had everything work correctly.
Now for the thing I'm not sure how to do: When I'm in the OnMouseDown() (which is where I would like to call a function to draw a node on the map since I have a Point to do it at), I can't seem to get a Graphics object from my Image object to do the drawing with. What should I do? It obviously can be done since I do it in the On_Paint() function.
Any pointers would be appreciated.
Thanks a bunch,
Mike
|
|
|
|
|
How to add code to the verb action in the file type actions after setting them in installer
Also how to get the file info , with which the application is invoked
I found that it only launches the application but doesnt call the function i specified its name in the verb property in the installer
thanks,
Wella
|
|
|
|
|
Greetings,
I'm new to the C# experience as such and on top of that I use rather a poorman's development tool, without many of VS.NETs nice drag-and-drop features where it comes to layouts etc.
I'm in need of a bar containing a button with a dropdown, a textfield and another button with a dropdown, in that order. Because of the textfield I suppose I'd better not try solving this using a toolbar and its menus. However, being a n00b, that's the only way I'm able to do above from the top of my head (ie without drag-and-dropping most of it).
So my rather embarrassing question is wether someone could spent a sec and hand me a snipplet of above. Yes.. I know Thanks a bunch!
|
|
|
|
|
What happens with events if computer is slow.
Lets say a timer ticks with 50Hz and the event handler does heavy computations that on P4 2GHz are done perfectly but if the program is run on a Celeron 266 and the computations are done slowlier that the timer ticks. What is going to happen to the timer event? Will it wait for the calculation to stop or it will be ignored and what is worse the program is going to crash.
Well if we don't need 100% reliable data a calculation or two may be omitted but it is better that the programs works on the slower computer that not to work at all.
|
|
|
|
|
Zinj wrote:
Lets say a timer ticks with 50Hz and the event handler does heavy computations that on P4 2GHz are done perfectly but if the program is run on a Celeron 266 and the computations are done slowlier that the timer ticks.
Timer runs in its own thread. Thus the timer will fire its event at the same interval whether on a P4 or a P1.
Zinj wrote:
Will it wait for the calculation to stop or it will be ignored and what is worse the program is going to crash.
Why not test it yourself....? I unfortunately dont have 2 PC's to try it on. Perhaps place a lock on some objects, and maybe do each calculation in it own thread, so it can finish on its own time.
One question: why are doing the calculations from a timer event?
Who is this miscrosoft, and what devilish plans have they for us?
|
|
|
|
|
so I think to calculate some equations 30 times a second (motion, physical simulation, etc)
|
|
|
|
|
I guess a Celleron 400 aint gonna cut that (especially doing realtime simulation). From your other post, are doing some DirectX? I would try optimize the calculations.
Who is this miscrosoft, and what devilish plans have they for us?
|
|
|
|
|
Hey what's up coders...
Okay I am changing between two full screen forms. Each form has it's own 24bit 1024 X 768 fancy backround bitmap created in photoshop. When I change between screens there is a very small amount of flicker [and this isn't allowed] .
So what can I do to fix this? I am thinking maybe directx is the key for me but I thought I would write you all first and see.
I am open to any suggestions.
|
|
|
|
|
|
Hey Mark thanks man but me thinks... The flicker comes from the switching of the forms. The drawing comes afterwards... Unless there is another way to tell the form to draw the background..
thanks,
Lata
|
|
|
|
|
although it is a little bit stupid...how about use another graphic object to load that bmp file before display it.
|
|
|
|
|
who can help me reading the header of an avi-file from my C# application?
i want to get some informations like width, height rate/sec. etc.
do i have to use unmanaged code and call API functions?
i am a beginner so maybe someone could send me sample code
|
|
|
|
|
I tried to find or create a c# component to create a query by drag and drop tables and fields (something like Access Query design). Any idea, please help me.
regards.
|
|
|
|
|
There's one in VS.NET....other than that Im not sure.
Who is this miscrosoft, and what devilish plans have they for us?
|
|
|
|
|
www.devcity.com where working on one a while back! Don't know whats happened to it though!
|
|
|
|
|
I tried to integrate a flex program with C# the way I used to integrate with VB6 but nothing is happening.
I want to know the correct way to do it. Is there any DLLs I have to attach?
Pls help me.
Thanks.
kind rgds,
Anjana Aluthwala
|
|
|
|