Author Topic: Image problem in TinyPTC and it should work  (Read 10912 times)

0 Members and 1 Guest are viewing this topic.

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: Image problem in TinyPTC and it should work
« Reply #20 on: September 17, 2008 »
This what I have done...By putting background of drawimage2 and I dont know if I got it right.
I am really new to bitmap as If I have good understanding on how bitmap work in freebasic then it would be good for me to carry on next version of program I make in bitmap  ;)

can you please correct me   Clyde...  ;D

Code: [Select]
'-------------------------
' Â .: Bitmap Text :.
'         +
' Â .: Font Loader :.
'
' Â Using Bitmap 256 color
' Â palette image
'
' Â Whithout "DLL"s !!!
'
'-------------------------
'    by Rbraz 2006
'-------------------------

Option Explicit

'Windowed
#define PTC_WIN

'-------------------------------------
' Includes.
'-------------------------------------
#Include Once "tinyptc.bi"

'Screen constants
Const XRES=640          'Screen Width
Const YRES=480          'Screen Height
Const ARES=XRES * YRES  'Array Width

'BitmapFont constants
'BitmapFont const
Const FontW=32 'Font Width
Const FontH=32 'Font Height
Const FontL=60 'Number Of Letters In The Font

'Sub Routines
Declare Sub Draw_Text(byval message as string, byval xpos as integer, byval ypos as integer, byval inc as integer)
Declare Sub LoadAnimImage( stringFilename As string, byval FrameW, byval FrameH )
Declare Sub DrawImage(byval xpos as integer, byval ypos as integer, byval character as integer, byval FrameW as integer, byval FrameH as integer)

' I dont know if is need another drawimage for background
Declare Sub DrawImage2(stringFilename2 As string, byval FrameW, byval FrameH)

Declare Sub Load_Bitmap(byval filename as string)
Declare Sub ClearScreen()
Declare Sub FPS_Count()

'Variables
Dim Shared Buffer(ARES) as integer  'Tinyptc buffer
Dim Shared BitmapFont( FontW, FontH, FontL ) as integer ' Font buffer

'Bitmap (256 color palette) loader variables
ReDim Shared img_buffer(1) as ubyte                     ' Bitmap Image buffer
Dim Shared img_r(256), img_g(256), img_b(256) as ubyte  ' RGB color palette buffer
Dim Shared img_w, img_h as short                        ' Image Width / Height

'FPS Counter
Dim Shared iFPS, bSettime,iSecStart,iFrameCount,iFrameStart as integer

'Image file name
Dim file_name  as string
Dim file_name2 as string

file_name="Media\rsigold2.bmp"
file_name2="Media\BACKGROUND.bmp"

' Load Background
Load_Bitmap(file_name2)

'Load our bitmap font
LoadAnimImage( file_name,FontW,FontH )
 
'Open TinyPTC window
If( ptc_open( "Bitmap Text + Font Loader", XRES, YRES ) = 0 ) Then
    End -1
End if

'Main Loop
While Inkey$() <> Chr$( 27 )
 
      ClearScreen()
      drawimage2(file_name2,0,0)
      Draw_Text("FPS : "& iFPS,10,10,FontW)
 
      Draw_Text("BITMAP TEXT",132,150,FontW)
      Draw_Text("+",290,190,FontW)
      Draw_Text("FONT LOADER",132,230,FontW)
      Draw_Text("BY RBRAZ - 2006",90,320,FontW) 
 
      FPS_Count()
 
      Ptc_Update @Buffer(0)
Wend

'Close TinyPTC window
ptc_close()


'Draw text on screen
Sub Draw_Text(byval message as string, byval xpos as integer, byval ypos as integer, byval inc as integer)
    Dim a,i as integer
    Dim character as integer
    Dim char as string
    Dim alphatab as string

    For a=1 To Len(message)
        char = Mid$(message,a,1)
        character = Asc(char)-32  'Make sure that your font are into this range
        If (character>-1) And (character<FontL) then
            DrawImage(xpos,ypos,character,FontW,FontH)
        End If
        xpos=xpos+inc
    Next
End Sub

