|
|
Rank: Advanced Member Groups: Member
Joined: 3/3/2008 Posts: 47 Points: 141
|
Hi, In the previous post http://forums.aurigma.com/yaf_postst3079_Draw-Frame-for-VObject.aspxwe were asking about adding frame onto ImageVObject. Actually we plan to go with the 3rd method - Create custom imagevobject that will draw the Rectangle... But, after several try, we couldn't get it done... Just wondering can we have a sample for it? Thanks.
|
|
Rank: Advanced Member Groups: Administration
, Member
Joined: 3/10/2008 Posts: 23 Points: 69
|
Ching Yen, Unfortunately ImageVObject does not support borders. But you can inherit your oun class, which supports borders. This is code sample of ImageWithBorder, which allow to draw picture with a border: Code:
Imports Aurigma.GraphicsMill.WinControls
Public Class ImageWithBorder
Inherits ImageVObject
Dim _bgFrame As RectangleVObject
Public Sub New(ByVal bitmap As Aurigma.GraphicsMill.Bitmap, ByVal scaleToActualSize As Boolean, ByVal x As Single, ByVal y As Single)
MyBase.New(bitmap, scaleToActualSize, x, y)
_bgFrame = New RectangleVObject(0, 0, 1, 1)
_bgFrame.Pen = New System.Drawing.Pen(Color.BurlyWood, 10)
_bgFrame.Pen.Alignment = Drawing2D.PenAlignment.Inset
_bgFrame.Brush = Nothing
End Sub
Public Overrides Sub Draw(ByVal renderingRect As System.Drawing.Rectangle, ByVal g As System.Drawing.Graphics, ByVal coordinateMapper As ICoordinateMapper)
Dim rectBounds As System.Drawing.RectangleF = _bgFrame.GetVObjectBounds()
Dim objBounds As System.Drawing.RectangleF = Me.GetVObjectBounds()
If Not rectBounds.Equals(objBounds) Then
Dim interim As System.Drawing.Pen = _bgFrame.Pen
_bgFrame = New RectangleVObject(objBounds)
_bgFrame.Transform = Me.Transform
_bgFrame.Pen = interim
_bgFrame.Brush = Nothing
End If
MyBase.Draw(renderingRect, g, coordinateMapper)
_bgFrame.Transform = Me.Transform
_bgFrame.Draw(renderingRect, g, coordinateMapper)
End Sub
Public Property BackgroundPen() As System.Drawing.Pen
Get
Return _bgFrame.Pen
End Get
Set(ByVal Value As System.Drawing.Pen)
_bgFrame.Pen = Value
End Set
End Property
End Class
Now you can change borger of image. This sample demonstrates how to use ImageWithBorder class: Code:
Dim bt As New Aurigma.GraphicsMill.Bitmap("image.jpg")
Dim newImage As New ImageWithFrame(bt, False, 0, 0)
Me._multiLayerViewer.CurrentLayer.VObjects.Add(newImage)
Best regards, Tamila Ashrafova Aurigma Support Team
|
|
Rank: Advanced Member Groups: Member
Joined: 3/3/2008 Posts: 47 Points: 141
|
Hi, Thanks for the great code !! But, here comes the problem and perhaps you could give some hints on how to solve it... Please check on the attachment File Attachment(s):
FrameIssue.jpg (333kb) downloaded 7 time(s).
|
|
Rank: Advanced Member Groups: Administration
, Member
Joined: 3/10/2008 Posts: 23 Points: 69
|
Hi, To solve this problem you should override two methods GetVObjectBounds() and GetTransformedVObjectBounds() in ImageWithBorder class. For example: Code:
Public Sub UpdateFrame()
Dim rectBounds As System.Drawing.RectangleF = _bgFrame.GetVObjectBounds()
Dim objBounds As System.Drawing.RectangleF = MyBase.GetVObjectBounds()
If Not rectBounds.Equals(objBounds) Then
Dim interim As System.Drawing.Pen = _bgFrame.Pen
_bgFrame = New RectangleVObject(objBounds)
_bgFrame.Transform = Me.Transform
_bgFrame.Pen = interim
_bgFrame.Brush = Nothing
End If
End Sub
Public Overrides Sub Draw(ByVal renderingRect As System.Drawing.Rectangle, ByVal g As System.Drawing.Graphics, ByVal coordinateMapper As ICoordinateMapper)
MyBase.Draw(renderingRect, g, coordinateMapper)
UpdateFrame()
_bgFrame.Transform = Me.Transform
_bgFrame.Draw(renderingRect, g, coordinateMapper)
End Sub
Public Overrides Function GetVObjectBounds() As System.Drawing.RectangleF
UpdateFrame()
Return System.Drawing.RectangleF.Union(MyBase.GetVObjectBounds(), _bgFrame.GetVObjectBounds)
End Function
Public Overrides Function GetTransformedVObjectBounds() As System.Drawing.RectangleF
UpdateFrame()
Return System.Drawing.RectangleF.Union(MyBase.GetTransformedVObjectBounds(), _bgFrame.GetVObjectBounds)
End Function
Best regards, Tamila Ashrafova Aurigma Support Team
|
|
|
Guest |