Hi guys,
I'm trying to create at runtime a simple 81x81 bitmap, and store it into a database using byte array...
This is the code i wrote
Public Sub CreateScreenShotRecord()
Try
Dim oMemoryStream As New System.IO.MemoryStream()
Dim objWB As New WriteableBitmap(81, 81)
Dim objTransform As New Windows.Media.TranslateTransform()
Dim objStreamSource As StreamResourceInfo
objStreamSource = Application.GetResourceStream(New Uri("Images\shot.jpg", UriKind.Relative))
objWB.LoadJpeg(objStreamSource.Stream)
objWB.Invalidate()
objTransform.X = 10
objTransform.Y = 10
objWB.Render(_objBlue, objTransform)
objWB.Invalidate()
objTransform = New Windows.Media.TranslateTransform()
objTransform.X = 20
objTransform.Y = 20
objWB.Render(_objFucsia, objTransform)
objTransform = New Windows.Media.TranslateTransform()
objTransform.X = 30
objTransform.Y = 30
objWB.Render(_objGreen, objTransform)
objWB.Invalidate()
objWB.SaveJpeg(oMemoryStream, objWB.PixelWidth, objWB.PixelHeight, 0, 100)
oMemoryStream.Seek(0, IO.SeekOrigin.Begin)
__y_ImageByteArray = oMemoryStream.GetBuffer
Catch ex As Exception
__y_ImageByteArray = Nothing
End Try
End Sub
_objBlue, _objGreen, _objFucsia are public images variables and __y_ImageByteArray is a public byte array
So the problem is...:::
when i call this sub, the first time i execute the sub, the result image (stored into the __y_ImageByteArray variable) is equal of the base image ...Uri("Images\shot.jpg"...without any other images rendered, but the second time i execute the sub the result image is correct...
I can't understand the problem, i think SaveJpeg is async operation, but i'm not able to understand if the SaveJpeg has finished to write the memory stream or not...
Sorry for my bad english!
Daniele
TNX in advance