'Load frame images
Sub LoadAnimImage( Filename As string, byval FrameW, byval FrameH )
 Dim intX, intY, FrameWidth, FrameHeight, FrameNum
 Dim rect_x1, rect_x2, rect_y1, rect_y2, a, b
 Dim pixel
 
 'Load bitmap 256 color palette
 Load_Bitmap(Filename)

 FrameWidth   = img_w/FrameW
 FrameHeight  = img_h/FrameH
 
 FrameNum = 0
 rect_x1  = 0
 rect_x2  = FrameW
 rect_y1  = 0
 rect_y2  = FrameH
 
 For b = 0 to FrameHeight-1
     For a = 0 to FrameWidth-1
         For intY = rect_y1 to rect_y2-1
             For intX = rect_x1 to rect_x2-1
                 pixel= img_buffer( intX + ( intY * img_w ) )
                 BitmapFont( intX Mod FrameW, intY Mod FrameH, FrameNum ) = (img_r(pixel) Shl 16) Or (img_g(pixel) Shl 8 ) Or img_b(pixel)
             Next 
         Next
         rect_x1 = rect_x2
         rect_x2 = rect_x2 + FrameW
         FrameNum = FrameNum + 1
     Next 
     rect_x1 = 0
     rect_x2 = FrameW
     rect_y1 = rect_y2
     rect_y2 = rect_y2 + FrameH
 Next   
End Sub

'Draw image into Buffer
Sub DrawImage(byval xpos as integer, byval ypos as integer, byval character as integer, byval FrameW as integer, byval FrameH as integer)
Dim intX, intY As integer

For intY=0 to FrameH-1
    For intX=0 to FrameW-1
        if (xpos+intX) < (XRES - 1) and (xpos+intX) > 0 then
           Buffer( ((intY+ypos) * XRES) + (intX+xpos)) = BitmapFont(intX, intY, character)
        end if
    Next
Next

end sub

' DRAW BACKGROUND IMAGE
Sub DrawImage2(stringFilename2 As string, byval FrameW, byval FrameH)
 dim intx, intY As integer
 
  'Load bitmap 256 color palette
 Load_Bitmap(file_name2)

For intY=0 to FrameH-1
    For intX=0 to FrameW-1
        if (xpos+intX) < (XRES - 1) and (xpos+intX) > 0 then
           Buffer( ((intY+ypos) * XRES) + (intX+xpos)) = BitmapFont(intX, intY, character)
        end if
    Next
Next

end sub

'----------------------------------------
' For 256 color palette image only
'----------------------------------------
Sub Load_Bitmap(byval filename as string)
 Dim i,j,n,k,l,cnt as integer
 Dim Bmp_len, file as integer
 Dim byt as ubyte
 
 file = FreeFile
 
 OPEN filename FOR BINARY AS #file

 Get #file,19,img_w  ' bmp width
 Get #file,23,img_h  ' bmp height

 Bmp_len = img_w * img_h   ' Bmp size

 ReDim img_buffer(Bmp_len)
 Dim temp(Bmp_len)

 'Color palette
 cnt = 55
 For i = 0 To 255
     Get #file,cnt,byt
     img_b(i) = byt
     cnt+=1
     Get #file,cnt,byt
     img_g(i) = byt
     cnt+=1
     Get #file,cnt,byt
     img_r(i) = byt
     cnt+=2
 Next

 'Image pixels
 cnt = 1079
 For i = 0 To Bmp_len-1
     Get #file,cnt,byt
     img_buffer(i) = byt
     cnt+=1
 Next
 
 Close #file

 For i = -(Bmp_len-1) To 0
     temp(j) = img_buffer(Abs(i))
     j = j + 1
 Next

 'Flip image
  Do
    For j = 0 To img_w
        k = (j + (n * img_w))
        l = ((img_w - j) + (n * img_w))
        img_buffer(l) = temp(k)
    Next
    n = n + 1
    Loop Until n = img_h

End Sub

Sub ClearScreen() 
 Dim i as integer
 for i = 0 to ARES
     Buffer(i) = 0
 next
End Sub

Sub FPS_Count()
 If bSettime = 1 then
    iSecStart = Timer() * 1000.0
    iFrameStart = iFrameCount
    bSettime = 0
 EndIf
 
 If (Timer()*1000.0) >= iSecStart + 1000 then
    iFPS = iFrameCount - iFrameStart
    bSettime = 1
 EndIf
 iFrameCount = iFrameCount + 1
End Sub


 :cheers:
« Last Edit: September 17, 2008 by Hotshot »

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Image problem in TinyPTC and it should work
« Reply #21 on: September 17, 2008 »
Ah ok, I can see your getting side tracked.

I'll knock you up some code in a little while. And please compare the two versions to see what I have done with it thats different to yours. That way you'll get better at using 256 colour bitmaps.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Image problem in TinyPTC
« Reply #22 on: September 17, 2008 »
Ok, here is some code to draw single images, and animimages. The loading i've kept the same.

