@Diggsey,
Thanks for the reply. That is what I figured, I was just hoping I was wrong about that. Below is my contribution to the community for this problem: an ImageHelper class that has an ImageFromImage method. It takes two Basic2D.Image entities (Source and Destination) and coordinates within the source image that you want copied to the destination image.
@RanQor,
I haven't found a way to do that right now. You would need low-level access to the Image structure within DGDK.
Ok here is a listing of the ImageHelper class. Right now it has one structure (Position) that wraps the top, left, right, and bottom coordinates, a method (ImageFromImage) that will grab an image including alpha channel from a Basic2D.Image, and a helper function that will get the bit depth of the image and return the number of bytes for each pixel. It isn't really
Imports DarkGDK
Public Class ImageHelpers
Public Structure Position
Public Top As Integer
Public Left As Integer
Public Right As Integer
Public Bottom As Integer
Public Sub New(ByVal _Top As Integer, ByVal _Left As Integer, ByVal _Bottom As Integer, ByVal _Right As Integer)
Top = _Top
Left = _Left
Right = _Right
Bottom = _Bottom
End Sub
End Structure
Public Overloads Sub ImageFromImage(ByRef Source As Basic2D.Image, ByRef Destination As Basic2D.Image, ByVal ImagePosition As Position)
'put source image in memblock
Dim mbSrc As New DarkGDK.MemoryBlock(Source)
'Get info on source image
Dim Depth As Integer = ImageDepth(mbSrc) 'number of pixel bytes
Dim LineLength As Integer = Source.Width * Depth 'length in bytes of a row of pixels
'get info for destination image
Dim DestHeight As Integer = ImagePosition.Bottom - ImagePosition.Top
Dim DestWidth As Integer = ImagePosition.Right - ImagePosition.Left
Dim DestLineLength As Integer = DestWidth * Depth
'these will be helper variables for navigating the memblocks
Dim StartPos As Integer 'will be used to calculate starting position in source memblock image for each pixel row
Dim CopyTo As Integer 'calculate where in new memblock image to copy the current pixel row
'calculate the size of the destination memblock
Dim mbSize As Integer = (DestLineLength * DestHeight) + 12
'create destination memblock
Dim mbDst As New DarkGDK.MemoryBlock(mbSize)
'write the image header to destination memblock image
mbDst.WriteDWord(0, CUInt(DestWidth))
mbDst.WriteDWord(4, CUInt(DestHeight))
mbDst.WriteDWord(8, CUInt(Depth * 8))
'iterate through the number of pixel rows needed and copy to destination memblock image
For counter = 0 To (DestHeight - 1)
'calculate the starting position for current pixel row
StartPos = (12 + (ImagePosition.Left * Depth)) + ((counter + ImagePosition.Top) * LineLength)
'calculate the position to copy current pixel row to.
CopyTo = 12 + (counter * DestLineLength)
'copy the pixel row to destination memblock image
mbSrc.CopyTo(StartPos, mbDst, CopyTo, DestLineLength)
Next
'make the new image
Destination = mbDst.MakeImage()
'clean up
mbSrc.Delete()
mbDst.Delete()
End Sub
'Returns the number of bytes per pixel from a memblock image
Public Function ImageDepth(ByRef Source As DarkGDK.MemoryBlock) As Integer
'read the memblock and get the bit depth
Dim depth As UInteger = Source.ReadDWord(8)
'divide by number of bits in a byte and return the result
Return System.Math.Ceiling(CInt(depth) / 8)
End Function
End Class
Here is how you might use the class using the image I attached in my first post:
Dim SourceImage As New Basic2D.Image("button_play.png")
Dim DestinationImage As DarkGDK.Basic2D.Image
Dim ihelper As New ImageHelpers
DestinationImage = Nothing
ihelper.ImageFromImage(SourceImage, DestinationImage, New ImageHelpers.Position(9, 9, 140, 70))
Now you can use the Paste method from the destination image within the game loop to put the new image on the screen where ever you choose.
Design documents?!? What design documents??? I thought we were just going to wing it!!!