Bitmap: a C++ class
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的更多相关文章
- [翻译]开发文档:android Bitmap的高效使用
内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...
- 【开源毕设】一款精美的家校互动APP分享——爱吖校推 [你关注的,我们才推](持续开源更新3)附高效动态压缩Bitmap
一.写在前面 爱吖校推如同它的名字一样,是一款校园类信息推送交流平台,这么多的家校互动类软件,你选择了我,这是我的幸运.从第一次在博客园上写博客到现在,我一次一次地提高博文的质量和代码的可读性,都是为 ...
- Android Bitmap 和 ByteArray的互相转换
Android Bitmap 和 ByteArray的互相转换 移动平台图像处理,需要将图像传给native处理,如何传递?将bitmap转换成一个 byte[] 方便传递也方便cpp代码直接处理图像 ...
- Android-Drawable、Bitmap、byte[]、资源文件相互转换
我们在Android的开发中,经常可以遇到图片的处理,当中,有很多是 Bitmap.Drawable.byte[]和资源文件它们直接相互转换. 今天就此总结一下: 1.资源文件转为Drawable 2 ...
- bitmap对海量无重复的整数排序--转
原文地址:http://blog.csdn.net/u013074465/article/details/46956295 现在有n个无重复的正整数(n 小于10的7次方),如果内存限制在1.5M以内 ...
- 基于位图(Bitmap、BitmapData)的图片处理方法(C#)
目前操作位图的主流方法有三种: 1.基于Bitmap像素的处理方法,以GetPixel()和SetPixel()方法为主.方法调用简单,但是效率偏低. 2.基于内存的像素操作方法,以System.Ru ...
- android:布局、绘制、内存泄露、响应速度、listview和bitmap、线程优化以及一些优化的建议!
1.布局优化 首先删除布局中无用的控件和层级,其次有选择地使用性能较低的viewgroup,比如布局中既可以使用RelativeLayout和LinearLayout,那我们就采用LinearLayo ...
- 获取View的截图-将View转换为Bitmap对象
开发中,有时候需要获取View的截图来做动画来达到动画流程的目的 原理:将View的内容画到一个Bitmap画布上,然后取出 下面封装了一个从View生成Bitmap的工具类 /** * 将View转 ...
- bitmap解码
#include <stdio.h> #include <stdlib.h> #include <string.h> #define BYTE unsigned c ...
- Bitmap转换成BitmapImage
public BitmapImage BitmapToBitmapImage(System.Drawing.Bitmap bitmap) { MemoryStream ms = new MemoryS ...
随机推荐
- java----EL表达式
Java Web中的EL(表达式语言)详解 表达式语言(Expression Language)简称EL,它是JSP2.0中引入的一个新内容.通过EL可以简化在JSP开发中对对象的引用,从而规范页面 ...
- 转载:Struts2支持断点续传下载实现
转自:http://blog.sina.com.cn/s/blog_667ac0360102eckm.html package com.ipan.core.controller.web.result; ...
- Unity中对SQL数据库的操作
在Unity中,我们有时候需要连接数据库来达到数据的读取与储存.而在.NET平台下,ADO.NET为我们提供了公开数据访问服务的类.客户端应用程序可以使用ADO.NET来连接到数据源,并查询,添加,删 ...
- WPF XAML 特殊字符(小于号、大于号、引号、&符号)
XAML 受限于 XML 规则.例如, XML 特别关注一些特殊字符,如 & < > 如果试图使用这些字符设置一个元素内容,将会遇到许多麻烦,因为 XAML 解析器认为您正在做其 ...
- Oracle的归档日志
归档模式的特点和要求 在归档模式下,当LGWR后台进程的写操作从一个重做日志组切换到另一个重做日志组后,归档写后台进程(ARCH/ARCRn)就会将原来的重做日志的信息复制到归档日志文件中. 可以把归 ...
- aar
aar是一个类似于jar的文件格式.但是他们之间是有区别的.jar:仅仅包含class和清单文件,没有资源文件.aar:包含了class文件和资源文件.说白了就是Android的专属“jar” 将代码 ...
- 教你如何在 Android 使用多线程下载文件
# 教你如何在 Android 使用多线程下载文件 前言 在 Android 日常开发中,我们会经常遇到下载文件需求,这里我们也可以用系统自带的 api DownloadManager 来解决这个问题 ...
- VS2010类模板更改,增加版权等等信息
本文转载自XDOTNET 在开发过程中往往需要在每一个页面(类)增加注释等等内容,VS2010中可以修改模板,在原有模板中增加一个类,会引用System等等命名空间,以及一些程序集.下面我们来看看如何 ...
- will-change
目的: 让GPU分担CPU的工作,从而优化和分配内存,告知浏览器做好动画的准备. 背景: 注意事项: 1,will-change虽然可以加速,但是,一定一定要适度使用: 2,使用伪元素,独立渲染: 不 ...
- 【黑金原创教程】【Modelsim】【第二章】Modelsim就是电视机
声明:本文为黑金动力社区(http://www.heijin.org)原创教程,如需转载请注明出处,谢谢! 黑金动力社区2013年原创教程连载计划: http://www.cnblogs.com/al ...