Click here to Skip to main content
16,020,188 members
Please Sign up or sign in to vote.
3.04/5 (4 votes)
See more:
INTRODUCTION AND RELEVANT INFORMATION ABOUT THE QUESTION:

I have a bitmap that I need to scale.

Bitmap can be minimized and maximized, and is a background of a dialog box.

I have tried using GDI, but to no avail, picture gets blurred.

In order to get sharper image, I would like to try vector graphics.

I have posted here a few questions that will try to solve my problem using GDI, but while I am trying to fix my problem that way, I would like to try to solve it this way as well, because I fear that I will not make any progress using GDI.

I would work on Windows XP, using Visual Studio C++ 2008.

Ask for additional information, and I will provide them.

QUESTION:

Can anyone recommend an online tutorial for vector graphics in pure WIN32, using C or C++?

Code examples/books are welcome too.

MY EFFORTS:

I have found online converter from bitmap to vector.

I have tried to find code examples on MSDN, but have failed.

Same goes for browsing StackOverflow archive, and I have found nothing on CodeProject nor on CodeGuru.

I have found this book on Amazon:

Introduction to Graphics Programming for Windows 95: Vector Graphics Using C++,by Michael J. Young but I just do not know if it will help me.

Also, some say that metafiles can be used here too.

If so, can you please provide links to tutorials/books/code examples, that show how to use metafile to scale images?

I sincerely apologize for asking the question in such broad and general manner, but I am a beginner, and just do not know how to phrase it well, maybe that is also the reason why I have failed with Google search for this topic.

If there is a way to rephrase this question, leave a comment, and I will act accordingly.

I just need some material on this to start with, I hope I am not asking too much.

Thank you.

I will continue to search online, maybe my luck changes, and I find something that may help me.

Regards.
Posted
Comments
Sergey Alexandrovich Kryukov 23-Sep-13 18:22pm    
Pretty good question, come to think about. I voted 4.
—SA
AlwaysLearningNewStuff 23-Sep-13 18:56pm    
Thank you, Mr. Kryukov.

Regards.
RedDk 24-Sep-13 1:31am    
http://inkscape.org/download/?lang=en ... begin by knowing what an .svg becomes. Best way to know how it might be used. Plus fills in the gaps of misunderstanding when one goes to ask more questions.
AlwaysLearningNewStuff 24-Sep-13 10:53am    
Thank you for your suggestion, I highly appreciate it.

I will give it a try, and report my results.

Regards.

There is no way to scale a bitmap up without losing quality.

Bitmaps and Vector graphics are two separate concepts. Bitmaps are pictures compromised of pixels. Making a pixel bigger means that it changes the image.

Vector graphics however are different, they are not collections of pixels but lines, circles, and other graphics primitives that make up a picture. You then draw these graphics on a canvas which can be scaled without losing quality. Unfortunately you can't do this with pictures since they are pixel collections.

You can use GDI to draw vector graphics, and you can use it to draw bitmaps. Metafiles (which is what old clipart is in) are vector graphics format. Look up metafile formats or SVG formats if you want to learn how to draw vector graphics.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 23-Sep-13 17:31pm    
Of course (5ed), but it is not the main question. Also, I would add that there is no "conversion" from bitmap to vector, if you are not counting image recognition (which is not conversion). This is not a well-defined problem, by reasons close to those you just explained.

Please see my answer where I overview some variants.

—SA
Ron Beyer 23-Sep-13 17:44pm    
I 5'd yours, as always a good expansion on what I tried to say. I didn't mean to imply that there was a conversion from one to the other, in fact I was trying (perhaps poorly) to say that vector graphics and bitmap graphics are two different concepts.
Sergey Alexandrovich Kryukov 23-Sep-13 18:21pm    
I referred not to your answer and possible implied thought, but replied to OP who mentioned such "conversion". However, I think OP understands the problem well enough.
—SA
AlwaysLearningNewStuff 23-Sep-13 18:07pm    
Thank you for you solution.

The problem is that I have a bitmap with edges, and when I use GDI, I get blurred image.

While I am trying to solve problem using GDI, I thought that maybe, I could fix scaling problems with vector graphics.

I am a beginner, my ignorance is obvious just by reading through my question, and have never thought that I will need vector graphics for such a simple thing as scaling a bitmap, but I am stuck, so I have posted this question out of despair.
Thank you for your answer, you have 5 from me.

