Bitmap: a C++ class
        
The five steps involved to draw a bitmap:

Load bitmap using LoadBitmap or LoadImage
    Create a memory DC
    Select the bitmap into the memory DC.
    StretchBlt or BitBlt from the memory DC to screen DC.
    Cleanup.

This class is used in

Fractal Generator
    Avi Examples

The header file
Bitmap.h

/*
   Bitmap.h

Copyright (C) 2002-2005 René Nyffenegger

This source code is provided 'as-is', without any express or implied
   warranty. In no event will the author be held liable for any damages
   arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
   including commercial applications, and to alter it and redistribute it
   freely, subject to the following restrictions:

1. The origin of this source code must not be misrepresented; you must not
      claim that you wrote the original source code. If you use this source code
      in a product, an acknowledgment in the product documentation would be
      appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be
      misrepresented as being the original source code.

3. This notice may not be removed or altered from any source distribution.

René Nyffenegger rene.nyffenegger@adp-gmbh.ch
*/

#ifndef BITMAP_H_
#define BITMAP_H_

#include <string>
#include <sstream>
#include <windows.h>

class Bitmap {
  public:
    Bitmap();
    Bitmap(std::string const& file_name);

operator HBITMAP() const;

protected:
    friend class MemoryDC;
    Bitmap(HBITMAP);
    HBITMAP bitmap_;
};

#endif

The implementation file
Bitmap.cpp

/*
   Bitmap.h

Copyright (C) 2002-2005 René Nyffenegger

This source code is provided 'as-is', without any express or implied
   warranty. In no event will the author be held liable for any damages
   arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
   including commercial applications, and to alter it and redistribute it
   freely, subject to the following restrictions:

1. The origin of this source code must not be misrepresented; you must not
      claim that you wrote the original source code. If you use this source code
      in a product, an acknowledgment in the product documentation would be
      appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be
      misrepresented as being the original source code.

3. This notice may not be removed or altered from any source distribution.

René Nyffenegger rene.nyffenegger@adp-gmbh.ch
*/

#include "Bitmap.h"

/*! \page bmps_in_memory drawing on Bitmaps in Memory
 *
 *   If you want to use bitmaps in memory and draw upon them,
 *   you have to follow these steps:
 *
 *   \li 1 Allocate a MemoryDC (this is a memory device context used for the drawing operations
 *         which a device context provides)
 *   \li 2 Create a CompatibleBitmap
 *   \li 3 Select this compatible Bitmap into the memory device context (the bitmap now becomes
 *         the surface for the drawing operations made onto the device context. Keep the
 *         return value for unselecting it again
 *   \li 4 do your drawings
 *   \li 5 unselect the selected bitmap
 *
 *
 * See the following code for an example.
 *
 *   \code
 
  MemoryDC memDc;
  CompatibleBitmap compBmp(memDc, width, height);
  Bitmap oldBmp = memDc.Select(compBmp);
       
  // Your drawing operations go here
 
  memDc.Select(oldBmp);

*   \endcode
 *
 *
 *
 */

Bitmap::Bitmap() : bitmap_(0) {}

Bitmap::Bitmap(std::string const& file_name) {
  bitmap_ = static_cast<HBITMAP>(::LoadImage(0, file_name.c_str(), IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION));
}

Bitmap::Bitmap(HBITMAP bmp) : bitmap_(bmp) {

}

Bitmap::operator HBITMAP() const {
  return bitmap_;
}

