D:\ahk1.0\Ahk1.1.ahk

/*
; 如果当前脚本没有以管理员权限运行,并且命令行参数中没有 /restart 选项,
; 则以管理员权限重新启动脚本,并添加 /restart 选项。这样可以确保脚本以管理员权限运行,同时避免无限循环重启。
if !A_IsAdmin && !RegExMatch(_:=DllCall("GetCommandLineW", "Str"), " /restart(?!\S)")
    RunWait % "*RunAs " RegExReplace(_, "^\"".*?\""\K|^\S*\K", " /restart")
F5 & 7::
run D:\ahk1.0\Lib\二维码.ahk
send, ^c
return
*/

F5 & 7::
run D:\ahk1.0\Lib\二维码.ahk
send, ^c
return
;ΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞ  F5 & 7  二维码  ΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞΞ 000010-1320

D:\ahk1.0\Lib\二维码.ahk

#NoEnv  
SetTitleMatchMode fast
Process,priority, , Realtime
#SingleInstance, Force
SetBatchLines, -1

START:
; 直接使用剪贴板内容,不需要 InputBox
test := clipboard

Kanji_encode(str)
{
    tmp := StrSplit(str)
    for k,v in tmp
    {
        c := Asc(v)
        If ((c >= 0x0001) && (c <= 0x007F))
            out .= v
        Else if (c > 0x07FF)
        {
            out .= Chr(0xE0 | ((c >> 12) & 0x0F))
            out .= Chr(0x80 | ((c >> 6) & 0x3F))
            out .= Chr(0x80 | ((c >> 0) & 0x3F))
        }
        Else
        {
            out .= Chr(0xC0 | ((c >> 6) & 0x1F))
            out .= Chr(0x80 | ((c >> 0) & 0x3F))
        }
    }
    Return out
}

MATRIX_TO_PRINT := BARCODER_GENERATE_QR_CODE(Kanji_encode(test))
if (MATRIX_TO_PRINT = 1)
{
	Msgbox, 0x10, Error, The input message is blank. Please input a message to succesfully generate a QR Code image.
	Goto START
}