I havent tested the following code, as I dont have the images you are using to hand. And appologies if it looks messy. Btw, Im not a wizard to all things bitmapy.

Code: [Select]
Option Explicit

'Windowed
#define PTC_WIN

'-------------------------------------
' Includes.
'-------------------------------------
#Include Once "tinyptc.bi"

'
' Screen constants
'
Const XRES=640          'Screen Width
Const YRES=480          'Screen Height
Const ARES=XRES * YRES  'Array Width

'
' BitmapFont constants
'
Const FontW=32 'Font Width
Const FontH=32 'Font Height
Const FontL=60 'Number Of Letters In The Font

Const MAXIMAGES=2

'
' Sub Routines
'
Declare Sub BitmapText(byval message as string,_
                       byval xpos    as integer,_
                       byval ypos    as integer,_
                       byval inc     as integer)


Declare Sub LoadAnimImage( ByVal stringFilename As string,_
                           ByVal FrameW         As Integer,_
                           byval FrameH         As Integer,_
                           ByVal Num            As Integer=0)


Declare Sub DrawAnimImage(byval xpos as integer,_
                              byval ypos as integer,_
                              byval Frame as integer,_
                              byval FrameW as integer,_
                              byval FrameH as integer)



Declare Sub Load_Bitmap(byval filename as string, ByVal Num As Integer )
Declare Sub ClearScreen()

'
' Variables
'
Dim Shared Buffer(ARES) as integer  'Tinyptc buffer
Dim Shared BitmapFont( FontW, FontH, FontL ) as integer ' Font buffer
Dim Shared Background( XRES, YRES )

'
' Bitmap (256 color palette) loader variables
'
ReDim Shared img_buffer(1) as ubyte                     ' Bitmap Image buffer
Dim Shared As Ubyte img_r(256), img_g(256), img_b(256)   ' RGB color palette buffer
Dim Shared As Short img_w(MAXIMAGES), img_h(MAXIMAGES)                        ' Image Width / Height

'
' Image file names
'
Dim file_name  as string
Dim file_name2 as string

file_name="Media\rsigold2.bmp"
file_name2="Media\BACKGROUND.bmp"

'
' Load our images
'
LoadAnimImage( file_name,FontW,FontH )
LoadAnimImage( file_name2,XRES,YRES,1) ' presuming the background is the same size as the screen resolution,

'
' Open TinyPTC window
'
If( ptc_open( "Bitmap Text + Font Loader", XRES, YRES ) = 0 ) Then
    End -1
End if

'
' Main Loop
'
While Inkey$() <> Chr$( 27 )
 
      ClearScreen()
           
      DrawImage(0,0,1) ; Background Image

      BitmapText("BITMAP TEXT",132,150,FontW)
      BitmapText("+",290,190,FontW)
      BitmapText("FONT LOADER",132,230,FontW)
      BitmapText("BY RBRAZ - 2006",90,320,FontW) 
 
      Ptc_Update @Buffer(0)

Wend

'Close TinyPTC window
ptc_close()


'Draw text on screen
Sub BitmapText(byval message as string, byval xpos as integer, byval ypos as integer, byval inc as integer)
   
    Dim As Integer a,i
    Dim As Integer character
    Dim As String char
   
    For a=1 To Len(message)
        char = Mid$(message,a,1)
        character = Asc(char)-32  'Make sure that your font are into this range
        If (character>-1) And (character<FontL) then
            DrawAnimImage(xpos,ypos,character,FontW,FontH)
        End If
        xpos=xpos+inc
    Next
End Sub

