MS Chart - save chart as bitmap? 
Author Message
 MS Chart - save chart as bitmap?

How can I save chart that I produced with MS Chart Control to some bitmap
file or even better to gif or jpg file?

Thanks!

--
Zeljko



Mon, 29 Apr 2002 03:00:00 GMT  
 MS Chart - save chart as bitmap?
I had a real {*filter*} of a time trying to do this, which should have been
really easy, this is how I ended up doing it, Not a particularly graceful
method, but it works, ignore the printing part.

Private Sub cmdPreview_Click()
On Error GoTo ErrTrap
Const PRINTER_MARGIN As Single = 1440

Dim sngGraphWidth As Single      '  Original Values
Dim sngGraphHeight As Single
Dim bytPageOrientation As Byte
Dim OriginalClipBoardPic As IPictureDisp
Dim OriginalClipboardText As String

    '   we need to resize the graph so that it always takes the whole
Printed Page
    '   Minus an inch for margins
    Me.MousePointer = vbHourglass
    picFrame.Visible = False
    LockWindowUpdate Me.hwnd
    sngGraphHeight = Me.Graph.Height
    sngGraphWidth = Me.Graph.Width
    bytPageOrientation = Printer.Orientation
    Printer.Orientation = vbPRORLandscape
    Me.Graph.Width = (Printer.Width - PRINTER_MARGIN * 2)      '  Can add *2
in here for better resolution, note
    Me.Graph.Height = (Printer.Height - PRINTER_MARGIN * 2)    '  have to
change fonts to larger first.
    ' Copy old items from Clipboard and clear it
    If Clipboard.GetFormat(vbCFText) Then
      OriginalClipboardText = Clipboard.GetText
    End If
    If Clipboard.GetFormat(vbCFBitmap) Or Clipboard.GetFormat(vbCFMetafile)
Or Clipboard.GetFormat(vbCFDIB) Then
      Set OriginalClipBoardPic = Clipboard.GetData()
    End If
    Clipboard.Clear
    ' Copy Graph to clipboard then send to printer
    Graph.EditCopy
    Printer.PaintPicture Clipboard.GetData(), PRINTER_MARGIN,
PRINTER_MARGIN, (Printer.Width - PRINTER_MARGIN * 2), (Printer.Height -
PRINTER_MARGIN * 2)
    Printer.EndDoc
    ' Restore everything
    Me.Graph.Height = sngGraphHeight
    Me.Graph.Width = sngGraphWidth
    Printer.Orientation = bytPageOrientation
    ' Restore Clipboard
    Clipboard.Clear
    If Not (OriginalClipBoardPic Is Nothing) Then
      Clipboard.SetData OriginalClipBoardPic
    End If
    If Len(OriginalClipboardText) Then
      Clipboard.SetText OriginalClipboardText
    End If
    picFrame.Visible = True
    LockWindowUpdate 0
ExitSub:
    Me.MousePointer = vbDefault
    Exit Sub
ErrTrap:
    MsgBox Err.Description
    Resume ExitSub
End Sub

Hope it helps.

Paul

Quote:
> How can I save chart that I produced with MS Chart Control to some bitmap
> file or even better to gif or jpg file?

> Thanks!

> --
> Zeljko



Sat, 25 May 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. MS Chart - save chart as bitmap?

2. MS Chart control and (fake) Gantt charts-Basic question

3. MS Chart v's Chart

4. MS Chart 6 Pie Chart questions

5. Saving Chart from Chart Control to GIF Files

6. MS-Chart to Bitmap ?

7. MS GRAPH 97 Chart saved to GIF file

8. Refresh chart data, not entire chart

9. Hide a chart tip in Excel 7.0 chart

10. Report with 2 Charts using RDC displays only the first chart

11. Report with 2 Charts using RDC displays only the first chart

12. Charting Question - How to do something like a Gantt chart

 

 
Powered by phpBB® Forum Software