If MATRIX_TO_PRINT between 1 and 7
{
	Msgbox, 0x10, Error, ERROR CODE: %MATRIX_TO_PRINT% `n`nERROR CODE TABLE:`n`n1 - Input message is blank.`n2 - The Choosen Code Mode cannot encode all the characters in the input message.`n3 - Choosen Code Mode does not correspond to one of the currently indexed code modes (Automatic, numeric, alphanumeric or byte).`n4 - The choosen forced QR Matrix version (size) cannot encode the entire input message using the choosen ECL Code_Mode. Try forcing a higher version or choosing automated version selection (parameter value 0).`n5 - The input message is exceeding the QR Code standards maximum length for the choosen ECL and Code Mode.`n6 - Choosen Error Correction Level does not correspond to one of the standard ECLs (L, M, Q and H).`n7 - Forced version does not correspond to one of the QR Code standards versions.
	Goto START
}

	; Start gdi+
	If !pToken := Gdip_Startup()
	{
		MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
		ExitApp
	}
 
	pBitmap := Gdip_CreateBitmap((MATRIX_TO_PRINT.MaxIndex() + 8) * 10, (MATRIX_TO_PRINT.MaxIndex() + 8) * 10) ; Adding 8 pixels to the width and height here as a "quiet zone" for the image. This serves to improve the printed code readability. QR Code specs require the quiet zones to surround the whole image and to be at least 4 modules wide (4 on each side = 8 total width added to the image). Don't forget to increase this number accordingly if you plan to change the pixel size of each module.
	G := Gdip_GraphicsFromImage(pBitmap)
	Gdip_SetSmoothingMode(pBitmap, 3)
	pBrush := Gdip_BrushCreateSolid(0xFFFFFFFF)
	Gdip_FillRectangle(G, pBrush, 0, 0, (MATRIX_TO_PRINT.MaxIndex() + 8) * 10, (MATRIX_TO_PRINT.MaxIndex() + 8) * 10) ; Same as above.
	Gdip_DeleteBrush(pBrush)

	Loop % MATRIX_TO_PRINT.MaxIndex() ; Acess the Rows of the Matrix
	{
		CURRENT_ROW := A_Index
		Loop % MATRIX_TO_PRINT[1].MaxIndex() ; Access the modules (Columns of the Rows).
		{
			CURRENT_COLUMN := A_Index
			If (MATRIX_TO_PRINT[CURRENT_ROW, A_Index] = 1)
			{
				;Gdip_SetPixel(pBitmap, A_Index + 3, CURRENT_ROW + 3, 0xFF000000) ; Adding 3 to the current column and row to skip the quiet zones.
				Loop 10
				{
					CURRENT_REDIMENSION_ROW := A_Index
					Loop 10
					{
						Gdip_SetPixel(pBitmap, (CURRENT_COLUMN * 10) + 29 + A_Index, (CURRENT_ROW * 10) + 29 + CURRENT_REDIMENSION_ROW, 0xFF000000)
					}
			}
		}
			If (MATRIX_TO_PRINT[CURRENT_ROW, A_Index] = 0) ; White pixels need some more attention too when doing multi pixelwide images.
			{
				Loop 10
				{
					CURRENT_REDIMENSION_ROW := A_Index
					Loop 10
					{
						Gdip_SetPixel(pBitmap, (CURRENT_COLUMN * 10) + 29 + A_Index, (CURRENT_ROW * 10) + 29 + CURRENT_REDIMENSION_ROW, 0xFFFFFFFF)
					}
				}
			}
		}
	}
	StringReplace, FILE_NAME_TO_USE, test, `" ; We can't use all the characters that byte mode can encode in the name of the file. So we are replacing them here (if they exist).
	FILE_PATH_AND_NAME := A_Desktop . "\" .  "1.png"
	Gdip_SaveBitmapToFile(pBitmap, FILE_PATH_AND_NAME)
	Gdip_DisposeImage(pBitmap)
	Gdip_DeleteGraphics(G)
	Gdip_Shutdown(pToken)
;MsgBox,0,Success,Created QR Code in file`n%FILE_PATH_AND_NAME%
;Goto START
run, C:\Users\z\Desktop\1.png
WinWait, ahk_class #32770
WinActivate
Sleep, 500
Run, nircmd win settopmost foreground 1
exitapp
Return
#Include D:\ahk1.0\Lib\BARCODER.ahk
#Include D:\ahk1.0\Lib\Gdip_All.ahk

; 设置模块大小
ModuleSize := 5  ; 每个模块的像素大小,减小到5以控制图像大小

; 创建二维码图像
pBitmap := Gdip_CreateBitmap((MATRIX_TO_PRINT.MaxIndex() + 8) * ModuleSize, (MATRIX_TO_PRINT.MaxIndex() + 8) * ModuleSize)
G := Gdip_GraphicsFromImage(pBitmap)
Gdip_SetSmoothingMode(pBitmap, 3)
pBrush := Gdip_BrushCreateSolid(0xFFFFFFFF)
Gdip_FillRectangle(G, pBrush, 0, 0, (MATRIX_TO_PRINT.MaxIndex() + 8) * ModuleSize, (MATRIX_TO_PRINT.MaxIndex() + 8) * ModuleSize)
Gdip_DeleteBrush(pBrush)

; 绘制二维码
Loop % MATRIX_TO_PRINT.MaxIndex() {
    CURRENT_ROW := A_Index
    Loop % MATRIX_TO_PRINT[1].MaxIndex() {
        CURRENT_COLUMN := A_Index
        pixelColor := (MATRIX_TO_PRINT[CURRENT_ROW, CURRENT_COLUMN] = 1) ? 0xFF000000 : 0xFFFFFFFF
        ; 批量绘制每个模块
        Gdip_FillRectangle(G, pixelColor, (CURRENT_COLUMN * ModuleSize) + 29, (CURRENT_ROW * ModuleSize) + 29, ModuleSize, ModuleSize)
    }
}
转载请注明出处