Skip to content

Commit

Permalink
Feat: 支持保存带透明通道的 BMP 图片 (#154)
Browse files Browse the repository at this point in the history
* feat: 支持保存带透明通道的 BMP 图片
* adjust: 保存图像文件增加 withAlphaChannel 参数,用于指定是否保存透明通道,优先以 PNG 格式保存
* docs: 更新 savebmp(), saveimage(), savepng() 函数相关文档
* refactor: 移除不再使用的 saveimagetofile() 函数
  • Loading branch information
yixy-only authored Apr 25, 2024
1 parent 6e1a821 commit 43e3c72
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 91 deletions.
17 changes: 11 additions & 6 deletions include/ege.h
Original file line number Diff line number Diff line change
Expand Up @@ -1135,24 +1135,29 @@ const color_t* EGEAPI getbuffer(PCIMAGE pImg);

int EGEAPI resize_f(PIMAGE pDstImg, int width, int height);
int EGEAPI resize(PIMAGE pDstImg, int width, int height);

int EGEAPI getimage(PIMAGE pDstImg, int srcX, int srcY, int srcWidth, int srcHeight);
int EGEAPI getimage(PIMAGE pDstImg, PCIMAGE pSrcImg, int srcX, int srcY, int srcWidth, int srcHeight);
int EGEAPI getimage(PIMAGE pDstImg, LPCSTR pImgFile, int zoomWidth = 0, int zoomHeight = 0);
int EGEAPI getimage(PIMAGE pDstImg, LPCWSTR pImgFile, int zoomWidth = 0, int zoomHeight = 0);
int EGEAPI getimage(PIMAGE pDstImg, LPCSTR pResType, LPCSTR pResName, int zoomWidth = 0, int zoomHeight = 0);
int EGEAPI getimage(PIMAGE pDstImg, LPCWSTR pResType, LPCWSTR pResName, int zoomWidth = 0, int zoomHeight = 0);
int EGEAPI getimage_pngfile(PIMAGE pimg, LPCSTR filename);
int EGEAPI getimage_pngfile(PIMAGE pimg, LPCWSTR filename);

void EGEAPI putimage(int dstX, int dstY, PCIMAGE pSrcImg, DWORD dwRop = SRCCOPY);
void EGEAPI putimage(int dstX, int dstY, int dstWidth, int dstHeight, PCIMAGE pSrcImg, int srcX, int srcY, DWORD dwRop = SRCCOPY);
void EGEAPI putimage(int dstX, int dstY, int dstWidth, int dstHeight, PCIMAGE pSrcImg, int srcX, int srcY, int srcWidth, int srcHeight, DWORD dwRop = SRCCOPY);
void EGEAPI putimage(PIMAGE pDstImg, int dstX, int dstY, PCIMAGE pSrcImg, DWORD dwRop = SRCCOPY);
void EGEAPI putimage(PIMAGE pDstImg, int dstX, int dstY, int dstWidth, int dstHeight, PCIMAGE pSrcImg, int srcX, int srcY, DWORD dwRop = SRCCOPY);
void EGEAPI putimage(PIMAGE pDstImg, int dstX, int dstY, int dstWidth, int dstHeight, PCIMAGE pSrcImg, int srcX, int srcY, int srcWidth, int srcHeight, DWORD dwRop = SRCCOPY);
int EGEAPI saveimage(PCIMAGE pimg, LPCSTR filename);
int EGEAPI saveimage(PCIMAGE pimg, LPCWSTR filename);
int EGEAPI savepng(PCIMAGE pimg, LPCSTR filename, int bAlpha = 0);
int EGEAPI savepng(PCIMAGE pimg, LPCWSTR filename, int bAlpha = 0);
int EGEAPI getimage_pngfile(PIMAGE pimg, LPCSTR filename);
int EGEAPI getimage_pngfile(PIMAGE pimg, LPCWSTR filename);

int EGEAPI saveimage(PCIMAGE pimg, LPCSTR filename, bool withAlphaChannel = false);
int EGEAPI saveimage(PCIMAGE pimg, LPCWSTR filename, bool withAlphaChannel = false);
int EGEAPI savepng(PCIMAGE pimg, LPCSTR filename, bool withAlphaChannel = false);
int EGEAPI savepng(PCIMAGE pimg, LPCWSTR filename, bool withAlphaChannel = false);
int EGEAPI savebmp(PCIMAGE pimg, LPCSTR filename, bool withAlphaChannel = false);
int EGEAPI savebmp(PCIMAGE pimg, LPCWSTR filename, bool withAlphaChannel = false);

int EGEAPI putimage_transparent(
PIMAGE imgdest, // handle to dest
Expand Down
3 changes: 2 additions & 1 deletion man/api/img/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
<tr><td><a href="getbuffer.htm">getbuffer</a></td> <td>获取图像缓存区</td> <td align="center"></td></tr>

<tr><td><a href="saveimage.htm">saveimage</a></td> <td>保存图像</td> <td align="center"></td></tr>
<tr><td><a href="savepng.htm">savepng</a></td> <td>保存png图像</td> <td align="center"></td></tr>
<tr><td><a href="savepng.htm">savepng</a></td> <td>保存 PNG 图像</td> <td align="center"></td></tr>
<tr><td><a href="savebmp.htm">savebmp</a></td> <td>保存 BMP 图像</td> <td align="center">ege dev</td></tr>

<tr><td><a href="imagefilter_blurring.htm">imagefilter_blurring</a></td> <td>对指定图像进行图像模糊滤镜操作</td> <td align="center"></td></tr>
<tr><td><a href="rop.htm">三元光栅操作码</a></td> <td>介绍三元光栅操作码</td> <td align="center"></td></tr>
Expand Down
49 changes: 49 additions & 0 deletions man/api/img/savebmp.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>savebmp</title>
<link rel="stylesheet" type="text/css" href="../../css/index-table.css"/>
</head>
<body>

<pre><font size="4"><a href="../../index.htm">主页</a> / <a href="../index.htm">库函数目录</a> / <a href="index.htm">图像处理</a> / savebmp</font>
<font size="4">
<font size="4" color="#0000FF"><strong>功能:</strong></font>

将图像以 BMP 格式保存到文件中。(如果文件已存在,会覆盖原文件。)

<font size="4" color="#0000FF"><strong>声明:</strong></font>
<pre><font color=#0000FF>int </font><font color=#008080>savebmp</font>(
<font color=#800080>PCIMAGE </font> pimg,
<font color=#800080>LPCSTR </font> filename,
<font color=#0000FF>bool </font> withAlphaChannel = false
);

<font color=#0000FF>int </font><font color=#008080>savebmp</font>(
<font color=#800080>PCIMAGE </font> pimg,
<font color=#800080>LPCWSTR </font> filename,
<font color=#0000FF>bool </font> withAlphaChannel = false
);
</pre>
<font size="4" color="#0000FF"><strong>参数:</strong></font>
pimg
要保存的图像

