取出资源文件中的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的列表,当相关事件 ...
随机推荐
- Java——基本概念
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
- 『转』谷歌发布Windows版Chrome App Launcher
据国外媒体报道,谷歌发布了Windows版Chrome App Launcher,Windows用户现在因此能够使用谷歌的许多网络应用,如Chrome浏览器.Gmail.Google Drive和Ch ...
- Tomcat启动 Unable to process Jar entry [javassist/XXXXXX.class]
例如: 03-Mar-2017 17:01:45.864 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.startup.Co ...
- 使用TortoiseGit+码云管理项目代码
1.下载安装msysgit. 2.下载安装tortoisegit. 3.创建ssh密钥. 开始–所有程序–TortoiseGit–PuTTYgen 生成方法:点击“Generate”后,鼠标在key下 ...
- Web开发需要常见的问题
1.sendRedirec()方法执行后,是会直接跳转到目标页面还是执行完其后的语句再跳转到目标页面??? 该方法在执行完其后面的语句才会跳转到目标页面,比如: public void doGet(H ...
- return 0;和exit(0);的区别
首先说一下fork和vfork的差别: fork 是 创建一个子进程,并把父进程的内存数据copy到子进程中. vfork是 创建一个子进程,并和父进程的内存数据share一起用. 这两个的差别是,一 ...
- PHP安全性漫谈
最近刚做完两个PHP的网站项目,客户虽然没有安全性的相关需求,但是自己不能放过对自己的要求,何况对以后做电子商务的项目相当有帮助,呵呵,早准备早超生,经过查看PHP 帮助和相关资料~~~~ ...
- unity的sprite添加点击事件
直接说方法 添加一个2dxxx的碰撞器 添加一个OnMouseDown的回调函数,这个函数看script reference就可以
- pgsql的同步须知
pgsql的同步模式是根据master上的日志来做的同步,有两种同步方式,参考http://www.chinaxing.org/articles/Postgres/2012/12/14/2012-12 ...
- php 的两个扩展 memcache 和 memcachd
今天绕了很大弯子, 因为自己写的php的memcache类. 于是出现了下面问题 在本地测试好好的, 线上就出了问题 原因是线上使用的是memcache, 我本地使用的是memcached 区别参考网 ...