Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C++ for experts help please!

Posted on 2003-11-30
4
Medium Priority
?
325 Views
Last Modified: 2010-04-02
Hello experts!  

I need to convert an algorithm into a bitmap image.  This is the same as a surface graph from 90 elevation and 0 rotation.  I run a program in VB that looks like this:

Dim a, b as Long

Surface.Elevation = 90
Surface.Rotation = 0
For a = 0 to 999
     For b = 0 to 100
          FunctionNeededPopulateSurface a, b
     Next b
Next a
ExportSurface "MySurface.bmp"

I populate a graphing component with this code.  I then have to export the .bmp from the component.  I would like to bypass the graphing component and build the .bmp directly.  This is 100,000 datapoints that I am calculating here. The bmp is used in a "stretch environment".   It takes about 15 seconds to get the output on my machine.  I would like to build a C++ DLL library that I can reference and call a function once and have it do the math and create the .bmp for me.  I think this should drastically cut some time.  

Any ideas on how to accomplish this?  Can I get away with only one pixel per datapoint?

Many thanks!
0
Comment
Question by:OptionsMM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 9845056
Just create an HBITMAP of the desired size, select it into a DC, and then use SetPixel() API.  The question is rather vague as to the algorithm you want to apply to a,b... but assuming a is a horizontal coordinate and b is a vertical coordinate, then all you need to do is

     SetPixel( hdc, a,b, RGB(0,0,0) ); // make the point black

Note: SetPixel() can be rather slow, but it is *always* the first pass, and then we can work on faster functions.

When you are done, you can output the bitmap to a file, or otherwise do whatever you want.

Do you need help with any of these steps?  Or do you need to also draw a grid and a legend, etc.?  Or is the difficult part the algorothim you need to "have it do the math"?  If so, please explain.  Thanks!

-- Dan
0
 

Author Comment

by:OptionsMM
ID: 9846765
Hi Dan!  

Thanks for the quick reply!  I am not a c++ programmer.  I am building a 3d surface graph in a contour mode (like a topographical map).  The problem I am running into is the component gets overwhelmed trying to store 100,000 datapoints and rendering the picture as the graph spins and zooms.  I was able to solve the problem by creating a hidden instance of the chart, and then populating it with the 100,000 points.  Next I would export a .bmp and, and set the "flloor" of the graph to the bmp.  This gave me all the functionality without the slow performance.  

My idea was that simce it is a simple .bmp why not build a c++ program to generate the image and bypass creating an instance of the chart method i described above. However, perhaps it is best to write it in VB first?

I have never worked with an image before.  the code you posted didnt make any sense to me.

Thanks!




0
 

Author Comment

by:OptionsMM
ID: 9846886
Here is where I am at however I only get "-1" as an output

Sub SavePic()

    Dim Pic As New StdPicture
    Dim A As Long
    Dim B As Long

    Set Pic = LoadPicture("C:\Dot.bmp")
    B = CreateCompatibleDC(0)
    A = SetPixel(B, 1, 1, RGB(255, 0, 0))
   
    SavePicture Pic, "C:\Dot.bmp"
    MsgBox A
   
End Sub
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 1500 total points
ID: 9854190
The SetPixel() API function will not affect the variables A and B.  It only places a dot onto a bitmap.  The return value of SetPixel just indicates success of failuer -- it returns -1 when the call fails (most usually because you did not send in a valid HDC parameter)

I am still trying to understand your question.
Do you already have a function that will make A and B (or preferrably variables named X and Y) into screen cordinates?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question