Click here to Skip to main content
15,885,985 members
Articles / Desktop Programming / MFC

ImageStone - A Powerful C++ Class Library for Image Manipulation

Rate me:
Please Sign up or sign in to vote.
4.81/5 (250 votes)
6 Dec 2011Zlib3 min read 117.8K   51.5K   405  
An article on a library for image manipulation
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>ImageStone: ImageHandle_IPicture.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.1 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a></div>
<h1>ImageHandle_IPicture.h</h1><div class="fragment"><pre class="fragment">00001 <span class="comment">/*</span>
00002 <span class="comment"> *   Copyright (C) =USTC= Fu Li</span>
00003 <span class="comment"> *</span>
00004 <span class="comment"> *   Author   :  Fu Li</span>
00005 <span class="comment"> *   Create   :  2005-9-12</span>
00006 <span class="comment"> *   Home     :  http://www.crazy-bit.com/</span>
00007 <span class="comment"> *   Mail     :  crazybit@263.net</span>
00008 <span class="comment"> *   History  :  </span>
00009 <span class="comment"> */</span>
00010 <span class="preprocessor">#ifndef __PCL_IMAGE_HANDLE_IPICTURE__2005_09_12__H__</span>
00011 <span class="preprocessor"></span><span class="preprocessor">#define __PCL_IMAGE_HANDLE_IPICTURE__2005_09_12__H__</span>
00012 <span class="preprocessor"></span><span class="preprocessor">#include "ImageHandleBase.h"</span>
00013 
00014 <span class="comment">//class FCImageHandle ;</span>
00015     <span class="keyword">class </span><a class="code" href="class_f_c_image_handle___i_picture.html">FCImageHandle_IPicture</a> ;
00016 
00017 <span class="comment">//=============================================================================</span>
<a name="l00021"></a><a class="code" href="class_f_c_image_handle___i_picture.html">00021</a> <span class="comment"></span><span class="keyword">class </span><a class="code" href="class_f_c_image_handle___i_picture.html">FCImageHandle_IPicture</a> : <span class="keyword">public</span> <a class="code" href="class_f_c_image_handle.html">FCImageHandle</a>
00022 {
00023     <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="class_f_c_image_handle_base.html#a1">LoadImageMemory</a> (<span class="keyword">const</span> BYTE* pStart, <span class="keywordtype">int</span> nFileSize)
00024     {
00025         <span class="keywordflow">if</span> (!pStart || (nFileSize &lt;= 0))
00026             <span class="keywordflow">return</span> false ;
00027 
00028         HGLOBAL   hBuffer = ::GlobalAlloc (GMEM_MOVEABLE, nFileSize) ;
00029 
00030         <span class="comment">// copy buffer to HGLOBAL</span>
00031         ::CopyMemory (::GlobalLock(hBuffer), pStart, nFileSize) ;
00032         ::GlobalUnlock (hBuffer) ;
00033 
00034         IStream     * pStream = NULL ;
00035         IPicture    * pIPic = NULL ;
00036         <a class="code" href="class_f_c_obj_image.html">FCObjImage</a>  * pImg = <span class="keyword">new</span> <a class="code" href="class_f_c_obj_image.html">FCObjImage</a> ;
00037         <span class="keywordflow">if</span> (::CreateStreamOnHGlobal (hBuffer, TRUE, &amp;pStream) == S_OK)
00038         {
00039             <span class="keywordflow">if</span> (::OleLoadPicture (pStream, nFileSize, FALSE, IID_IPicture, (LPVOID*)&amp;pIPic) == S_OK)
00040             {
00041                 OLE_HANDLE   hDDB ;
00042                 pIPic-&gt;get_Handle (&amp;hDDB) ;
00043 
00044                 BITMAP       bm ;
00045                 GetObject ((HGDIOBJ)hDDB, <span class="keyword">sizeof</span>(BITMAP), &amp;bm) ;
00046                 <span class="keywordflow">if</span> (pImg-&gt;<a class="code" href="class_f_c_obj_image.html#z27_0">Create</a> (bm.bmWidth, bm.bmHeight, 24))
00047                 {
00048                     <span class="comment">// dest format</span>
00049                     <a class="code" href="class_p_c_l__array.html">PCL_array&lt;BITMAPINFO&gt;</a>   bmfh (pImg-&gt;<a class="code" href="class_f_c_obj_image.html#z29_8">NewImgInfoWithPalette</a>()) ;
00050                     HDC     hdc = ::GetDC(NULL) ;
00051                     ::GetDIBits (hdc, (HBITMAP)hDDB, 0, bm.bmHeight, pImg-&gt;<a class="code" href="class_f_c_obj_image.html#z29_3">GetMemStart</a>(), bmfh.get(), DIB_RGB_COLORS) ;
00052                     ::ReleaseDC (NULL, hdc) ;
00053                 }
00054                 pIPic-&gt;Release() ;
00055             }
00056             pStream-&gt;Release() ;
00057         }
00058 
00059         <span class="keywordflow">if</span> (!pImg-&gt;<a class="code" href="class_f_c_obj_image.html#z29_0">IsValidImage</a>())
00060         {
00061             <span class="keyword">delete</span> pImg; <span class="keywordflow">return</span> <span class="keyword">false</span>;
00062         }
00063         <a class="code" href="class_p_c_l___interface___composite.html#a2">PCL_PushObject</a> (pImg) ; <span class="comment">// pImg's ownership</span>
00064         <span class="keywordflow">return</span> true ;
00065     }
00066 };
00067 
00068 <span class="comment">//=============================================================================</span>
00069 <span class="comment">// inline Implement</span>
00070 <span class="comment">//=============================================================================</span>
00071 
00072 <span class="preprocessor">#endif</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Wed Mar 8 11:12:46 2006 for ImageStone by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.1 </small></address>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The zlib/libpng License


Written By
Team Leader PhoXo
China China
graduate from University of Science and Technology of China at 2002.

Now I work at www.phoxo.com.

Comments and Discussions