hbmMask& ICONINFO中的hbmColor [英] hbmMask & hbmColor in ICONINFO

查看:370
本文介绍了hbmMask& ICONINFO中的hbmColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结构ICONINFO具有两个字段hbmMask& hbmColor.这些字段的类型为HIBITMAP.

我想将位图转换为图标.当我加载位图文件时,将返回位图句柄HIBITMAP.使用该方法,如何获取hbmMask&的值hbmColor代表位掩码位图&颜色位图.如果将两个丝线都设置为已加载位图的HIBITMAP,则会得到图标,但没有颜色.

我们可以从HIBITMAP中为这些字段提取适当的值吗?

The structure ICONINFO has two fields hbmMask & hbmColor. These fields are of type HIBITMAP.

I want to convert bitmap to icon. When I load bitmap file, bitmap handle HIBITMAP is returned. Using this, how can I get values for hbmMask & hbmColor which represent bitmask bitmap & color bitmap. If I set both filieds to HIBITMAP of the loaded bitmap, I get icon but without colors.

Can we extract the proper values for these fields from HIBITMAP?

推荐答案

仅仅因为一个Icon实际上是两个位图:一个图像(定义像素的颜色)和一个蒙版(定义必须绘制的像素,不需要绘制的像素,因此是透明的).

HBITMAP只是一个图像,因此您不能提取"另一个图像.
但是您可以通过算法猜测"它.例如:

A)将蒙版完全设为黑色":将绘制所有像素(不透明)

B)观察图像的像素,猜出一种可以用作透明颜色"的颜色.创建一个白色"的蒙版,其中图像具有该颜色. (如果图像是图形,则可以将左上角的像素用作背景色")

C)与B相同,但在给定近似值下,也考虑透明的颜色,这些颜色在给定的近似值下接近.

A很简单,B很简单(只需要将彩色图像的BitBlt转换为单色位图),C则需要对图片进行更多的解析.
In the way you asked, no. Simply because an Icon is actually two bitmaps: an image (defines the color of the pixels) and a mask (defines which pixels have to be painted and which not, and hence be transparent).

An HBITMAP is just one image, so you cannot "extract" the other.
But you can "guess" it algorithmically. for example:

A) make the mask completly "black": all pixels will be drawn (no transparency)

B) look the pixel of the image an guess a color you may use as a "transparent color". Create a mask that is "white" where the image has that color. (if the image is a drawing, you can use the topleft pixel as "background color")

C) Same as B, but consider transparent also colors that are "close" under a given approximation to the chosen color.

A is trivial, B is simple (just require a BitBlt of a color image into a monochrome bitmap) C requires more parsing of the picture.


这篇关于hbmMask& ICONINFO中的hbmColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