Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
2 ratings:
 5 out of 5     Rate this Document

Saving Measurement Studio CNiPicture to a Bitmap File Using GDI+

Primary Software: Measurement Studio>>Visual C++ Support
Primary Software Version: 7.0
Primary Software Fixed Version: 7.1
Secondary Software: N/A

Problem: The Measurement Studio Visual C++ libraries return images as CNiPictures. How do I save these to a file as bitmap?

Solution:
You can save the image to a file using the GDI+ API. GDI+ is available with Microsoft Visual Studio 2003 and higher. GDI+ provides classes for drawing and manipulating graphics.

Add the following to your stdafx.h:

#include "atlimage.h"


Assuming that you have a CNiGraph variable called graph, the following code creates a bitmap of the graph and saves it as a file named graph.bmp in the root directory of your C drive:

// Determine dimensions of the control.
RECT controlBounds;
graph.GetClientRect(&controlBounds);
int bmpWidth = controlBounds.right - controlBounds.left;
int bmpHeight = controlBounds.bottom - controlBounds.top;

// Create the bitmap with the same dimensions of the control.
CImage bmp;
bmp.Create(bmpWidth, bmpHeight, 24);

// Play the enhanced metafile from the CNiPicture to the bitmap.
RECT imageBounds = { 0, 0, bmpWidth, bmpHeight };
CNiPicture controlImage = graph.ControlImage();
HDC bmpDC = bmp.GetDC();
::PlayEnhMetaFile(bmpDC, reinterpret_cast< HENHMETAFILE >(controlImage.Handle), &imageBounds);
bmp.ReleaseDC();

// Save bitmap to a .bmp file.
bmp.Save(_T("C:\\graph.bmp"));


You can also save the image to PNG, JPEG, and GIF formats. For more information, refer to the function reference help for CImage::Save.

Related Links: NI Discussion Forums: How to get a bitmap from CNiGraph in VC++
GDI+

Attachments:





Report Date: 07/22/2005
Last Updated: 05/07/2006
Document ID: 3NLH9U5B

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit