从资源里载入图象而不丢失调色板

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中,从资源里载入图象而不丢失调色板的更多相关文章

  1. 下载某资源文件并加载其中的所有Prefab到场景中

    using System.Collections; using System.Collections.Generic; using UnityEngine; /// <summary> / ...

  2. ffmpeg从AVFrame取出yuv数据到保存到char*中

    ffmpeg从AVFrame取出yuv数据到保存到char*中   很多人一直不知道怎么利用ffmpeg从AVFrame取出yuv数据到保存到char*中,下面代码将yuv420p和yuv422p的数 ...

  3. Android把图片保存到SQLite中

    1.bitmap保存到SQLite 中 数据格式:Blob db.execSQL("Create table " + TABLE_NAME + "( _id INTEGE ...

  4. 1.scrapy爬取的数据保存到es中

    先建立es的mapping,也就是建立在es中建立一个空的Index,代码如下:执行后就会在es建lagou 这个index.     from datetime import datetime fr ...

  5. 【redis,1】java操作redis: 将string、list、map、自己定义的对象保存到redis中

    一.操作string .list .map 对象 1.引入jar: jedis-2.1.0.jar   2.代码 /**      * @param args      */     public s ...

  6. 将数字n转换为字符串并保存到s中

    将数字n转换为字符串并保存到s中 参考 C程序设计语言 #include <stdio.h> #include <string.h> //reverse函数: 倒置字符串s中各 ...

  7. c# 抓取和解析网页,并将table数据保存到datatable中(其他格式也可以,自己去修改)

    使用HtmlAgilityPack 基础请参考这篇博客:https://www.cnblogs.com/fishyues/p/10232822.html 下面是根据抓取的页面string 来解析并保存 ...

  8. Flask实战第43天:把图片验证码和短信验证码保存到memcached中

    前面我们已经获取到图片验证码和短信验证码,但是我们还没有把它们保存起来.同样的,我们和之前的邮箱验证码一样,保存到memcached中 编辑commom.vews.py .. from utils i ...

  9. Java实现Qt的SIGNAL-SLOT机制(保存到Map中,从而将它们关联起来,收到信号进行解析,最后反射调用)

    SIGNAL-SLOT是Qt的一大特色,使用起来十分方便.在传统的AWT和Swing编程中,我们都是为要在 监听的对象上添加Listener监听器.被监听对象中保存有Listener的列表,当相关事件 ...

随机推荐

  1. hadoop安装及注意事项

    一.hadoop安装及注意事项1.安装hadoop的环境,必须在你的系统中有java的环境.2.必须安装ssh,有的系统默认就安装,如果没有安装需要手动安装.    可以用yum install -y ...

  2. 055——VUE中vue-router之路由参数的随意设置与伪静态链接地址处理:

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. 身份证&银行卡识别方案

    一.  调用第三方服务 腾讯云OCR识别: 实现方法:Post图片 URL到腾讯云服务器.Post图片文件 到腾讯云服务器 b.    报价: 月接口调用总量 0<调用量≤1000 1000&l ...

  4. PostgreSQL逻辑复制槽

    Schema | Name | Result data type | Argument data types | Type ------------+------------------------- ...

  5. linux中~和/区别

    /是指根目录  就是所有目录最顶层的目录~指的是你当前用户的主目录  如果是root用户的话就是/root/目录    如果是其他用户的话就是/home/下以你用户名命名的用户 在linux里面,~/ ...

  6. HDU 2485

    http://acm.hdu.edu.cn/showproblem.php?pid=2485 n个车站,m条边,两边之间费用为1,问最少摧毁多少车站,使得1-n无法在k时间内到达 将2-(n-1)每个 ...

  7. php 递归读取目录

    看到很多面试题有这个,今天有机会写了一下. 要注意的是: 在opendir这个函数用完后,要注意closedir,因为安全问题,打开的目录依然存在于内存中,在并发情况下最好关闭,不然容易被破坏. &l ...

  8. 《DSP using MATLAB》Problem 2.5

    2.代码: %% ------------------------------------------------------------------------ %% Output Info abo ...

  9. wiremock docker 运行

    使用docker 模式 docker-compose yaml version: '3.3' services: service1: image: rodolpheche/wiremock ports ...

  10. 【转】Linux 图形界面与命令行模式切换

    原文网址:http://blog.csdn.net/ldl22847/article/details/7600368 Tip:使用环境VMware Workstation    OS:CentOS 6 ...