動かしてみるには自分で素材を用意しないといけないものもあります。
その中でも、LoadDivGraphで読み込む画像は、区別するために指定された位置に合わせて多くのものを描かなければならず、大変です。
今回開発したツールは、分割後の画像のサイズと分割する数を指定することで、連番の入った画像を簡単に作成してくれます。
この「分割後の画像のサイズと分割する数」はLoadDivGraphの引数として指定するものなので、取得する手間はファイル名と同じくらいです。
複数枚読み込ませる場合でも区別できるよう、背景色、文字色、文字のフォントも指定できます。
ツールはHSPで作成し、Vectorで公開しました。
分割ダミー画像生成ツールの詳細情報 : Vector ソフトを探す!
ソースコードはこちらです。
► スポイラーを表示
#uselib "comdlg32.dll"
#func ChooseFont "ChooseFontA" var
#const CF_INITTOLOGFONTSTRUCT 0x00000040
#const CF_LIMITSIZE 0x00002000
#const CF_NOSCRIPTSEL 0x00800000
#const CF_NOVERTFONTS 0x01000000
#const FW_NORMAL 400
#const FW_BOLD 700
#func ChooseColor "ChooseColorA" var
#const CC_ANYCOLOR 0x00000100
#const CC_RGBINIT 0x00000001
#uselib "user32.dll"
#func PostMessage "PostMessageA" int, int, int, int
#const WM_APP 0x8000
#uselib "kernel32.dll"
#cfunc GetPrivateProfileInt "GetPrivateProfileIntA" str, str, int, str
#func GetPrivateProfileString "GetPrivateProfileStringA" str, str, str, var, int, str
#func WritePrivateProfileString "WritePrivateProfileStringA" str, str, str, str
inifile = ".\\dummyimage.ini"
; 個数
xnum = GetPrivateProfileInt("image", "xnum", 4, inifile)
ynum = GetPrivateProfileInt("image", "ynum", 4, inifile)
; 1個の大きさ
xsize = GetPrivateProfileInt("image", "xsize", 32, inifile)
ysize = GetPrivateProfileInt("image", "ysize", 32, inifile)
; 背景色
br = GetPrivateProfileInt("color", "back_r", 255, inifile)
bg = GetPrivateProfileInt("color", "back_g", 255, inifile)
bb = GetPrivateProfileInt("color", "back_b", 255, inifile)
; 文字色
tr = GetPrivateProfileInt("color", "text_r", 0, inifile)
tg = GetPrivateProfileInt("color", "text_g", 0, inifile)
tb = GetPrivateProfileInt("color", "text_b", 0, inifile)
; 文字フォント
sdim tfont, 64
tfont = "MS ゴシック"
GetPrivateProfileString "font", "name", tfont, tfont, varsize(tfont), inifile
tbold = GetPrivateProfileInt("font", "bold", 0, inifile)
titalic = GetPrivateProfileInt("font", "italic", 0, inifile)
; 生成後保存ダイアログを表示する
showsavedlg = GetPrivateProfileInt("save", "showsavedlg", 1, inifile)
; 作成した色
dim ccolors, 16
repeat 16
ccolors(cnt) = 0xffffff
loop
title "分割ダミー画像生成ツール 1.0.0"
objsize 50, 20
pos 0, 0 : mes " x方向の画像数"
pos 0, 20 : mes " y方向の画像数"
pos 140, 0 : input xnum, 100, 20
pos 140, 20 : input ynum, 100, 20
pos 0, 50 : mes "画像1枚のxサイズ"
pos 0, 70 : mes "画像1枚のyサイズ"
pos 140, 50 : input xsize, 100, 20
pos 140, 70 : input ysize, 100, 20
pos 0, 100 : mes " 背景色"
pos 0, 120 : mes " 文字色"
pos 0, 140 : mes " 文字フォント"
putx = 170
pos putx, 100 : mes "(R:" : putx += ginfo_mesx
pos putx, 100 : input br, 30, 20 : putx += 30 : bid = stat
pos putx, 100 : mes ", G:" : putx += ginfo_mesx
pos putx, 100 : input bg, 30, 20 : putx += 30
pos putx, 100 : mes ", B:" : putx += ginfo_mesx
pos putx, 100 : input bb, 30, 20 : putx += 30
pos putx, 100 : mes ") " : putx += ginfo_mesx
pos putx, 100 : button goto "選択", *colordlg_b
putx = 170
pos putx, 120 : mes "(R:" : putx += ginfo_mesx
pos putx, 120 : input tr, 30, 20 : putx += 30 : tid = stat
pos putx, 120 : mes ", G:" : putx += ginfo_mesx
pos putx, 120 : input tg, 30, 20 : putx += 30
pos putx, 120 : mes ", B:" : putx += ginfo_mesx
pos putx, 120 : input tb, 30, 20 : putx += 30
pos putx, 120 : mes ") " : putx += ginfo_mesx
pos putx, 120 : button goto "選択", *colordlg_t
pos 140, 140 : input tfont, (putx - 140) - 100, 20, 31 : fid = stat
objsize 50, 20
pos putx - 100, 140 : chkbox "太字", tbold
pos putx - 50, 140 : chkbox "斜体", titalic
pos putx, 140 : button goto "選択", *fontdlg
objsize putx + 50, 50
font "MS ゴシック", 30, 16
objmode 2, 1
pos 0, 170 : button goto "生成", *create_image
objmode 1, 1
sysfont
objsize putx + 50, 20
pos 0, 230
chkbox "生成後保存ダイアログを表示", showsavedlg
width putx + 50, 250
gsel 0, 1
onexit goto *close_result
; キーが押された時にすぐに値を取得すると値が古かったので、ワンクッション置く
onkey goto *send_message
oncmd goto *update_colors, WM_APP
*update_colors
gsel 0
if (0 255 : cr = 255
if cg 255 : cg = 255
if cb 255 : cb = 255
dim cc, 9
cc(0) = 4 * 9 ; lStructSize
cc(1) = hwnd ; hwndOwner
cc(3) = (cb > 8) & 0xff
cb = (cc(3) >> 16) & 0xff
cselected = 1
} else {
cselected = 0
}
return
*fontdlg
gsel 0
dim cf, 15
dim lf, 7 + 8 ; LF_FACESIZE = 32
lf(0) = 12 * 96 / 72 ; lfHeight
if tbold : lf(4) = FW_BOLD : else : lf(4) = FW_NORMAL ; lfWeight
if titalic : titalic_bool = 1 : else : titalic_bool = 0
poke lf, 4 * 5, titalic_bool ; lfItalic
slen = strlen(tfont)
if slen > 31 : slen = 31
memcpy lf, tfont, slen, 4 * 7, 0 ; lfFaceName
poke lf, 4 * 7 + slen, 0
cf(0) = 4 * 15 ; lStructSize
cf(1) = hwnd ; hwndOwner
cf(3) = varptr(lf) ; lpLogFont
cf(5) = CF_INITTOLOGFONTSTRUCT | CF_LIMITSIZE | CF_NOSCRIPTSEL | CF_NOVERTFONTS ; Flags
cf(13) = 12 ; nSizeMin
cf(14) = 12 ; nSizeMax
ChooseFont cf
if stat != 0 {
sdim newfont, 32
memcpy newfont, lf, 32, 0, 4 * 7
if lf(4) > FW_NORMAL : newbold = 1 : else : newbold = 0
if peek(lf, 4 * 5) : newitalic = 1 : else : newitalic = 0
objprm fid, newfont
objprm fid + 1, newbold
objprm fid + 2, newitalic
}
stop
*create_image
gsel 0
sdim invalid_messages, 64, 4
invalid_param = 0
if xnum 1 {
invalid_message = ""
repeat invalid_param
invalid_message += "・" + invalid_messages(cnt) + "\n"
loop
}
if invalid_param > 0 {
dialog invalid_message + "が不正です。\n正の整数を設定してください。", 1, "エラー"
stop
}
invalid_bcol = (br xsize) or (ginfo_mesy > ysize) : break
fright *= 2
loop
while fleft <= fright
center = int((fleft + fright) / 2)
font tfont, center, fstyle
mes str(xnum * ynum - 1)
if (ginfo_mesx <= xsize) and (ginfo_mesy <= ysize) {
fleft = center + 1
} else {
fright = center - 1
}
wend
color br, bg, bb
boxf 0, 0, xnum * xsize, ynum * ysize
font tfont, fleft - 1, fstyle
color tr, tg, tb
for i, 0, ynum
for j, 0, xnum
pos xsize * j, ysize * i
mes str(i * xnum + j) + " " ; 普通に出力すると斜体の右が切れる
next
next
redraw 1
if showsavedlg {
dialog "bmp", 17, "ビットマップファイル"
if stat == 1 {
filename = refstr
if getpath(filename, 2) == "" : filename += ".bmp"
bmpsave filename
}
}
stop
*close_result
if (wparam == 1) and (iparam == 0) {
gsel 1, -1
stop
}
; 設定を保存する
; 個数
WritePrivateProfileString "image", "xnum", str(xnum), inifile
WritePrivateProfileString "image", "ynum", str(ynum), inifile
; 1個の大きさ
WritePrivateProfileString "image", "xsize", str(xsize), inifile
WritePrivateProfileString "image", "ysize", str(ysize), inifile
; 背景色
WritePrivateProfileString "color", "back_r", str(br), inifile
WritePrivateProfileString "color", "back_g", str(bg), inifile
WritePrivateProfileString "color", "back_b", str(bb), inifile
; 文字色
WritePrivateProfileString "color", "text_r", str(tr), inifile
WritePrivateProfileString "color", "text_g", str(tg), inifile
WritePrivateProfileString "color", "text_b", str(tb), inifile
; 文字フォント
WritePrivateProfileString "font", "name", tfont, inifile
WritePrivateProfileString "font", "bold", str(tbold), inifile
WritePrivateProfileString "font", "italic", str(titalic), inifile
; 生成後保存ダイアログを表示する
WritePrivateProfileString "save", "showsavedlg", str(showsavedlg), inifile
end
オフトピック
「作品お披露目掲示板でやれ」ですか、わかりません。