取出资源文件中的bitmap,并将其保存到TMemoryStream中,从资源里载入图象而不丢失调色板
从资源里载入图象而不丢失调色板
procedure loadgraphic(naam:string);
var
{ I've moved these in here, so they exist only during the lifetime of the
procedure. }
HResInfo: THandle;
BMF: TBitmapFileHeader;
MemHandle: THandle;
Stream: TMemoryStream;
ResPtr: PByte;
ResSize: Longint;
null:array [0..8] of char;
begin
{ In this first part, you are retrieving the bitmap from the resource.
The bitmap that you retrieve is almost, but not quite, the same as a
.BMP file (complete with palette information). }
strpcopy (null, naam);
HResInfo := FindResource(HInstance, null, RT_Bitmap);
ResSize := SizeofResource(HInstance, HResInfo);
MemHandle := LoadResource(HInstance, HResInfo);
ResPtr := LockResource(MemHandle);
{ Think of a MemoryStream almost as a "File" that exists in memory.
With a Stream, you can treat either the same way! }
Stream := TMemoryStream.Create;
try
Stream.SetSize(ResSize + SizeOf(BMF));
{ Next, you effectively create a .BMP file in memory by first writing
the header (missing from the resource, so you add it)... }
BMF.bfType := $4D42;
Stream.Write(BMF, SizeOf(BMF));
{ Then the data from the resource. Now the stream contains a .BMP file }
Stream.Write(ResPtr^, ResSize);
{ So you point to the beginning of the stream... }
Stream.Seek(0, 0);
{ ...and let Delphi's TBitmap load it in }
Bitmap:=tbitmap.create;
Bitmap.LoadFromStream(Stream);
{ At this point, you are done with the stream and the resource. }
finally
Stream.Free;
end;
FreeResource(MemHandle);
end;
取出资源文件中的bitmap,并将其保存到TMemoryStream中,从资源里载入图象而不丢失调色板的更多相关文章
- 下载某资源文件并加载其中的所有Prefab到场景中
using System.Collections; using System.Collections.Generic; using UnityEngine; /// <summary> / ...
- ffmpeg从AVFrame取出yuv数据到保存到char*中
ffmpeg从AVFrame取出yuv数据到保存到char*中 很多人一直不知道怎么利用ffmpeg从AVFrame取出yuv数据到保存到char*中,下面代码将yuv420p和yuv422p的数 ...
- Android把图片保存到SQLite中
1.bitmap保存到SQLite 中 数据格式:Blob db.execSQL("Create table " + TABLE_NAME + "( _id INTEGE ...
- 1.scrapy爬取的数据保存到es中
先建立es的mapping,也就是建立在es中建立一个空的Index,代码如下:执行后就会在es建lagou 这个index. from datetime import datetime fr ...
- 【redis,1】java操作redis: 将string、list、map、自己定义的对象保存到redis中
一.操作string .list .map 对象 1.引入jar: jedis-2.1.0.jar 2.代码 /** * @param args */ public s ...
- 将数字n转换为字符串并保存到s中
将数字n转换为字符串并保存到s中 参考 C程序设计语言 #include <stdio.h> #include <string.h> //reverse函数: 倒置字符串s中各 ...
- c# 抓取和解析网页,并将table数据保存到datatable中(其他格式也可以,自己去修改)
使用HtmlAgilityPack 基础请参考这篇博客:https://www.cnblogs.com/fishyues/p/10232822.html 下面是根据抓取的页面string 来解析并保存 ...
- Flask实战第43天:把图片验证码和短信验证码保存到memcached中
前面我们已经获取到图片验证码和短信验证码,但是我们还没有把它们保存起来.同样的,我们和之前的邮箱验证码一样,保存到memcached中 编辑commom.vews.py .. from utils i ...
- Java实现Qt的SIGNAL-SLOT机制(保存到Map中,从而将它们关联起来,收到信号进行解析,最后反射调用)
SIGNAL-SLOT是Qt的一大特色,使用起来十分方便.在传统的AWT和Swing编程中,我们都是为要在 监听的对象上添加Listener监听器.被监听对象中保存有Listener的列表,当相关事件 ...
随机推荐
- Informatica存储库和集成服务的配置
1.配置存储库 首先登陆informatica的管理界面: 这里的用户名不区分大小写(注意后面配置集成服务是区分的,后面会提到)
- Python+Flask+MysqL的web建设技术过程
一.前言(个人学期总结) 个人总结一下这学期对于Python+Flask+MysqL的web建设技术过程的学习体会,Flask小辣椒框架相对于其他框架而言,更加稳定,不会有莫名其妙的错误,容错性强,运 ...
- New Concept English Two 5
$课文9 冷遇 83. On Wednesday evening, we went to the Town Hall. 星期三的晚上,我们去了市政厅. 84. It was the last day ...
- 通过Ftp put命令上传导致文件损坏的解决办法
通过Linux命令行向在一台Windows FTP服务器上传文件.然后在另一台Windows客户机登录FTP服务器下载,但是下载后的文件大小变了,exe文件错误了不能正确执行.刻意打包的文件(.rar ...
- 2017年7月ROS学习资料小结
<孙子兵法·谋攻篇>:"上兵伐谋,其次伐交,其次伐兵,其下攻城:攻城之法为不得已." 任何发生在自己国土上的战争,即便胜利,也饱含屈辱. ----~~~~----Gaz ...
- EM算法的思考
参考文献1: http://blog.sina.com.cn/s/blog_6c7b434d01013zwe.html 参考文献2: http://www.cnblogs.com/jerrylead/ ...
- springboot整合mybatis增删改查(一):项目创建
新建 打开 IDEA 工具,通过 File -> New -> Project->Spring Initializr 主要步骤包括: 选择 Spring Initializr 项目 ...
- 20155234 2016-2017-2 《Java程序设计》第8周学习总结
20155234 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 java.util.loggging包提供了日志功能相关类与接口. 使用日志的起点是Logg ...
- POJ2728 Desert King 最优比率生成树
题目 http://poj.org/problem?id=2728 关键词:0/1分数规划,参数搜索,二分法,dinkelbach 参考资料:http://hi.baidu.com/zzningxp/ ...
- IIS7Appcmd 命令详解
IIS7 Appcmd 命令详解 废话不说!虽然有配置界面管理器!但是做安装包的时候命令创建是必不可少的!最近使用NSIS制作安装包仔细研究了一下Appcmd的命令,可谓是功能齐全. 上网查了些资料, ...