I have try to translate this code in 5.11.
That works, but i have just a part of the picture in the PBI created, and i not understand why
Code: Select all
Procedure WindowCallBack(WindowId, Message, lParam, wParam)
If Message = #WM_PAINT
StartDrawing(WindowOutput(0))
DrawImage(ImageID(1), 0, 0)
StopDrawing()
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
UsePNGImageEncoder()
UsePNGImageDecoder()
UseJPEGImageDecoder()
UseJPEGImageEncoder()
UseBriefLZPacker()
Structure myBITMAPINFO
bmiHeader.BITMAPINFOHEADER
bmiColors.RGBQUAD[1]
EndStructure
Structure RGB
v.l
EndStructure
Procedure CreateMask()
hDC = StartDrawing(ImageOutput(1))
main = CreateRectRgn_(0,0,0,0)
picl_X = ImageWidth(1)
picl_Y = ImageHeight(1)
mem = AllocateMemory(picl_X*picl_Y*4)
bmi.myBITMAPINFO
bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
bmi\bmiHeader\biWidth = picl_X
bmi\bmiHeader\biHeight = picl_Y
bmi\bmiHeader\biPlanes = 1
bmi\bmiHeader\biBitCount = 32
bmi\bmiHeader\biCompression = #BI_RGB
GetDIBits_(hDC,ImageID(1),1,picl_Y-1,mem,bmi,#DIB_RGB_COLORS)
*pixel.RGB = mem
trans.RGB
trans\v = *pixel\v
If Blue (trans\v)=255 And Green (trans\v)=0 And Red (trans\v)=0 : messag$= " -> Rouge"
ElseIf Blue (trans\v)=0 And Green (trans\v)=255 And Red (trans\v)=0 : messag$= " -> Vert"
ElseIf Blue (trans\v)=0 And Green (trans\v)=0 And Red (trans\v)=255 : messag$= " -> Bleu"
ElseIf Blue (trans\v)=255 And Green (trans\v)=255 And Red (trans\v)=255 : messag$= " -> Blanc"
ElseIf Blue (trans\v)=0 And Green (trans\v)=0 And Red (trans\v)=0 : messag$= " -> Noir"
EndIf
coulon = MessageRequester ( "Sélection de la couleur du masque" , "Couleur détectée : " + "Rouge : " + Str ( Blue (trans\v))+ " ; Vert : " + Str ( Green (trans\v))+ " ; Bleu : " + Str ( Red (trans\v))+messag$+ Chr (13)+ Chr (13)+ "Acceptez-vous cette couleur? (Oui : Utiliser la couleur ; Non : Ouvrir la palette de couleur)" , #PB_MessageRequester_YesNo )
If coulon<>6
trans\v = ColorRequester ()
trans\v = RGB ( Blue (trans\v), Green (trans\v), Red (trans\v))
EndIf
For ay=0 To picl_Y-2
For ax=0 To picl_X-1
If *pixel\v <> trans\v
sub = CreateRectRgn_(ax,picl_Y-ay-1,ax+1,picl_Y-ay-2)
CombineRgn_(main,main,sub,#RGN_OR)
DeleteObject_(sub)
EndIf
*pixel + 4
Next ax
Next ay
StopDrawing()
ProcedureReturn main
EndProcedure
File.s = OpenFileRequester("Open Bitmap","","Bitmap|*.bmp;*.png",0)
If File
Image = LoadImage(1, File)
w = ImageWidth(1)
h = ImageHeight(1)
ScreenX = GetSystemMetrics_(#SM_CXSCREEN)
ScreenY = GetSystemMetrics_(#SM_CYSCREEN)
HWnd = OpenWindow(0, screenx, screeny, w, h, "Mask-Image", #WS_POPUP)
Mask = CreateMask()
Oldsize = GetRegionData_(Mask, 0, 0)
*Source = AllocateMemory(Oldsize)
GetRegionData_(mask,oldsize,*Source)
*Target = AllocateMemory(Oldsize + 8)
;Newsize = PackMemory(*Source,*Target,Oldsize,9)
Newsize = CompressMemory(*Source, Oldsize, *Target, Oldsize + 8, #PB_Packer_BriefLZ)
Newfile.s = ReplaceString(GetFilePart(File), GetExtensionPart(File),"png")
SaveImage(1, Newfile, #PB_ImagePlugin_PNG)
Rest = Newsize % 4
NomFenetre.s = Left(GetFilePart(File),Len(GetFilePart(File)) - 4)
File = ReplaceString(GetFilePart(File),GetExtensionPart(File),"pbi")
If CreateFile(0, File)
WriteStringN(0,"UsePNGImageDecoder()")
WriteStringN(0,"UseBriefLZPacker()")
WriteStringN(0,"")
WriteStringN(0,"Procedure OpenMaskedWindow_" + NomFenetre + "(WinID, x, y, Title.s, imID)")
WriteStringN(0,"")
WriteStringN(0," Hwnd" + NomFenetre + " = OpenWindow(winID, GetSystemMetrics_(#SM_CXSCREEN), y, " + Str(w) + ", " + Str(h) + ", Title, #WS_POPUP)")
WriteStringN(0," Memhandle = GlobalAlloc_(#GMEM_MOVEABLE," + Str(Oldsize + 8) + ")")
WriteStringN(0," *Mem = GlobalLock_(Memhandle)")
;WriteStringN(0," UnpackMemory(?" + NomFenetre + "_Mask, *Mem)")
WriteStringN(0," UncompressMemory(?" + NomFenetre + "_Mask, " + Trim(Str(Newsize)) + ", *Mem," + Trim(Str(Oldsize)) + ")")
WriteStringN(0," Region = ExtCreateRegion_(0," + Str(Oldsize) + ", *Mem)")
WriteStringN(0," SetWindowRgn_(Hwnd" + NomFenetre + ", Region, #True)")
WriteStringN(0," Pic = CatchImage(imID,?" + NomFenetre +")")
WriteStringN(0," Brush = CreatePatternBrush_(Pic)")
WriteStringN(0," SetClassLong_(Hwnd" + NomFenetre + ", #GCL_HBRBACKGROUND, Brush)")
WriteStringN(0," ResizeWindow(WinID, x, y, #PB_Ignore, #PB_Ignore)")
WriteStringN(0," GlobalUnlock_(Memhandle)")
WriteStringN(0," GlobalFree_(Memhandle)")
WriteStringN(0," DeleteObject_(Region)")
WriteStringN(0," ProcedureReturn Hwnd" + NomFenetre)
WriteStringN(0,"")
WriteStringN(0," DataSection")
WriteStringN(0,"")
WriteStringN(0," " + Left(GetFilePart(File),Len(GetFilePart(File)) - 4)+":")
WriteStringN(0," ;***********")
WriteStringN(0,"")
WriteStringN(0," IncludeBinary " + Chr(34) + GetFilePart(Newfile) + Chr(34))
WriteStringN(0,"")
WriteStringN(0," " + Left(GetFilePart(File),Len(GetFilePart(File)) - 4) + "_Mask:")
WriteStringN(0," ;***********")
WriteStringN(0,"")
String.s = " Data.l "
For i = 0 To Newsize - 4 - Rest Step 4
String + "$" + LSet(Hex(PeekL(*Target + i)),8," ")
Count + 1
If Count = 10
Count = 0
WriteStringN(0, String)
String = " Data.l "
Else
String + ","
EndIf
Next i
If Count
String = Left(String, Len(String) - 1)
WriteStringN(0, String)
EndIf
WriteStringN(0,"")
WriteStringN(0," EndDataSection")
WriteStringN(0,"")
WriteStringN(0,"EndProcedure")
WriteStringN(0,"")
WriteStringN(0,"OpenMaskedWindow_PicText(WinID, x, y, Title.s, imID)")
WriteStringN(0,"MessageRequester(" + Chr(34) + Chr(34) + ", " + Chr(34) + "Escape pour sortir" + Chr(34) + ")")
WriteStringN(0,"Repeat : Evenement = WaitWindowEvent() :Until GetAsyncKeyState_(#VK_ESCAPE)")
CloseFile(0)
MessageRequester("Fichier .pbi créé!","Cliquez droit pour sortir.",0)
Else
MessageRequester("Error!", "Can't create '"+ ReplaceString(ReplaceString(file, GetFilePart(file),"MaskWindow_" + GetFilePart(file)),GetExtensionPart(file),"pbi'"),0)
EndIf
SetWindowRgn_(hwnd, mask, #True)
ResizeWindow(0,(screenx - w) / 2,(screeny - h) / 2, #PB_Ignore, #PB_Ignore)
SetWindowCallback(@WindowCallback())
Repeat
Select WaitWindowEvent()
Case #WM_LBUTTONDOWN
SendMessage_(hwnd,#WM_NCLBUTTONDOWN, #HTCAPTION,0)
Case #WM_RBUTTONDOWN
Quit=1
EndSelect
Until Quit=1
DeleteObject_(mask)
EndIf
End