Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
.gif and .jpeg support
#1
Might support png as well, haven't tested.

I followed JimCamels tutorial and thought it long winded and pointless. I looked around and found out how to load something as an image without using a picture box.

It's mostly just common sense, but I found code all over for it.

Code:
Function CreateSurfaceFromFile(DirectDraw As DirectDraw7, ByVal _
        FileName As String, SurfaceDesc As DDSURFACEDESC2) As _
        DirectDrawSurface7
  Dim Picture As StdPicture
  Dim width As Long
  Dim Height As Long
  Dim Surface As DirectDrawSurface7
  Dim hdcPicture As Long
  Dim hdcSurface As Long

  Set Picture = LoadPicture(FileName)

  width = CLng((Picture.width * 0.001) * 567 / _
          Screen.TwipsPerPixelX)
  Height = CLng((Picture.Height * 0.001) * 567 / _
          Screen.TwipsPerPixelY)

  With SurfaceDesc
    If .lFlags = 0 Then .lFlags = DDSD_CAPS
    .lFlags = .lFlags Or DDSD_WIDTH Or DDSD_HEIGHT
    If .ddsCaps.lCaps = 0 Then _
          .ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_VIDEOMEMORY
    If .lWidth = 0 Then .lWidth = width
    If .lHeight = 0 Then .lHeight = Height
  End With
  
  Set Surface = DirectDraw.CreateSurface(SurfaceDesc)

  hdcPicture = CreateCompatibleDC(0)

  SelectObject hdcPicture, Picture.Handle

  hdcSurface = Surface.GetDC

  StretchBlt hdcSurface, 0, 0, SurfaceDesc.lWidth, _
        SurfaceDesc.lHeight, hdcPicture, 0, 0, _
        width, Height, SRCCOPY

  Surface.ReleaseDC hdcSurface

  DeleteDC hdcPicture

  Set Picture = Nothing
  Set CreateSurfaceFromFile = Surface
  Set Surface = Nothing
End Function

Code:
Public Declare Function CreateCompatibleDC Lib "gdi32" ( _
      ByVal hdc As Long) As Long

Public Declare Function SelectObject Lib "gdi32" ( _
      ByVal hdc As Long, ByVal hObject As Long) As Long

Public Declare Function StretchBlt Lib "gdi32" ( _
      ByVal hdc As Long, ByVal x As Long, ByVal y As Long, _
      ByVal nWidth As Long, ByVal nHeight As Long, _
      ByVal hSrcDC As Long, ByVal xSrc As Long, _
      ByVal ySrc As Long, ByVal nSrcWidth As Long, _
      ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long

Public Declare Function DeleteDC Lib "gdi32" ( _
      ByVal hdc As Long) As Long
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#2
awesome, goin to test it later...
Reply
#3
JimCamel, now there's a name that goes a long way back.
Reply
#4
could always have

Code:
Dim pic as StdPicture

Set pic = loadpicture(app.path & "\Blabnla.jpg")

Savepicture pic, app.path & "\tmp"

Loadsurf app.path & "\tmp", pic 'Or what ever it is you do with loading a surface. I am also using pic because it has descriptions in it such as width/height. Not much data will be passed on through to the lordsurf sub AS pic does not contain the picture, only the handle number which is a reference to the spool.

kill app.path & "\tmp"

simplistic method. Might not be as good but....sure helps with minimal amount of lines

Make sure you grab the width/height etc Smile
Reply
#5
Verrigan Wrote:Just wanted to point out that the pictures are converted to bitmaps when the surface is created... No matter what format they are in.

If we are using .png files will it actually slow the client down at any point at all when it has to convert?
Reply
#6
in order to load/convert PNG files you must use external DLL calling. VB does not support the PNG format. Look about on the net... I dont really like the png format idea. Just use ZLib with bmp for the win.
Reply
#7
I gave up trying to find a method for .png. gif is smaller anyway.

faffing around with extrernal .dll files is pointless when there is a more optimised image file format.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#8
You guys that are going on about not being able to find .png format.. ^_^

its in the konfuze milestone source if you want it =P
Reply
#9
IMO png isnt worth it, bitmap format using zlib compression is way smaller than png. Although I like the idea of transparency capability, but again bitmap supports that to.

Of course, it could provide to be easier Tongue Who knows. Each to his own ^_^

But you could argue the process of changing PNG to BMP could be slower than just compress/uncompress. Especially on the scale size of the typical MS tileset. Such a pity, should break it up into smaller parts. IMO 128 x 128
Reply
#10
Well, I use .gif files because all my maps are pre-made. I have the entire map blted, then the tops of houses etc. blted above everything else (aka. fringe).

Means I'm not copying 900 different 32x32 blocks each loop.

I then save the attributes to a 'map' file.

Runs very nice.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#11
you should make an PNG support since its more compressed.

JPG gets blurry and GIF tends to loose color :\


-----------
EDIT: They HAD an PNG support tutorial on Elysium somewhere but I think its gone, but just FYI, the dll needed for PNG is 'PaintX.dll'
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)