File size: 14,749 Bytes
b1b3bae |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
'Copyright (C) 2002 Microsoft Corporation
'All rights reserved.
'
'THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
'EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
'MERCHANTIBILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'
'Date: June 2002
'Author: Duncan Mackenzie
'
'Requires the release version of .NET Framework
Imports System.Drawing
Imports System.IO
Imports System.Linq
Imports System.Xml.Linq
Namespace GraphicObjects
<Serializable()> Public MustInherit Class ImageGraphic
Inherits GraphicObject
Protected Sub New()
MyBase.New()
Me.ObjectType = Interfaces.Enums.GraphicObjects.ObjectType.GO_Image
End Sub
Public MustOverride Function GetImage() As Image
End Class
<Serializable()> Public Class LinkedImageGraphic
Inherits ImageGraphic
Protected m_ImagePath As String
<NonSerialized()> Protected m_Image As Image
#Region "Constructors"
Public Sub New()
MyBase.New()
Me.ObjectType = Interfaces.Enums.GraphicObjects.ObjectType.GO_Image
End Sub
Public Sub New(ByVal graphicPosition As Point, ByVal ImagePath As String)
Me.New()
Me.SetPosition(graphicPosition)
Me.ImagePath = ImagePath
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal ImagePath As String)
Me.New(New Point(posX, posY), ImagePath)
End Sub
Public Sub New(ByVal graphicPosition As Point, ByVal graphicSize As Size, ByVal ImagePath As String)
Me.New(graphicPosition, ImagePath)
Me.SetSize(graphicSize)
Me.AutoSize = False
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal graphicSize As Size, ByVal ImagePath As String)
Me.New(New Point(posX, posY), graphicSize, ImagePath)
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal width As Integer, ByVal height As Integer, ByVal ImagePath As String)
Me.New(New Point(posX, posY), New Size(width, height), ImagePath)
End Sub
Public Sub New(ByVal graphicPosition As Point, ByVal Rotation As Single, ByVal ImagePath As String)
Me.New(graphicPosition, ImagePath)
Me.Rotation = Rotation
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal Rotation As Single, ByVal ImagePath As String)
Me.New(New Point(posX, posY), Rotation, ImagePath)
End Sub
Public Sub New(ByVal graphicPosition As Point, ByVal graphicSize As Size, ByVal Rotation As Single, ByVal ImagePath As String)
Me.New(graphicPosition, Rotation, ImagePath)
Me.SetSize(graphicSize)
Me.AutoSize = False
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal graphicSize As Size, ByVal Rotation As Single, ByVal ImagePath As String)
Me.New(New Point(posX, posY), graphicSize, Rotation, ImagePath)
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal width As Integer, _
ByVal height As Integer, ByVal Rotation As Single, ByVal ImagePath As String)
Me.New(New Point(posX, posY), New Size(width, height), Rotation, ImagePath)
End Sub
#End Region
Public Overrides Function GetImage() As System.Drawing.Image
Try
If m_Image Is Nothing Then
m_Image = New Bitmap(m_ImagePath)
End If
Return m_Image
Catch ex As System.Exception
Return Nothing
End Try
End Function
Public Property ImagePath() As String
Get
Return m_ImagePath
End Get
Set(ByVal Value As String)
If Value <> m_ImagePath Then
m_ImagePath = Value
m_Image = Nothing
End If
End Set
End Property
Public Overrides Sub Draw(ByVal g As System.Drawing.Graphics)
Dim container As System.Drawing.Drawing2D.GraphicsContainer
Dim myMatrix As Drawing.Drawing2D.Matrix
container = g.BeginContainer()
myMatrix = g.Transform()
If m_Rotation <> 0 Then
myMatrix.RotateAt(m_Rotation, New PointF(X, Y), Drawing.Drawing2D.MatrixOrder.Append)
g.Transform = myMatrix
End If
Dim myImage As Image
myImage = Me.GetImage
g.EndContainer(container)
End Sub
End Class
<Serializable()> Public Class EmbeddedImageGraphic
Inherits ImageGraphic
Protected m_Image As Image
#Region "Constructors"
Public Sub New()
MyBase.New()
Me.ObjectType = Interfaces.Enums.GraphicObjects.ObjectType.GO_Image
End Sub
Public Sub New(ByVal graphicPosition As Point, ByVal startingImage As Image)
Me.New()
Me.SetPosition(graphicPosition)
Me.Image = startingImage
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal startingImage As Image)
Me.New(New Point(posX, posY), startingImage)
End Sub
Public Sub New(ByVal graphicPosition As Point, ByVal graphicSize As Size, ByVal startingImage As Image)
Me.New(graphicPosition, startingImage)
Me.SetSize(graphicSize)
Me.AutoSize = False
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal graphicSize As Size, ByVal startingImage As Image)
Me.New(New Point(posX, posY), graphicSize, startingImage)
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal width As Integer, ByVal height As Integer, ByVal startingImage As Image)
Me.New(New Point(posX, posY), New Size(width, height), startingImage)
End Sub
Public Sub New(ByVal graphicPosition As Point, ByVal Rotation As Single, ByVal startingImage As Image)
Me.New(graphicPosition, startingImage)
Me.Rotation = Rotation
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal Rotation As Single, ByVal startingImage As Image)
Me.New(New Point(posX, posY), Rotation, startingImage)
End Sub
Public Sub New(ByVal graphicPosition As Point, ByVal graphicSize As Size, ByVal Rotation As Single, ByVal startingImage As Image)
Me.New(graphicPosition, Rotation, startingImage)
Me.SetSize(graphicSize)
Me.AutoSize = False
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal graphicSize As Size, ByVal Rotation As Single, ByVal startingImage As Image)
Me.New(New Point(posX, posY), graphicSize, Rotation, startingImage)
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal width As Integer, _
ByVal height As Integer, ByVal Rotation As Single, ByVal startingImage As Image)
Me.New(New Point(posX, posY), New Size(width, height), Rotation, startingImage)
End Sub
#End Region
Public Property Image() As Image
Get
Return m_Image
End Get
Set(ByVal Value As Image)
m_Image = Value
End Set
End Property
Public Overrides Function GetImage() As System.Drawing.Image
Return Me.Image
End Function
Public Overrides Sub Draw(ByVal g As System.Drawing.Graphics)
Dim container As System.Drawing.Drawing2D.GraphicsContainer
Dim myMatrix As Drawing.Drawing2D.Matrix
container = g.BeginContainer()
myMatrix = g.Transform()
If m_Rotation <> 0 Then
myMatrix.RotateAt(m_Rotation, New PointF(X, Y), Drawing.Drawing2D.MatrixOrder.Append)
g.Transform = myMatrix
End If
g.EndContainer(container)
End Sub
Public Overrides Function LoadData(data As System.Collections.Generic.List(Of System.Xml.Linq.XElement)) As Boolean
MyBase.LoadData(data)
m_Image = Base64ToImage((From xel2 As XElement In data Select xel2 Where xel2.Name = "ImageData").Single)
Return True
End Function
Public Overrides Function SaveData() As System.Collections.Generic.List(Of System.Xml.Linq.XElement)
Dim elements As System.Collections.Generic.List(Of System.Xml.Linq.XElement) = MyBase.SaveData()
elements.Add(New XElement("ImageData", ImageToBase64(m_Image, Imaging.ImageFormat.Bmp)))
Return elements
End Function
Public Function ImageToBase64(image As Image, format As System.Drawing.Imaging.ImageFormat) As String
Using ms As New MemoryStream()
' Convert Image to byte[]
image.Save(ms, format)
Dim imageBytes As Byte() = ms.ToArray()
' Convert byte[] to Base64 String
Dim base64String As String = Convert.ToBase64String(imageBytes)
Return base64String
End Using
End Function
Public Function Base64ToImage(base64String As String) As Image
' Convert Base64 String to byte[]
Dim imageBytes As Byte() = Convert.FromBase64String(base64String)
Dim ms As New MemoryStream(imageBytes, 0, imageBytes.Length)
' Convert byte[] to Image
ms.Write(imageBytes, 0, imageBytes.Length)
Dim image__1 As Image = Image.FromStream(ms, True)
Return image__1
End Function
End Class
<Serializable()> Public Class EmbeddedAnimationGraphic
Inherits ImageGraphic
Protected m_Image As Image
#Region "Constructors"
Public Sub New()
MyBase.New()
Me.ObjectType = Interfaces.Enums.GraphicObjects.ObjectType.GO_Animation
End Sub
Public Sub New(ByVal graphicPosition As Point, ByVal startingImage As Image)
Me.New()
Me.SetPosition(graphicPosition)
Me.Image = startingImage
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal startingImage As Image)
Me.New(New Point(posX, posY), startingImage)
End Sub
Public Sub New(ByVal graphicPosition As Point, ByVal graphicSize As Size, ByVal startingImage As Image)
Me.New(graphicPosition, startingImage)
Me.SetSize(graphicSize)
Me.AutoSize = False
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal graphicSize As Size, ByVal startingImage As Image)
Me.New(New Point(posX, posY), graphicSize, startingImage)
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal width As Integer, ByVal height As Integer, ByVal startingImage As Image)
Me.New(New Point(posX, posY), New Size(width, height), startingImage)
End Sub
Public Sub New(ByVal graphicPosition As Point, ByVal Rotation As Single, ByVal startingImage As Image)
Me.New(graphicPosition, startingImage)
Me.Rotation = Rotation
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal Rotation As Single, ByVal startingImage As Image)
Me.New(New Point(posX, posY), Rotation, startingImage)
End Sub
Public Sub New(ByVal graphicPosition As Point, ByVal graphicSize As Size, ByVal Rotation As Single, ByVal startingImage As Image)
Me.New(graphicPosition, Rotation, startingImage)
Me.SetSize(graphicSize)
Me.AutoSize = False
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal graphicSize As Size, ByVal Rotation As Single, ByVal startingImage As Image)
Me.New(New Point(posX, posY), graphicSize, Rotation, startingImage)
End Sub
Public Sub New(ByVal posX As Integer, ByVal posY As Integer, ByVal width As Integer, _
ByVal height As Integer, ByVal Rotation As Single, ByVal startingImage As Image)
Me.New(New Point(posX, posY), New Size(width, height), Rotation, startingImage)
End Sub
#End Region
Public Property Image() As Image
Get
Return m_Image
End Get
Set(ByVal Value As Image)
m_Image = Value
End Set
End Property
Public Overrides Function GetImage() As System.Drawing.Image
Return Me.Image
End Function
Public Overrides Sub Draw(ByVal g As System.Drawing.Graphics)
Dim container As System.Drawing.Drawing2D.GraphicsContainer
Dim myMatrix As Drawing.Drawing2D.Matrix
container = g.BeginContainer()
myMatrix = g.Transform()
If m_Rotation <> 0 Then
myMatrix.RotateAt(m_Rotation, New PointF(X, Y), Drawing.Drawing2D.MatrixOrder.Append)
g.Transform = myMatrix
End If
If Not m_Image Is Nothing Then
'Begin the animation.
If Not currentlyAnimating Then
'Begin the animation only once.
ImageAnimator.Animate(m_Image, New EventHandler(AddressOf Me.OnFrameChanged))
currentlyAnimating = True
End If
'Get the next frame ready for rendering.
ImageAnimator.UpdateFrames()
'Draw the next frame in the animation.
g.DrawImage(m_Image, X, Y, Width, Height)
End If
g.EndContainer(container)
End Sub
Private Sub OnFrameChanged(ByVal o As Object, ByVal e As EventArgs)
'Force a call to the Paint event handler.
'Me.AdditionalInfo.Invalidate()
End Sub
Private currentlyAnimating As Boolean = False
End Class
End Namespace
|