"bmp","jpg","jpeg","jpe","jfif","png","tif","tiff","gif","emf","wmf", "ico","rle","jp2","cur","tga","ppm","pgm"
Code: Select all
CompilerIf Not #PB_Compiler_Unicode
MessageRequester("Info","Please Compile in Unicode Mode", #PB_MessageRequester_Ok|#MB_ICONWARNING)
End
CompilerEndIf
UseJPEG2000ImageDecoder()
UseTGAImageDecoder()
#HDF_IMAGE = 2048
#HDI_IMAGE = 32
#Jpeg_Encoder = "image/jpeg"
#Gif_Encoder = "image/gif"
#Bmp_Encoder = "image/bmp"
#Png_Encoder = "image/png"
#Tif_Encoder = "image/tiff"
Global oldproc,Var.lv_item ,VarHeader.HDITEM,iinf.ICONINFO,header_h,Icwnd
Global *token, *Image, encoderCLSID.GUID,Image
Image = 0
Var\mask = #LVIF_IMAGE
VarHeader\mask = #HDI_IMAGE
VarHeader\fmt = #HDF_IMAGE
Structure PPMColor
r.a
g.a
b.a
EndStructure
Structure PGMColor
c.a
EndStructure
Structure RectF
x.f
y.f
width.f
height.f
EndStructure
Structure GdiplusStartupInput
GdiPlusVersion.i
*DebugEventCallback.DebugEventProc
SuppressBackgroundThread.i
SuppressExternalCodecs.i
EndStructure
Structure ImageCodecInfo
clsid.CLSID
formatID.GUID
*codecName
*dllName
*formatDescription
*filenameExtension
*mimeType
flags.l
version.l
sigCount.l
sigSize.l
*sigPattern.byte
*sigMask.byte
EndStructure
Procedure.i Gdiplus_New(version = 1, *hEventCB = #Null, Codecs = #False, bgThread = #False)
OpenLibrary(0, "gdiplus.dll")
Protected *token, input.GdiplusStartupInput
With input
\GdiPlusVersion = version
\DebugEventCallback = *hEventCB
\SuppressExternalCodecs = Codecs
\SuppressBackgroundThread = bgThread
EndWith
CallFunction(0, "GdiplusStartup", @*token, @input, #Null)
ProcedureReturn *token
EndProcedure
Procedure GetEncoderClsid(format$, *Clsid.CLSID)
Protected number , Size , *pImageCodecInfo.ImageCodecInfo, i, *memory
CallFunction(0,"GdipGetImageEncodersSize",@number, @Size)
If Size = 0
ProcedureReturn -1
EndIf
*memory = AllocateMemory(Size)
If *memory = #Null
ProcedureReturn -1
EndIf
*pImageCodecInfo = *memory
CallFunction(0,"GdipGetImageEncoders",number, Size, *pImageCodecInfo)
For i = 1 To number
If format$ = PeekS(*pImageCodecInfo\MimeType, -1, #PB_Unicode)
CopyMemory(*pImageCodecInfo\clsid, *Clsid, SizeOf(CLSID))
FreeMemory(*memory)
ProcedureReturn i
EndIf
*pImageCodecInfo + SizeOf(ImageCodecInfo)
Next
FreeMemory(*memory)
ProcedureReturn -1
EndProcedure
Procedure SetImg(gad,Row,Col,iImg)
Var\iItem = Row
Var\iSubItem = Col
Var\iImage = iImg ;Index of image in the list
SendMessage_(GadgetID(gad), #LVM_SETITEM, 0, @Var)
EndProcedure
Procedure SetHeaderImage(Header,Col)
VarHeader\iImage = 1
SendMessage_(Header , #HDM_SETITEM, Col, @VarHeader)
EndProcedure
Procedure Hheight(hWnd, uMsg, wParam, lParam)
Select uMsg
Case #HDM_LAYOUT
result = CallWindowProc_(oldproc, hwnd, uMsg, wParam, lParam)
*hdlayout.HD_LAYOUT = lParam
If *hdlayout\prc <> 0
*rect.RECT = *hdlayout\prc
*rect\top = header_h
EndIf
If *hdlayout\pwpos <> 0
*windowpos.WINDOWPOS = *hdlayout\pwpos
*windowpos\cy = header_h
EndIf
Default
result = CallWindowProc_(oldproc, hWnd, uMsg, wParam, lParam)
EndSelect
ProcedureReturn result
EndProcedure
Procedure LoadPPGM(Image,filename$)
Result = ReadFile(#PB_Any, filename$,#PB_Ascii)
If Result
If CreateImage(Image, 1, 1)
Format$ = ReadString(Result)
Dimensions$ = ReadString(Result)
If Val(StringField(Dimensions$, 1, " ")) = 0
Dimensions$ = ReadString(Result)
EndIf
w = Val(StringField(Dimensions$, 1, " "))
h = Val(StringField(Dimensions$, 2, " "))
ResizeImage(Image, w, h)
StartDrawing(ImageOutput(Image))
max = Val(ReadString(Result))
Select Format$
Case "P2"
Stringlen = Lof(Result) - Loc(Result)
content$ = Space(Stringlen*SizeOf(Character)+1)
Dim color.s(0)
ReadData(Result, @content$, Stringlen)
content$ = PeekS(@content$,-1,#PB_Ascii)
CreateRegularExpression(1, "\d+")
ExtractRegularExpression(1, content$, color())
For y = 0 To h - 1
For x = 0 To w - 1
pos = (y*w + x)*1
Plot(x, y,RGB(Val(color(pos)),Val(color(pos)),Val(color(pos))))
Next
Next
Case "P3"
Stringlen = Lof(Result) - Loc(Result)
content$ = Space(Stringlen*SizeOf(Character)+1)
Dim color.s(0)
ReadData(Result, @content$, Stringlen)
content$ = PeekS(@content$,-1,#PB_Ascii)
CreateRegularExpression(1, "\d+")
ExtractRegularExpression(1, content$, color())
For y = 0 To h - 1
For x = 0 To w - 1
pos = (y*w + x)*3
r=Val(color(pos))*255 / max
g=Val(color(pos+1))*255 / max
b=Val(color(pos+2))*255 / max
Plot(x, y, RGB(r,g,b))
Next
Next
Case "P5"
Bufferlen = Lof(Result) - Loc(Result)
*Buffer = AllocateMemory(Bufferlen)
ReadData(Result, *Buffer, Bufferlen)
For y = 0 To h - 1
For x = 0 To w - 1
*gray.PGMColor = pos + *Buffer
Plot(x, y,RGB(*gray\c,*gray\c,*gray\c))
pos + 1
Next
Next
Case "P6"
Bufferlen = Lof(Result) - Loc(Result)
*Buffer = AllocateMemory(Bufferlen)
ReadData(Result, *Buffer, Bufferlen)
For y = 0 To h - 1
For x = 0 To w - 1
*color.PPMColor = pos + *Buffer
Plot(x, y, RGB(*color\r*255 / max, *color\g*255 / max, *color\b*255 / max))
pos + 3
Next
Next
EndSelect
StopDrawing()
CloseFile(Result)
ProcedureReturn 1
EndIf
EndIf
EndProcedure
LoadFont(0,"Consolas",14)
OpenWindow(0,0,0,800,600,"Load any Image",#PB_Window_SystemMenu|#PB_Window_ScreenCentered| #PB_Window_MaximizeGadget| #PB_Window_SizeGadget)
ListIconGadget(0,10,10,780,500,"",0,#PB_ListIcon_MultiSelect |#PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines)
OpenWindow(1,0,0,600,400,"View Image",#PB_Window_ScreenCentered,WindowID(0)); |#PB_Window_Invisible)
ScrollAreaGadget(1,0,0,600,400,1920,1200)
ImageGadget(3,0,0,800,600,0)
CloseGadgetList()
UseGadgetList(WindowID(0))
ButtonGadget(10,10,560,50,20,"RUN")
SendMessage_(GadgetID(0), #LVM_SETEXTENDEDLISTVIEWSTYLE , #LVS_EX_SUBITEMIMAGES, #LVS_EX_SUBITEMIMAGES)
Header = SendMessage_(GadgetID(0), #LVM_GETHEADER, 0, 0)
SetGadgetFont(0,FontID(0))
AddGadgetColumn(0, 1, "Column 1",250)
AddGadgetColumn(0, 2, "Column 2",255)
AddGadgetColumn(0, 3, "Column 3",255)
ILwnd = ImageList_Create_(64,64,#ILC_COLOR32, 0, 200)
SendMessage_(GadgetID(0), #LVM_SETIMAGELIST, #LVSIL_SMALL, ILwnd)
For i = 0 To 200
AddGadgetItem(0, -1, Chr(10)+" "+Str(i)+Chr(10)+ " 222"+Chr(10)+" 333"+Chr(10)+ " 444")
Next
oldproc = SetWindowLongPtr_(Header, #GWL_WNDPROC, @Hheight())
Image = 1
header_h = 64
ColumnCount = SendMessage_(header, #HDM_GETITEMCOUNT, 0, 0)
Dim order(ColumnCount-1)
For c = 0 To ColumnCount-1
order(c) = c+1
Next
SendMessage_(GadgetID(0), #LVM_SETCOLUMNORDERARRAY, ColumnCount, @order())
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
CallFunction(0,"GdipDeleteGraphics",*Localgfx)
CallFunction(0,"GdiplusShutdown",*token)
CloseLibrary(0)
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 0
FileName$ = path$+GetGadgetItemText(0,GetGadgetState(0),1)
Ext$ = LCase(GetExtensionPart(FileName$))
Select Ext$
Case "bmp","jpg","jpeg","jpe","jfif","png","tif","tiff","gif","emf","wmf", "ico","rle"
CallFunction(0,"GdipCreateBitmapFromFile",@FileName$, @*image)
CallFunction(0,"GdipCreateHBITMAPFromBitmap",*Image, @HBITMAP,0)
SetGadgetState(3,HBITMAP)
Case "cur"
hCursor = LoadCursorFromFile_(@FileName$)
SetGadgetState(3,hCursor)
DeleteObject_(hCursor)
Case "jp2","tga"
If IsImage(0)
FreeImage(0)
EndIf
LoadImage(0,FileName$)
SetGadgetState(3,ImageID(0))
Case "ppm","pgm"
If IsImage(0)
FreeImage(0)
EndIf
LoadPPGM(0, FileName$)
SetGadgetState(3,ImageID(0))
EndSelect
Case 10
;FileName$ = OpenFileRequester("Open image", "", "All supported formats|*.bmp;*.gif;*.jpg;*.jpeg;*.jfif;*jpe;*.png|BMP image (*.bmp)|*.bmp|JPEG image (*.jpg;*.jpeg)|*.jpg;*.jpeg|GIF image (*.gif)|*.gif|PNG image (*.png)|*.png", 0)
;If FileName$
Path$ = PathRequester("Directory", "E:\")
If ExamineDirectory(0, Path$, "*.*")
*token = Gdiplus_New()
Repeat
NextEntry = NextDirectoryEntry(0)
FileName$ = DirectoryEntryName(0)
File$ = Path$+FileName$
Ext$ = LCase(GetExtensionPart(FileName$))
If FileSize(File$) > 0; And FileSize(Path$ + FileName$) < 100000
Select Ext$
Case "bmp","jpg","jpeg","jpe","jfif","png","tif","tiff","gif","emf","wmf","ico","rle"
If *token
CallFunction(0,"GdipCreateBitmapFromFile",@File$, @*image)
CallFunction(0,"GdipCreateHBITMAPFromBitmap", *Image,@HBITMAP,0)
If HBITMAP
imgH = CopyImage_(HBITMAP,#IMAGE_BITMAP,64,64,0)
DeleteObject_(HBITMAP)
iinf\hbmMask = imgH
iinf\hbmColor = imgH
Icwnd = CreateIconIndirect_(iinf)
item = ImageList_AddIcon_(ILwnd,Icwnd)
DeleteObject_(imgH)
DestroyIcon_(Icwnd)
SetGadgetItemText(0,item, FileName$,1)
CallFunction(0,"GdipDisposeImage",*image)
EndIf
EndIf
Case "cur"
hCursor = LoadCursorFromFile_(@File$)
If hCursor
item = ImageList_AddIcon_(ILwnd,hCursor)
DeleteObject_(hCursor)
SetGadgetItemText(0,item, FileName$,1)
EndIf
Case "jp2","tga"
LoadImage(0,File$)
If IsImage(0)
imgH = CopyImage_(ImageID(0),#IMAGE_BITMAP,64,64,0)
FreeImage(0)
iinf\hbmMask = imgH
iinf\hbmColor = imgH
Icwnd = CreateIconIndirect_(iinf)
item = ImageList_AddIcon_(ILwnd,Icwnd)
DeleteObject_(imgH)
DestroyIcon_(Icwnd)
SetGadgetItemText(0,item, FileName$,1)
EndIf
Case "ppm","pgm"
LoadPPGM(Image, File$)
If IsImage(Image)
imgH = CopyImage_(ImageID(image),#IMAGE_BITMAP,64,64,0)
FreeImage(image)
iinf\hbmMask = imgH
iinf\hbmColor = imgH
Icwnd = CreateIconIndirect_(iinf)
item = ImageList_AddIcon_(ILwnd,Icwnd)
DeleteObject_(imgH)
DestroyIcon_(Icwnd)
SetGadgetItemText(0,item, FileName$,1)
EndIf
EndSelect
EndIf
Until NextEntry = 0
EndIf
For x = 0 To item
SetImg(0,x,1,x)
Next
EndSelect
EndSelect
Until Quit = 1
End