'Load frame images
Sub LoadAnimImage( ByVal Filename As string, byval FrameW As Integer, byval FrameH as Integer, ByVal Num As Integer=0 )
 
    Dim intX, intY, FrameWidth, FrameHeight, FrameNum
    Dim rect_x1, rect_x2, rect_y1, rect_y2, a, b
    Dim pixel
 
    'Load bitmap 256 color palette
    Load_Bitmap(Filename)

    FrameWidth   = img_w(Num)/FrameW
    FrameHeight  = img_h(Num)/FrameH
 
    FrameNum = 0
    rect_x1  = 0
    rect_x2  = FrameW
    rect_y1  = 0
    rect_y2  = FrameH
 
    Dim As UInteger Col
 
    For b = 0 to FrameHeight-1
        For a = 0 to FrameWidth-1
            For intY = rect_y1 to rect_y2-1
                For intX = rect_x1 to rect_x2-1
                   
                    pixel= img_buffer( intX + ( intY * img_w(Num) ) )
                 
                    Col=(img_r(pixel) Shl 16 ) Or (img_g(pixel) Shl 8) Or (img_b(pixel)
                 
                    Select Case As Const Num
                 
                    Case 0
                    BitmapFont( intX Mod FrameW, intY Mod FrameH, FrameNum ) = Col
                 
                    Case 1
                    Background( intx Mod FrameW, inty Mod FrameH )= Col
                   
                    End Select
                 
                Next 
            Next
            rect_x1 = rect_x2
            rect_x2 = rect_x2 + FrameW
            FrameNum = FrameNum + 1
        Next 
        rect_x1 = 0
        rect_x2 = FrameW
        rect_y1 = rect_y2
        rect_y2 = rect_y2 + FrameH
    Next   

End Sub

Sub DrawAnimImage(byval xpos as integer,_
                  byval ypos as integer,_
                  byval Frame as integer,_
                  byval FrameW as integer,_
                  byval FrameH as integer)

    Dim As Integer intX, intY

    For intY=0 to FrameH-1
        For intX=0 to FrameW-1
            if (xpos+intX) < (XRES - 1) and (xpos+intX) > 0 then
                Buffer( ((intY+ypos) * XRES) + (intX+xpos)) = BitmapFont(intX, intY, Frame )
            end if
        Next
    Next

end sub


Sub DrawImage( ByVal XPos As Integer, ByVal YPos As Integer, ByVal Num As Integer=0 )
   
    Dim As Integer x,y
   
    For Y=0 to img_h( Num )-1
        For X=0 to img_w( Num )-1
            if (xpos+X) < (XRES - 1) and (xpos+X) > 0  then
               
                Select Case As Const Num
               
                Case 0
                Buffer( ((Y+ypos) * XRES) + (X+xpos)) = Background( X, Y )
               
                End Select
           
            end if
        Next
    Next
   
End Sub


'----------------------------------------
' For 256 color palette image only
'----------------------------------------
Sub Load_Bitmap(byval filename as string, ByVal Num As Integer )

    Dim i,j,n,k,l,cnt as integer
    Dim Bmp_len, file as integer
    Dim byt as ubyte
 
    file = FreeFile
 
    OPEN filename FOR BINARY AS #file

    Get #file,19,img_w(num)  ' bmp width
    Get #file,23,img_h(num)  ' bmp height

    Bmp_len = img_w(num) * img_h(num)   ' Bmp size

    ReDim img_buffer(Bmp_len)
    Dim temp(Bmp_len)

    'Color palette
    cnt = 55
    For i = 0 To 255
       
        Get #file,cnt,byt
        img_b(i) = byt
        cnt+=1
       
        Get #file,cnt,byt
        img_g(i) = byt
        cnt+=1
       
        Get #file,cnt,byt
        img_r(i) = byt
        cnt+=2
    Next

    'Image pixels
    cnt = 1079
    For i = 0 To Bmp_len-1
        Get #file,cnt,byt
        img_buffer(i) = byt
        cnt+=1
    Next
 
    Close #file

    For i = -(Bmp_len-1) To 0
        temp(j) = img_buffer(Abs(i))
        j = j + 1
    Next

    'Flip image
    Do
    For j = 0 To img_w(num)
        k = (j + (n * img_w(num)))
        l = ((img_w(num) - j) + (n * img_w(num)))
        img_buffer(l) = temp(k)
    Next
    n = n + 1
    Loop Until n = img_h(num)

End Sub

What ive done is use case, to choose which image array to contain the relevant data. Add more to taste. You could if you wanted have an array called ImageData( MaxWidth, MaxHeight, MaxImages ) if you catch my drift.

I hope that you can see and understand what the code is doing. And if for any reason the code doesnt work, let me know in a reply please dude, as like I say I havent fully tested it.

Cheers,
Clyde.
« Last Edit: September 18, 2008 by Clyde »
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: Image problem in TinyPTC and it should work
« Reply #23 on: September 20, 2008 »
Look at

' Load bitmap 256 color palette
 ' =============================================================
 ' Why Error? One things caught my eyes is
 ' Filename on here and other File_name as it going
 ' confuse me as I did put File_name on here but still get the error.
 ' =============================================================

Putting background and Fonts on screen isnt easy for freebasic but that will soon change once I understand on how it is work  8)

