|
|
2025/4/11(Fri) 13:32:13|NO.103347
Webサイト上のpng→ico変換ツールのように、hsp内でicoファイルを作成したいです。
例えば、下記のように、128*128, 64*64, 48*48, 32*32, 16*16の画像を、
マルチアイコンとして保存するにはどうしたらいいでしょうか?
buffer 1, 256, 256
color 255, 0, 0
font "", 100
mes "icon"
mx = ginfo_mesx
my = ginfo_mesy
color 0, 0, 0
boxf
color 0, 0, 255
boxf 2, 2, 252, 252
color 0, 255, 0
circle 16, 16, 236, 236
color 255, 0, 0
pos (ginfo_winx / 2) - (mx / 2), (ginfo_winy / 2) - (my / 2)
font "", 100
mes "icon"
screen 0, 128.0 * 2.4, 128
repeat 5
pos x, y
if (cnt = 0) {
sx = 128
sy = 128
iy = 64
} else {
sx = 16 * (5 - cnt)
sy = 16 * (5 - cnt)
iy = 128 - (16 * (4 - cnt))
}
gzoom sx, sy, 1, 0, 0, 256, 256, 1
x += sx
y = iy
await
loop
|
|
2025/4/13(Sun) 20:50:00|NO.103350
仕様書は公開されているので仕様書通りにバイナリ(アイコンファイル)を出力すればよいのでは?
…ということで作ってみた。これを実行ファイルにして投稿すれば今年も参加賞は頂きだっ!
// 実行時にicon.iconと128.png,64.png,48,png,32.png,16.pngファイルは
// 上書きされるので注意すること
// 仕様書https://ja.wikipedia.org/wiki/ICO_(%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%83%95%E3%82%A9%E3%83%BC%E3%83%9E%E3%83%83%E3%83%88)
#include "hspcv.as"
#define NUM 5
SIZE = 128, 64, 48, 32, 16
// アイコンの元となる画像の作成
alloc m_nIcon, 10240000;
sdim m_nData, 10240000, NUM;
dim m_nByte, NUM;
// 128x128以上の画像を読み込むこと
dialog "png|jpg", 16
if (stat == 0) {
end
}
fname = refstr;
cvload fname, 1
repeat NUM
cvcopy 0, 0, 0, 1
cvresize SIZE(cnt), SIZE(cnt), 1, CV_INTER_AREA
cvsave "" + SIZE(cnt) + ".png", 1
loop
// アイコンの作成
// アイコンデータ読み込み
repeat NUM
bload "" + SIZE(cnt) + ".png", m_nData(cnt)
m_nByte(cnt) = strsize;
loop
// ヘッダ 6byte
wpoke m_nIcon, 0, 0;
wpoke m_nIcon, 2, 1; // タイプ 1:ico 2:cur
wpoke m_nIcon, 4, 5; // 個数 128, 64, 48, 32, 16
// ディレクトリ 16byte x NUM
off = 6;
gdp = 6 + (16 * NUM);
repeat NUM
poke m_nIcon, off + 0, SIZE(cnt); // 幅
poke m_nIcon, off + 1, SIZE(cnt); // 高さ
poke m_nIcon, off + 2, 0; // パレット色数
poke m_nIcon, off + 3, 0; //
wpoke m_nIcon, off + 4, 0; // カラープレーン数
wpoke m_nIcon, off + 6, 0; // ピクセル毎のビット数
lpoke m_nIcon, off + 8, m_nByte(cnt); // 画像データのバイト数
lpoke m_nIcon, off + 12, gdp; // 画像データの位置
off += 16;
gdp += m_nByte(cnt);
loop
// アイコンデータ
repeat NUM
i = cnt;
repeat m_nByte(i)
n = peek(m_nData(i), cnt);
poke m_nIcon, off, n;
off++;
loop
loop
bsave "icon.ico", m_nIcon, gdp;
dialog "アイコンデータを出力しました"

| |
|
2025/4/20(Sun) 00:15:14|NO.103374
ありがとうございます、icoファイルの保存はできました。
透過情報を維持するにはどうしたらいいでしょうか?
a2d.hsp等を用いてみたのですがうまくいかず......
|
|
2025/4/20(Sun) 12:27:08|NO.103375
仕様書に書いてありますよ?
"PNGフォーマットの場合、PNGの持つ透明性データを直接利用する"
|
|
2025/4/20(Sun) 17:22:44|NO.103376
自分の環境ではa2d使用して透過PNGを指定すればアイコンも透過しますが、なんか違うんですかね?
#include "a2d.hsp"
SIZE = 128, 64, 48, 32, 16
NUM = length(SIZE)
dialog "png",16
if (stat == 0):end
fname = refstr
alCreateImageByFile 0, fname
sw = alGetWidth()
sh = alGetHeight()
repeat NUM
alCreateImage 1, SIZE(cnt), SIZE(cnt)
alStretchImageToImage 0, 1, 0, 0, sw, sh, 0, 0, SIZE(cnt), SIZE(cnt)
alSaveFile "" + SIZE(cnt) + ".png", "image/png", 0, 0, SIZE(cnt), SIZE(cnt)
loop
// アイコンの作成
// アイコンデータ読み込み
alloc m_nIcon, 10240000;
sdim m_nData, 10240000, NUM;
dim m_nByte, NUM;
repeat NUM
bload "" + SIZE(cnt) + ".png", m_nData(cnt)
m_nByte(cnt) = strsize;
loop
// ヘッダ 6byte
wpoke m_nIcon, 0, 0;
wpoke m_nIcon, 2, 1; // タイプ 1:ico 2:cur
wpoke m_nIcon, 4, NUM; // 個数 128, 64, 48, 32, 16
// ディレクトリ 16byte x NUM
off = 6;
gdp = 6 + (16 * NUM);
repeat NUM
poke m_nIcon, off + 0, SIZE(cnt); // 幅
poke m_nIcon, off + 1, SIZE(cnt); // 高さ
poke m_nIcon, off + 2, 0; // パレット色数
poke m_nIcon, off + 3, 0; //
wpoke m_nIcon, off + 4, 0; // カラープレーン数
wpoke m_nIcon, off + 6, 0; // ピクセル毎のビット数
lpoke m_nIcon, off + 8, m_nByte(cnt); // 画像データのバイト数
lpoke m_nIcon, off + 12, gdp; // 画像データの位置
off += 16;
gdp += m_nByte(cnt);
loop
// アイコンデータ
repeat NUM
i = cnt;
repeat m_nByte(i)
n = peek(m_nData(i), cnt);
poke m_nIcon, off, n;
off++;
loop
loop
bsave "icon.ico", m_nIcon, gdp;
dialog "アイコンデータを出力しました"

| |
|
2025/4/22(Tue) 11:14:38|NO.103378
すみません、アイコン作成部分ではない部分で透過情報が失われていたようでした。
改良したらうまくできました! ありがとうございました。
|
|