Today I've been working on adding images to maps using the GdiPlusRasterLayer. As the images do not have world files associated with them, I am creating them on the fly by handling the StreamLoading event of the ImageSource. However, the StreamLoadingEventArgs does not indicate which stream is attempting to be loaded, so I am struggling trying to provide a generic event handler that allows me to dynamically load and display several images on a map.
Private _imageWorldFiles As New Dictionary(Of String, WorldFile)
...
Dim imageWorldFile = New WorldFile(worldExtent, imageWidth, imageHeight)
_imageWorldFiles.Add(Path, imageWorldFile)
AddHandler imageSource.StreamLoading, AddressOf MapImage_StreamLoading
...
Private Sub MapImage_StreamLoading(ByVal sender As Object, ByVal e As StreamLoadingEventArgs)
If e.AlternateStreamName.Contains(".JGW") Then
' Need the key here or some indication of which stream we're dealing with
Dim imageWorldFile = _imageWorldFiles("d:\_scratch\image.jpg")
Dim sb = New StringBuilder
sb.AppendLine(imageWorldFile.HorizontalResolution)
sb.AppendLine("0")
sb.AppendLine("0")
sb.AppendLine(imageWorldFile.VerticalResolution)
sb.AppendLine(imageWorldFile.UpperLeftX)
sb.AppendLine(imageWorldFile.UpperLeftY)
Dim byteArray = Encoding.ASCII.GetBytes(sb.ToString())
Dim stream = New MemoryStream(byteArray)
e.AlternateStream = stream
e.AlternateStreamName = "test.jgw"
End If
End Sub
Here I am trying to create a WorldFile object and store them in a dictionary. Then, in the StreamLoading event, I was going to retrieve the corresponding WorldFile from the dictionary and writing it to the stream. The problem is I have no way of retrieving the key for the current stream in the event handler.
Thanks for any help you can provide. Paul