Code: [Select]
Option Explicit

'Windowed
#define PTC_WIN

'-------------------------------------
' Includes.
'-------------------------------------
#Include Once "tinyptc.bi"
'
' Screen constants
'
Const XRES=640          'Screen Width
Const YRES=480          'Screen Height
Const ARES=XRES * YRES  'Array Width
'
' BitmapFont constants
'
Const FontW=32 'Font Width
Const FontH=32 'Font Height
Const FontL=60 'Number Of Letters In The Font

Const MAXIMAGES=2

'
' Sub Routines
Declare Sub BitmapText(byval message as string,_
                       byval xpos    as integer,_
                       byval ypos    as integer,_
                       byval inc     as integer)

Declare Sub LoadAnimImage( ByVal stringFilename As string,_
                           ByVal FrameW         As Integer,_
                           byval FrameH         As Integer,_
                           ByVal Num            As Integer=0)

Declare Sub DrawAnimImage(byval xpos as integer,_
                              byval ypos as integer,_
                              byval Frame as integer,_
                              byval FrameW as integer,_
                              byval FrameH as integer)

Declare Sub Load_Bitmap(byval filename as string, ByVal Num As Integer )
Declare Sub ClearScreen()

 ' =========================================================================
' I HAVE ADD THAT ON HERE...SOMEONE TAP MY HEAD AND SAY WELLDONE BOY, KEEP GOING! LOL
 ' =========================================================================
declare Sub DrawImage( ByVal XPos As Integer, ByVal YPos As Integer, ByVal Num As Integer=0 )

'
' Variables
'
Dim Shared Buffer(ARES) as integer  'Tinyptc buffer
Dim Shared BitmapFont( FontW, FontH, FontL ) as integer ' Font buffer
Dim Shared Background( XRES, YRES )

'
' Bitmap (256 color palette) loader variables
'
ReDim Shared img_buffer(1) as ubyte                     ' Bitmap Image buffer
Dim Shared As Ubyte img_r(256), img_g(256), img_b(256)   ' RGB color palette buffer
Dim Shared As Short img_w(MAXIMAGES), img_h(MAXIMAGES)                        ' Image Width / Height

'
' Image file names
'
Dim file_name  as string
Dim file_name2 as string

file_name ="Media\rsigold2.bmp"
file_name2="Media\BACKGROUND.bmp"
'
' Load our images
'
LoadAnimImage( file_name,FontW,FontH )
LoadAnimImage( file_name2,XRES,YRES,1) ' presuming the background is the same size as the screen resolution,

'
' Open TinyPTC window
'
If( ptc_open( "Bitmap Text + Font Loader", XRES, YRES ) = 0 ) Then
    End -1
End if

' Main Loop
While Inkey$() <> Chr$( 27 )
 
      ClearScreen()
     
      ' Background Image     
      DrawImage(0,0,1)

      BitmapText("BITMAP TEXT",132,150,FontW)
      BitmapText("+",290,190,FontW)
      BitmapText("FONT LOADER",132,230,FontW)
      BitmapText("BY RBRAZ - 2006",90,320,FontW) 
 
      Ptc_Update @Buffer(0)

Wend

'Close TinyPTC window
ptc_close()

'Draw text on screen
Sub BitmapText(byval message as string, byval xpos as integer, byval ypos as integer, byval inc as integer)
   
    Dim As Integer a,i
    Dim As Integer character
    Dim As String char
   
    For a=1 To Len(message)
        char = Mid$(message,a,1)
        character = Asc(char)-32  'Make sure that your font are into this range
        If (character>-1) And (character<FontL) then
            DrawAnimImage(xpos,ypos,character,FontW,FontH)
        End If
        xpos=xpos+inc
    Next
End Sub