Bitmap: a C++ class的更多相关文章

  1. [翻译]开发文档:android Bitmap的高效使用

    内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...

  2. 【开源毕设】一款精美的家校互动APP分享——爱吖校推 [你关注的,我们才推](持续开源更新3)附高效动态压缩Bitmap

    一.写在前面 爱吖校推如同它的名字一样,是一款校园类信息推送交流平台,这么多的家校互动类软件,你选择了我,这是我的幸运.从第一次在博客园上写博客到现在,我一次一次地提高博文的质量和代码的可读性,都是为 ...

  3. Android Bitmap 和 ByteArray的互相转换

    Android Bitmap 和 ByteArray的互相转换 移动平台图像处理,需要将图像传给native处理,如何传递?将bitmap转换成一个 byte[] 方便传递也方便cpp代码直接处理图像 ...

  4. Android-Drawable、Bitmap、byte[]、资源文件相互转换

    我们在Android的开发中,经常可以遇到图片的处理,当中,有很多是 Bitmap.Drawable.byte[]和资源文件它们直接相互转换. 今天就此总结一下: 1.资源文件转为Drawable 2 ...

  5. bitmap对海量无重复的整数排序--转

    原文地址:http://blog.csdn.net/u013074465/article/details/46956295 现在有n个无重复的正整数(n 小于10的7次方),如果内存限制在1.5M以内 ...

  6. 基于位图(Bitmap、BitmapData)的图片处理方法(C#)

    目前操作位图的主流方法有三种: 1.基于Bitmap像素的处理方法,以GetPixel()和SetPixel()方法为主.方法调用简单,但是效率偏低. 2.基于内存的像素操作方法,以System.Ru ...

  7. android:布局、绘制、内存泄露、响应速度、listview和bitmap、线程优化以及一些优化的建议!

    1.布局优化 首先删除布局中无用的控件和层级,其次有选择地使用性能较低的viewgroup,比如布局中既可以使用RelativeLayout和LinearLayout,那我们就采用LinearLayo ...

  8. 获取View的截图-将View转换为Bitmap对象

    开发中,有时候需要获取View的截图来做动画来达到动画流程的目的 原理:将View的内容画到一个Bitmap画布上,然后取出 下面封装了一个从View生成Bitmap的工具类 /** * 将View转 ...

  9. bitmap解码

    #include <stdio.h> #include <stdlib.h> #include <string.h> #define BYTE unsigned c ...

  10. Bitmap转换成BitmapImage

    public BitmapImage BitmapToBitmapImage(System.Drawing.Bitmap bitmap) { MemoryStream ms = new MemoryS ...

随机推荐

  1. JAVA中有一个特殊的类: Object

    JAVA中有一个特殊的类: Object.它是JAVA体系中所有类的父类(直接父类或者间接父类). 此类中的方法可以使所的类均继承. 以下介绍的三种方法属于Object: (1) finalize方法 ...

  2. hrbustoj 1318:蛋疼的蚂蚁(计算几何,凸包变种,叉积应用)

    蛋疼的蚂蚁 Time Limit: 1000 MS     Memory Limit: 65536 K Total Submit: 39(22 users)    Total Accepted: 26 ...

  3. 编程之美 set 6 寻找最近点对

    这道题在算法课上当做例题讲过, 当时的印象也比较深 另有一道近似算法的题也在算法课上讲过, 并且印象更深, 复习的时候完全没管, 以为志在必得, 结果真考了那道近似算法, 我却没能打出来 为避免阴沟翻 ...

  4. C语言while语句

    在C语言中,共有三大常用的程序结构: 顺序结构:代码从前往后执行,没有任何“拐弯抹角”: 选择结构:也叫分支结构,重点要掌握 if else.switch 以及条件运算符: 循环结构:重复执行同一段代 ...

  5. oracle11g配置dataguard

     DATAGUARD是通过建立一个PRIMARY和STANDBY组来确立其参照关系.      STANDBY一旦创建,DATAGUARD就会通过将主数据库(PRIMARY)的REDO传递给STAND ...

  6. 【BZOJ3572】[Hnoi2014]世界树 虚树

    [BZOJ3572][Hnoi2014]世界树 Description 世界树是一棵无比巨大的树,它伸出的枝干构成了整个世界.在这里,生存着各种各样的种族和生灵,他们共同信奉着绝对公正公平的女神艾莉森 ...

  7. Objective-C入门教材

    2011-05-11 15:58 三聪 cnblogs 字号:T | T 阅读本文前,你也要了解面向对象的基本概念.对象的使用以及面象对象设计模式都是bjective-C进行面向对象编程和设计Coco ...

  8. onbeforeunload 适用DOM 0级,不适用 DOM 2级

    你可以在控制台试下: window.addEventListener("beforeunload", function () { return 'ss'; }); 我这里 chro ...

  9. 170314、工具:apache httpClient多线程并发情况下安全实用及工具类分享

    简单用法介绍:介绍来源网络 建立连接:在HttpClient中使用多线程的一个主要原因是可以一次执行多个方法.在执行期间,每一个方法都使用一个HttpConnection实例.由于在同一时间多个连接只 ...

  10. 160519、Oracle中将查询出的多条记录的某个字段拼接成一个字符串的方法

    with temp as( select 'China' nation ,'Guangzhou' city from dual union all select 'China' nation ,'Sh ...