I try to Fill Image into Round Corner Rectangle... I researched internet Found some codes and Modified. I get what I want in PictureBoX FillPath.
Only diffences is ;
in PictureBox
Dim grpX As Graphics = PictureBox1.CreateGraphics
and in PrintDocument
Dim grpX As Graphics = e.Graphics
other all Codes are same. But in PictureBox İmage fit Perfectly. otherside in PrintDocument image only fill a place as Rectangle size.
How can I fill Rectangle in PrintDocument as Filled in PictureBox ?
What I have tried:
Public Function createRoundRect(ByVal R As Rectangle, ByVal radius As Integer) As GraphicsPath
Dim gp As New GraphicsPath()
Dim x As Integer, y As Integer, w As Integer, h As Integer
x = R.X
y = R.Y
w = R.Width
h = R.Height
If radius = 0 Then
gp.AddRectangle(New Rectangle(x, y, w, h))
Else
gp.AddLine(x + radius, y, x + w - radius, y)
gp.AddArc(x + w - radius, y, radius, radius, 270, 90)
gp.AddLine(x + w, y + radius, x + w, y + h - radius)
gp.AddArc(x + w - radius, y + h - radius, radius, radius, 0, 90)
gp.AddLine(x + w - radius, y + h, x + radius, y + h)
gp.AddArc(x, y + h - radius, radius, radius, 90, 90)
gp.AddLine(x, y + h - radius, x, y + radius)
gp.AddArc(x, y, radius, radius, 180, 90)
gp.CloseFigure()
End If
Return gp
End Function
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Dim newImage As Image = Drawing.Image.FromFile("C:\Users\Yaman\Desktop\Frames\384.jpg")
Dim imaj As Bitmap = New Bitmap("C:\Users\Yaman\Desktop\Frames\384.jpg")
Dim grpX As Graphics = PictureBox1.CreateGraphics
Dim rectX As Rectangle = New Rectangle(CDec(10), CDec(10), CDec(200), CDec(100))
Dim tg As Graphics = Graphics.FromImage(imaj)
tg.SmoothingMode = SmoothingMode.AntiAlias
grpX.SmoothingMode = SmoothingMode.AntiAlias
tg.DrawImage(newImage, CDec(10), CDec(10), CDec(200), CDec(100))
Dim TBrush As New TextureBrush(imaj)
Dim gp As New GraphicsPath
gp = createRoundRect(rectX, 12)
grpX.FillPath(TBrush, gp)
End Sub
Private Sub PrintDocument2_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument2.PrintPage
Dim newImage As Image = Drawing.Image.FromFile("C:\Users\Yaman\Desktop\Frames\384.jpg")
Dim imaj As Bitmap = New Bitmap("C:\Users\Yaman\Desktop\Frames\384.jpg")
Dim grpX As Graphics = e.Graphics
Dim rectX As Rectangle = New Rectangle(CDec(10), CDec(10), CDec(200), CDec(100))
Dim tg As Graphics = Graphics.FromImage(imaj)
tg.SmoothingMode = SmoothingMode.AntiAlias
grpX.SmoothingMode = SmoothingMode.AntiAlias
tg.DrawImage(newImage, CDec(10), CDec(10), CDec(200), CDec(100))
Dim TBrush As New TextureBrush(imaj)
Dim gp As New GraphicsPath
gp = createRoundRect(rectX, 12)
grpX.FillPath(TBrush, gp)
End Sub