filename
保存的图像文件名

withAlphaChannel
是否保存图像透明度通道,true: 保存, false: 不保存。默认为不保存。

<font size="4" color="#0000FF"><strong>返回值:</strong></font>

成功返回0,否则返回非0,若pimg传入错误,会引发运行时异常。

<font size="4" color="#0000FF"><strong>示例:</strong></font>

(无)

</font>
</pre>

</body>

15 changes: 10 additions & 5 deletions man/api/img/saveimage.htm
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
<font size="4">
<font size="4" color="#0000FF"><strong>功能:</strong></font>

将图像保存到文件中。目前只能保存成BMP或者PNG格式。
将图像保存到文件中。目前支持 BMP 和 PNG 格式。(如果文件已存在,会覆盖原文件。)

<font size="4" color="#0000FF"><strong>声明:</strong></font>
<pre><font color=#0000FF>int </font><font color=#008080>saveimage</font>(
<font color=#800080>PCIMAGE </font> pimg,
<font color=#800080>LPCSTR </font> filename
<font color=#800080>LPCSTR </font> filename,
<font color=#0000FF>bool </font> withAlphaChannel = false
);

<font color=#0000FF>int </font><font color=#008080>saveimage</font>(
<font color=#800080>PCIMAGE </font> pimg,
<font color=#800080>LPCWSTR </font> filename
<font color=#800080>LPCWSTR </font> filename,
<font color=#0000FF>bool </font> withAlphaChannel = false
);
</pre>
<font size="4" color="#0000FF"><strong>参数:</strong></font>
Expand All @@ -28,10 +30,13 @@

filename
保存的图像文件名
如果文件名以.bmp 结尾,则保存成 BMP 格式。
如果文件名以.png 结尾,则保存成 PNG 格式。
如果文件名以 .bmp 结尾,则保存成 BMP 格式。
如果文件名以 .png 结尾,则保存成 PNG 格式。
无后缀名或者其他后缀名,则保存成 PNG 格式。

withAlphaChannel
是否保存图像的透明通道。true: 保存, false: 不保存。默认为不保存。

<font size="4" color="#0000FF"><strong>返回值:</strong></font>

成功返回 grOk(0),否则返回非 0 值,若 pimg 传入错误,会引发运行时异常。
Expand Down
12 changes: 6 additions & 6 deletions man/api/img/savepng.htm
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
<font size="4">
<font size="4" color="#0000FF"><strong>功能:</strong></font>

将图像保存到文件中。
将图像以 PNG 格式保存到文件中。(如果文件已存在,会覆盖原文件。)

<font size="4" color="#0000FF"><strong>声明:</strong></font>
<pre><font color=#0000FF>int </font><font color=#008080>savepng</font>(
<font color=#800080>PCIMAGE </font> pimg,
<font color=#800080>LPCSTR </font> filename,
<font color=#0000FF>int </font> bAlpha = 0
<font color=#800080>LPCSTR </font> filename,
<font color=#0000FF>bool </font> withAlphaChannel = false
);

<font color=#0000FF>int </font><font color=#008080>savepng</font>(
<font color=#800080>PCIMAGE </font> pimg,
<font color=#800080>LPCWSTR </font> filename,
<font color=#0000FF>int </font> bAlpha = 0
<font color=#0000FF>bool </font> withAlphaChannel = false
);
</pre>
<font size="4" color="#0000FF"><strong>参数:</strong></font>
Expand All @@ -31,8 +31,8 @@
filename
保存的图像文件名

bAlpha
设置是否保存图像透明度通道,true: 保存, false: 不保存。默认为不保存。
withAlphaChannel
是否保存图像透明度通道,true: 保存, false: 不保存。默认为不保存。

<font size="4" color="#0000FF"><strong>返回值:</strong></font>

Expand Down
Loading

0 comments on commit 43e3c72

Please sign in to comment.