'Load frame images
Sub LoadAnimImage( ByVal Filename As string, byval FrameW As Integer, byval FrameH as Integer, ByVal Num As Integer=0 )
 
    Dim intX, intY, FrameWidth, FrameHeight, FrameNum
    Dim rect_x1, rect_x2, rect_y1, rect_y2, a, b
    Dim pixel
 
    ' Load bitmap 256 color palette
    ' =============================================================
    ' Why Error? One things caught my eyes is
    ' Filename on here and other File_name as it going
    ' confuse me as I did put File_name on here but still get the error.
    ' =============================================================
    Load_Bitmap(Filename)           

    FrameWidth   = img_w(Num)/FrameW
    FrameHeight  = img_h(Num)/FrameH
 
    FrameNum = 0
    rect_x1  = 0
    rect_x2  = FrameW
    rect_y1  = 0
    rect_y2  = FrameH
 
    Dim As UInteger Col
 
    For b = 0 to FrameHeight-1
        For a = 0 to FrameWidth-1
            For intY = rect_y1 to rect_y2-1
                For intX = rect_x1 to rect_x2-1
                   
                    pixel= img_buffer( intX + ( intY * img_w(Num) ) )
                 
                    Col=(img_r(pixel) Shl 16 ) Or (img_g(pixel) Shl 8) Or (img_b(pixel)
                 
                    Select Case As Const Num
                 
                    Case 0
                    BitmapFont( intX Mod FrameW, intY Mod FrameH, FrameNum ) = Col
                 
                    Case 1
                    Background( intx Mod FrameW, inty Mod FrameH )= Col
                   
                    End Select
                 
                Next 
            Next
            rect_x1 = rect_x2
            rect_x2 = rect_x2 + FrameW
            FrameNum = FrameNum + 1
        Next 
        rect_x1 = 0
        rect_x2 = FrameW
        rect_y1 = rect_y2
        rect_y2 = rect_y2 + FrameH
    Next   

End Sub

Sub DrawAnimImage(byval xpos as integer,_
                  byval ypos as integer,_
                  byval Frame as integer,_
                  byval FrameW as integer,_
                  byval FrameH as integer)

    Dim As Integer intX, intY

    For intY=0 to FrameH-1
        For intX=0 to FrameW-1
            if (xpos+intX) < (XRES - 1) and (xpos+intX) > 0 then
                Buffer( ((intY+ypos) * XRES) + (intX+xpos)) = BitmapFont(intX, intY, Frame )
            end if
        Next
    Next

end sub

Sub DrawImage( ByVal XPos As Integer, ByVal YPos As Integer, ByVal Num As Integer=0 )
   
    Dim As Integer x,y
   
    For Y=0 to img_h( Num )-1
        For X=0 to img_w( Num )-1
            if (xpos+X) < (XRES - 1) and (xpos+X) > 0  then
               
                Select Case As Const Num
               
                Case 0
                Buffer( ((Y+ypos) * XRES) + (X+xpos)) = Background( X, Y )
               
                End Select
           
            end if
        Next
    Next
   
End Sub

'----------------------------------------
' For 256 color palette image only
'----------------------------------------
Sub Load_Bitmap(byval filename as string, ByVal Num As Integer )

    Dim i,j,n,k,l,cnt as integer
    Dim Bmp_len, file as integer
    Dim byt as ubyte
 
    file = FreeFile
 
    OPEN filename FOR BINARY AS #file

    Get #file,19,img_w(num)  ' bmp width
    Get #file,23,img_h(num)  ' bmp height

    Bmp_len = img_w(num) * img_h(num)   ' Bmp size

    ReDim img_buffer(Bmp_len)
    Dim temp(Bmp_len)

    'Color palette
    cnt = 55
    For i = 0 To 255
       
        Get #file,cnt,byt
        img_b(i) = byt
        cnt+=1
       
        Get #file,cnt,byt
        img_g(i) = byt
        cnt+=1
       
        Get #file,cnt,byt
        img_r(i) = byt
        cnt+=2
    Next

    'Image pixels
    cnt = 1079
    For i = 0 To Bmp_len-1
        Get #file,cnt,byt
        img_buffer(i) = byt
        cnt+=1
    Next
 
    Close #file

    For i = -(Bmp_len-1) To 0
        temp(j) = img_buffer(Abs(i))
        j = j + 1
    Next

    'Flip image
    Do
    For j = 0 To img_w(num)
        k = (j + (n * img_w(num)))
        l = ((img_w(num) - j) + (n * img_w(num)))
        img_buffer(l) = temp(k)
    Next
    n = n + 1
    Loop Until n = img_h(num)

End Sub
« Last Edit: September 20, 2008 by Hotshot »

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Image problem in TinyPTC and it should work
« Reply #24 on: September 21, 2008 »
I attached one example for you, it's very simple.
If you need to add more images you will need to change this code, but first play with this one and try to understand how it works.

Challenge Trophies Won:

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: Image problem in TinyPTC and it should work
« Reply #25 on: September 22, 2008 »
Thank you RBZ.... ;D  and once I learn understand that then I will put more image in then post on here if goes wrong.

 :cheers: