Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

save 3d graph as image (file) - GDI+ Error

Hello forum,

 

i have a problem to save a 3d graph as an image (jpg file). I searched in this forum how to
save the 3d graph as an image and found a solution but sometimes an error occures (GDI+).
Maybe someone can help me.

 

Iam using VS 2005 and NI Measurement Studio 8.5 for VS 2005
and here is what I did:

 

'#
For Iteration As Short = 0 To 100

 

  ' some opeartions to generate arrays
  ' some calculation etc.
  '...

 

  ' sketch 3d graph with
  CW3DGraph.Plot3DParametricSurface(arrX, arrY, arrZ, Type.Missing)


  ' create image variable to get control of 3d graph
  Dim img As System.Drawing.Image = Nothing
  Dim Ni3DgraphErrorCounter As Short = 1

 

  '##########
  ' ERROR GDI+ : create image of 3d graph - if error: repeat process up to 10 times until image is created/saved
  Do While Ni3DgraphErrorCounter < 10
                       
    ' reset image variable for 3dgraph
    img = Nothing

 

    ' get control of 3dgraph and try to save as image (jpg file)
    Try
      CW3DGraph.Update()
      img = CW3DGraph.ControlImage()

                                                                   

      ' here GDI+ error occures - but only sometimes!
      img.Save(tmpFileFolder & "\3dGraphNo" & (Iteration + 1) & ".JPG", System.Drawing.Imaging.ImageFormat.Jpeg)
      ' end of error occures
                             
      ' if image is saved succesfully: do something with saved image
 
      Kill(tmpFileFolder & "3dGraphNo" & (Iteration + 1) & ".JPG")          ' delete generated image file                              
 
      Exit Do                                         ' image creation successful - exit loop
                       
    Catch ex As Exception
      ' error occured -> show user infos in logwindow (but only once)


      If Ni3DgraphErrorCounter = 1 Then
        ' first error message
        frmMain.logWindow.Items.Add("")
        frmMain.logWindow.Items.Add("ERROR at creating image of 3dGraph " & (Iteration + 1) & " --> repeat process")
        frmMain.logWindow.Items.Add(ex)
      End If      ' check if Ni3DgraphErrorCounter = 1


      Ni3DgraphErrorCounter += 1

 

    ' thought following instruction can help to provide GDI+ Error - but not working...
    Finally
      If Not img Is Nothing Then
        img.Dispose()               ' free resources of 3dgraph image
      End If

 

    End Try

 

  Loop

' end of try / catch image creation error

'#####


Next Iteration
'# end of source code

 

 

And here is the logWindow Error Message:

'#
ERROR at creating image of 3dGraph 7 --> repeat process
  System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. 
  at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
  at System.Drawing.Image.Save(String filename, ImageFormat format)
  at ProjectName.FormName.SubName(Object sender, EventArgs e)
'#   

            

As you see - the first iterations are working without errors. No problem to save 3dGraph as image.
But after a random number of iterations the GDI+ Error occures and from this point for all following iterations.
I dont know why a GDI+ Error occures because at every iteration iam using a different filename to save the image
and i also delete the generated file at the end of the iteration (if succesfully saved before) and also free resources
with .dispose instruction.

 

Where is the problem?

 

Thanks for help
Robert_R
 

0 Kudos
Message 1 of 2
(4,065 Views)

Or is there an easier/better way to save the 3d graph as image (file).

For example: Its very easy to save a Scattergraph or Waveformgraph as image (file)

ScatterGraph.ToImage.Save(tmpFileFolder & "\Filename.JPG")

0 Kudos
Message 2 of 2
(4,063 Views)