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

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. J2EE课程设计——企业人力资源管理系统

    一.项目名称:企业人力资源管理系统 小组成员:冯雨倩 汤杰 二.项目需求: 随着现在计算机技术的不断完善,以及现代经济的不断发展,传统的管理技术不再满足企业的需要,越来越多的企业注重计算机信息管理系统 ...

  2. 『转』Bitdefender Internet Security 2013 – 免费1年

    活动中可以选择获取Bitdefender Internet Security 2013+Bitdefender Mobile Security (手机版)各一年激活码申请地址:https://part ...

  3. 流程设计器jQuery + svg/vml(Demo1 - 构建设计器UI界面)

    之前用Silverlight实现过一个流程设计器(Demo),使用起来不是很方便.打算参考GooFlow,结合自己对工作流的理解,用jQuery改造实现一个,力求简单实用. 第一步是要构建设计器的UI ...

  4. SharePoint Development - Custom Content Type using Visual Studio 2010 based SharePoint 2010

    博客地址 http://blog.csdn.net/foxdave 本文所述均来自之前实际的项目模块 首先再论述一下SharePoint ContentType内容类型 SharePoint的列表和文 ...

  5. LNMP架构下的nginx、mysql、php的源码安装

    一.LNMP的介绍 LNMP就是Linux+Nginx+Mysql+Php这种网站服务架构.Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统,常见版本有:centos.ubun ...

  6. Openlayers4中地图的导出

    概述: 本文讲述Openlayers4中地图的导出,包括调用天地图切片跨域.Geoserver11 WMS跨域等. 效果: 导出图片 页面展示 实现代码: document.getElementByI ...

  7. 第2本MATLAB书

    前面看的<DSP using MATLAB>后面还有两章,其内容太难了,看不下去,暂时放放: 因为工作中需要MATLAB和电磁场的相关知识,从网上找了本 初步翻了翻,里面有代码有图片,英文 ...

  8. 利用Web Services开发分布式应用

    一.引言 在前面文章中分别介绍了MSMQ和.NET Remoting技术,今天继续分享.NET 平台下另一种分布式技术——Web Services 二.Web Services 详细介绍 2.1 We ...

  9. eclipse adt logcat过滤用法

    点击Save Filters的加号,by Log Tag如下就可以只看2dx程序出来的debug信息了

  10. Panabit Live CD使用说明

    为了方便更多的用户实际使用Panabit,省去安装FreeBSD和Panabit等步骤,自2007年9月,即Panabit V7.09起,Panabit网站发布Panabit标准版安装包时,同步发布相 ...