Regards.
There is no such thing as converted from bitmap graphics to vector, because this is something which does not have strict sense. It could be some kind of image recognition and can be performed just out of despair. I don't know why would you want it, so don't want to discuss it at this time. In normal business, you would operate with vector graphic in first place and save graphics in bitmaps of required size when needed, which is actually called rendering.

For Windows, the problem of vector graphics is actually reduced to creation of some model of vector graphics and rendering this model on screen (or other media, such as print page), which is all boiled down to either handling of the WM_PAINT event or rendering graphics on some bitmap on the fly. Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/dd145213%28v=vs.85%29.aspx[^].

The model can be anything; you can defined your own and implement all the operations you need. This is not actually too hard to do, but requires some architectural skills.

Windows metafiles are rudimentary, old, ugly and awkward to use. However, Windows API provides all one needs to support metafiles or enhance metafiles: http://en.wikipedia.org/wiki/Windows_Metafile[^],
http://msdn.microsoft.com/en-us/library/cc215212.aspx[^],
http://msdn.microsoft.com/en-us/library/dd145051%28v=VS.85%29.aspx[^].

You can look at look at available vector graphics standard, in particular on these two, XML-based:
http://en.wikipedia.org/wiki/SVG[^],
http://www.w3.org/Graphics/SVG[^],
http://www.w3.org/Graphics/SVG/IG/resources/svgprimer.html[^];
http://www.svgelves.com/[^],
http://en.wikipedia.org/wiki/Vector_Markup_Language[^].

I would say, the only widely used, strict and based on the open standards is the SVG. One important thing is it its use in the Web is standardized in HTML5: http://en.wikipedia.org/wiki/HTML5[^].

Its use is really supported by most Web browsers, directly of via plug-ins: http://en.wikipedia.org/wiki/SVG#Support_for_SVG_in_web_browsers[^].

SVG can also be hardware-accelerated, based on OpenVG: http://en.wikipedia.org/wiki/OpenVG[^].

You can do SVG programming using the open-source and cross-platform librsvg C library:
http://en.wikipedia.org/wiki/Librsvg[^],
https://wiki.gnome.org/LibRsvg[^].

See also this one: http://libboard.sourceforge.net/[^].

You can find some more: http://bit.ly/15n39ui[^].

—SA
 
Share this answer
 
Comments
AlwaysLearningNewStuff 23-Sep-13 18:07pm    
Thank you for you solution.

The problem is that I have a bitmap with edges, and when I use GDI, I get blurred image.

While I am trying to solve problem using GDI, I thought that maybe, I could fix scaling problems with vector graphics.

I am a beginner, my ignorance is obvious just by reading through my question, and have never thought that I will need vector graphics for such a simple thing as scaling a bitmap, but I am stuck, so I have posted this question out of despair.
Thank you for your answer, you have 5 from me.

Regards.
Sergey Alexandrovich Kryukov 23-Sep-13 18:19pm    
You are very welcome.

You are quite right. In all cases when you have scaling (and if images are not photographs), the best approach is to use vector graphics.

Good luck, call again.

—SA
AlwaysLearningNewStuff 23-Sep-13 18:53pm    
Thank you Mr. Kryukov, that means a lot to me.

I have never expected to come this far, the original project I work on was simple, but was altered recently, since new research and analysis have expanded my employers needs.

Being a beginner, I am terrified just thinking about using vector graphics, as I do not find it easy topic for a beginner.

Since the product is commercial, I must ask you if those libraries you have mentioned, are free to use for commercial use.

Again, thank you Mr.Kryukov, I will report my results soon ( I am sure that I will encounter some problems on this thorny path).

Regards.
Sergey Alexandrovich Kryukov 23-Sep-13 20:33pm    
It's all open-source. I try not to promote anything proprietary. You can also use XML parsers available in .NET FCL (there are at least tree: XmlReader/XmlWriter, XmlDocument (implementing DOM) and XDocument).
—SA
AlwaysLearningNewStuff 24-Sep-13 11:02am    
Thank you, Mr. Kryukov.

I had to check about libraries license, just in case.

I think that my employers can give me the picture in .EMF format ( that would be the ENHANCED META FILE right? ).

That way, the only thing I would need is to learn how to use metafile to scale that image on a dialog box background.

I will look for some examples from the book: Programing Windows 5th edition, from Charles Petzold. Perhaps, there is an example of scaling a picture from metafile.

Technically, I think that all the action will take place in the WM_PAINT, I just do not know how the scaling will be done at this moment.

Never mind, I better start learning, there is a lot of work awaiting me.

Hopefully we shall "speak" again, and I will have some good news!

Regards.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900