取出资源文件中的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;

时间: 2024-08-28 08:37:15

取出资源文件中的bitmap,并将其保存到TMemoryStream中,从资源里载入图象而不丢失调色板的相关文章

将XML文件保存到DataGridView中

1 #region get护理单记录信息XML 2 //将XML文件保存到DataTable 3 private DataTable FromXML2DataTable(string XMLStr,string data_h,string data_d) 4 { 5 XmlDocument myDoc = new XmlDocument(); 6 myDoc.LoadXml(XMLStr); 7 if (string.IsNullOrEmpty(XMLStr) || !myDoc.HasChil

VB.NET屏幕指定区域截图代码,保存到Image中

VB.NET屏幕指定区域截图代码,保存到Image中 使用VB.NET实现屏幕上指定位置的图像进行截图功能,保存到Image中 Dim texthwnd As IntPtr texthwnd = FindWindowEx(0, 0, vbNullString, "等待输入验证码") Dim pl As SwtPj.WINDOWPLACEMENT GetWindowPlacement(texthwnd, pl) Dim image As Bitmap = New Bitmap(119,

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

一.操作string .list .map 对象 1.引入jar: jedis-2.1.0.jar 2.代码 /** * @param args */ public static void main(String[] args) { //连接redis服务 Jedis jedis = new Jedis("192.168.88.15",6379); //密码验证-如果你没有设置redis密码可不验证即可使用相关命令 //        jedis.auth("abcdefg&

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

一.操作string .list .map 对象 1.引入jar: jedis-2.1.0.jar 2.代码 /** * @param args */ public static void main(String[] args) { //连接redis服务 Jedis jedis = new Jedis("192.168.88.15",6379); //password验证-假设你没有设置redispassword可不验证就可以使用相关命令 //        jedis.auth(&

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

先建立es的mapping,也就是建立在es中建立一个空的Index,代码如下:执行后就会在es建lagou 这个index. from datetime import datetime from elasticsearch_dsl import DocType, Date, Nested, Boolean, \ analyzer, InnerDoc, Completion, Keyword, Text, Integer from elasticsearch_dsl.connections im

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

参考 C程序设计语言 #include <stdio.h> #include <string.h> //reverse函数: 倒置字符串s中各字符的位置 void reverse(char s[]){ int c,i,j; for(i=0,j=strlen(s)-1;i<j;i++,j--){ c=s[i], s[i]=s[j], s[j]=c; } } //itoa函数: 将数字n转换为字符串并保存到s中 void itoa(int n, char s[]){ int i,

Python获取个人网站的所有课程下载链接和密码,并保存到Mongodb中

1.获取网站课程的分类地址: ''' 爬取屌丝首页,获取每个分类名称和链接 ''' import requests from lxml import etree headers = { 'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36', } def get_class_data(): list_dat

实现一个函数itoa(int n, char s[]),将整数n这个数字转换为对应的字符串,保存到s中。

实现一个函数itoa(int n, char s[]),将整数n这个数字转换为对应的字符串,保存到s中. #include <stdio.h> void reverse(char *left, char *right){ while (left < right) {  char tmp = *left;  *left = *right;  *right = tmp;  left++;  right--; }} void my_itoa(int n, char s[]){ char *st

PHP session_set_save_handler将SESSION保存到Mysql中

将SESSION保存到mysql中 <?php /**  * SessionMysql 数据库存储类  */ defined('IN_QIAN') or exit('Access Denied'); class SessionMysql { public $lifetime = 1800; // 有效期,单位:秒(s),默认30分钟 public $db; public $table; /**  * 构造函数  */ public function __construct() { session