Is it possible to add an outline, one that continues to expand outwards from the text?
Ie: the outside stroke from Photoshop is what I am looking for
I have found a way to have the outline go inside the text, but it is not what I am looking for.
I've looked around, but I haven't been able to find anyone on google who wanted an outter outline.
Thanks
Current inner outline:
Dim grp As Graphics = e.Graphics
Dim gp As New Drawing2D.GraphicsPath
Dim useFont As Font = New Font("Impact", 60, FontStyle.Regular)
grp.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
grp.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
gp.AddString("3000", useFont.FontFamily, FontStyle.Regular, 60, New Point(0, 0), StringFormat.GenericTypographic)
useFont.Dispose()
Dim orangeBrush As New SolidBrush(Color.FromArgb(226, 149, 0))
grp.FillPath(orangeBrush, gp)
'This is the stroke below
Dim blackpen As New Pen(Color.Black, 2)
grp.DrawPath(blackpen, gp)
gp.Dispose()
If you reverse the order in which you drawpath and fillpath you can get a outside border for your text.
Related
I drew an ellipse/circle with Graphics. It is the right size when I am in the WYSIWYG editor. However, when I run the program, the circle is larger.
correct sized circle in editor
too large sized circle
The "too large sized circle" is also of lower resolution and has jagged edges.
How do I make it the same size?
Protected Overrides Sub OnPaint(
ByVal pEvent _
As PaintEventArgs)
Me.Size = New Size(heightWidth, heightWidth)
'MyBase.OnPaint(pEvent)
Dim CenterCircle _
As New Rectangle(0, 0, heightWidth, heightWidth)
Dim colorBigCircle As Color = Color.FromArgb(218, 227, 243)
Dim colorSmallCircle As Color = Color.FromArgb(67, 99, 155)
pEvent.Graphics.FillEllipse(
New SolidBrush(
colorBigCircle
),
CenterCircle)
pEvent.Graphics.DrawEllipse(
New Pen(
colorSmallCircle, 3
),
CenterCircle)
The "too large sized circle" is also of lower resolution and has jagged edges.
pEvent.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
Setting the size of the form in the paint event is a big no-no. Either set the form's dimensions in the designer with a form border that isn't sizable, or set the form's MinimumSize and MaximumSize to the same dimension.
You should dispose of your drawing objects. Setting the SmoothingMode will fix the jagged edges of the circle. Your paint code should look something like this:
Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
Dim centerCircle As New Rectangle(0, 0, Me.ClientSize.Width, Me.ClientSize.Height)
Dim colorBigCircle As Color = Color.FromArgb(218, 227, 243)
Dim colorSmallCircle As Color = Color.FromArgb(67, 99, 155)
Using br As New SolidBrush(colorBigCircle)
e.Graphics.FillEllipse(br, centerCircle)
End Using
Using p As New Pen(colorSmallCircle, 3) With {.Alignment = PenAlignment.Inset}
e.Graphics.DrawEllipse(p, centerCircle)
End Using
End Sub
I'm drawing a 2d grid of hexagons using the DrawPolygon function. Works great, but I'm trying to figure out how to fill them with a certain color. It would appear the FillEllipse function is only meant for rectangles. Is there something I could use to fill shapes made with DrawPolygon? Please note, the below code includes a function I'm too lazy to include called CreateHex, which passes 2 coordinates (x and y of course) which it uses to calculate the 6 points which CreateHex uses to return the 6 points needed for the Hexagon. Here's my code:
Dim myPen As New Pen(Color.Black)
Dim PicGraphics As Graphics = Graphics.FromImage(bmp)
Dim DrawFont As New Font("Arial", SizeSide / 3)
Dim drawFormat As New StringFormat
Dim drawBrush As New SolidBrush(Color.Black)
For lc = 1 To ColNum
For lc2 = 1 To RowNum
PicGraphics.DrawPolygon(myPen, CreateHex(lc, lc2))
PicGraphics.FillEllipse(New SolidBrush(Color.Red), CreateHex(lc, lc2)) ' <---- this doesn't work.
Next
Next
If I comment out the FillEllipse statement, it draws the polygons normally. But if its uncommented, it will draw nothing at all. Anyone know of a solution?
I'm working on making a paint-esq image manipulator in VB.Net, and I'm still new to vb. I want the user to be able to upload an image and make adjustments to it, such as adding lines and text. I also want the user to be able to transfer the drawings and text they added to a different baseimage. For example, if the user draws a dog on top of a picture of a park, they can change it so the dog is on a street instead.
I've been messing with the idea of loading the image as the picturebox.backgroundImage, but running into difficulties changing the backgroundImage without reseting the drawings and with croping the image. I've also been dabling in having two pictureboxes with the one on top for drawings, but I'm running into transparency and cropping issues
Here is the code I'm using to establish my picturebox by setting the base image as .backgroundImage
Private Sub LoadImage(thisImage As Image)
'we set the picturebox size according to image, we can get image width and height with the help of Image.Width and Image.height properties.
img.BackgroundImage = thisImage 'c'
img.Image = New Bitmap(thisImage.Width, thisImage.Height) 'c'
img.BorderStyle = BorderStyle.FixedSingle
End Sub
example of the image maniputlation
Private Sub ButtonDone_Click(sender As Object, e As EventArgs) Handles ButtonDone.Click, DoneToolStripMenuItem.Click
Cursor = Cursors.Default
Select Case LCase(stateFlag)
Case "header"
'Reset stuff back to normal
ButtonHeader.Text = "Header"
stateFlag = ""
Cancel_Button.Enabled = False
'set up space to draw on the image
Dim newBm As New Bitmap(img.Image.Width, img.Image.Height)
' First we define a rectangle with the help of already calculated points
Dim newGraphics As Graphics = Graphics.FromImage(newBM) ' create graphics
newGraphics.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
newGraphics.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
newGraphics.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
'set image attributes
newGraphics.DrawImage(img.Image, New Rectangle(0, 0, img.Image.Width + 1, img.Image.Height + 1), _
0, 0, img.Image.Width + 1, img.Image.Height + 1, GraphicsUnit.Pixel)
'Draw Edges for header
newGraphics.DrawLine(Pens.Black, startPoint.X, borderSize - 20, startPoint.X, borderSize - 50)
newGraphics.DrawLine(Pens.Black, endPoint.X, borderSize - 20, endPoint.X, borderSize - 50)
Dim drawFont As New Font("Times New Roman", 12)
Dim drawBrush As New SolidBrush(Color.Black)
Dim stringSize As SizeF = newGraphics.MeasureString(HeaderLabel.Text, drawFont)
' Draw header label inbetween the two edges.
newGraphics.DrawString(HeaderLabel.Text, drawFont, drawBrush, (startPoint.X + endPoint.X) / 2 - (stringSize.Width / 2), borderSize - 45)
img.Image = newBm
PushUndo(img.Image.Clone)
End Sub
I would advise trying the following method to use one picturebox on top of the other, it is a lot simpler than some other methods. In your form load handler, do something like:
pctBackground.BackgroundImage = Bitmap.FromFile("park.jpg")
pctForeground.BackColor = Color.Transparent
pctForeground.Parent = pctBackground
pctForeground.Image = New Bitmap(pctForeground.ClientSize.Width, pctForeground.ClientSize.Height)
Then when you have drawn on the pctForeground, save it like:
pctForeground.Image.Save("dog_in_park.png", System.Drawing.Imaging.ImageFormat.Png)
I have problem with Graphics.RotateTransfrom() with the following code :
Dim newimage As Bitmap
newimage = System.Drawing.Image.FromFile("C:\z.jpg")
Dim gr As Graphics = Graphics.FromImage(newimage)
Dim myFontLabels As New Font("Arial", 10)
Dim myBrushLabels As New SolidBrush(Color.Black)
Dim a As String
'# last 2 number are X and Y coords.
gr.DrawString(MaskedTextBox2.Text * 1000 + 250, myFontLabels, myBrushLabels, 1146, 240)
gr.DrawString(MaskedTextBox2.Text * 1000, myFontLabels, myBrushLabels, 1146, 290)
a = Replace(Label26.Text, "[ mm ]", "")
gr.DrawString(a, myFontLabels, myBrushLabels, 620, 1509)
a = Replace(Label5.Text, "[ mm ]", "")
gr.DrawString(a, myFontLabels, myBrushLabels, 624, 548)
gr.RotateTransform(90.0F)
gr.DrawString(a, myFontLabels, myBrushLabels, 0, 0)
PictureBox1.Image = newimage
I dont know why but my image in pictureBox1 is not rotated. Someone known solution ?
The issue at hand is that the RotateTransform method does not apply to the existing image.
Instead, it applies to the transformation matrix of the graphics object. Basically, the transformation matrix modifies the coordinate system used to add new items.
Try the following :
Dim gfx = Graphics.FromImage(PictureBox1.Image)
gfx.DrawString("Test", Me.Font, Brushes.Red, New PointF(10, 10))
gfx.RotateTransform(45)
gfx.DrawString("Rotate", Me.Font, Brushes.Red, New PointF(10, 10))
The first string is drawn normally, while the second is drawn rotated.
So what you need to do is create a new graphics object, apply your rotation, draw your source image onto the graphics (graphics.DrawImage), and then draw all your text :
' Easy way to create a graphisc object
Dim gfx = Graphics.FromImage(PictureBox1.Image)
gfx.Clear(Color.Black)
gfx.RotateTransform(90) ' Rotate by 90°
gfx.DrawImage(Image.FromFile("whatever.jpg"), New PointF(0, 0))
gfx.DrawString("Test", Me.Font, Brushes.Red, New PointF(10, 10))
gfx.DrawString("Rotate", Me.Font, Brushes.Red, New PointF(10, 10))
But beware of rotation, you'll find that you need to change the coordinates at which you draw your image (Or change the RenderingOrigin property of the graphics, setting it to the center of the image makes it easier to handle rotations), otherwise your picture won't be visible (it will be drawn, but off the visible part of the graphics).
Hope that helps
I have a set of shapes created in visual basic that need to be colored in:
Public Class Form1
Private Sub btnDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDraw.Click
Dim formSurface As Graphics = Me.CreateGraphics 'creates surface
Dim world As New Pen(Color.Black, 3)
formSurface.DrawRectangle(world, 250, 50, 300, 300) 'world
Dim roof As New Pen(Color.Black, 3)
Dim roof1 As New Point(325, 200)
Dim roof2 As New Point(475, 200)
Dim roof3 As New Point(400, 100)
Dim roof4 As New Point(400, 100)
Dim curvePoints As Point() = {roof1, roof2, roof3, roof4}
formSurface.DrawPolygon(roof, curvePoints) 'triangle roof
Dim body As New Pen(Color.Black, 3)
formSurface.DrawRectangle(body, 325, 200, 150, 150) 'square body
Dim sun As New Pen(Color.Black, 3)
formSurface.DrawEllipse(sun, 450, 75, 50, 50) 'sun
Dim door As New Pen(Color.Black, 3)
formSurface.DrawRectangle(door, 387, 300, 25, 50) 'door
End Sub
End Class
Everything works perfectly; the shapes are all generated where I want them to be. (I'm trying to draw a house) However, how do I color them in? Also, if I do, will the colors overlap (I want that to happen)?
Should I use some function like image.fill? I know that isn't right but I'm looking for something like that.
Thanks!
You want to use the formSurface.FillPolygon, FillRectangle, and FillEllipse commands. You can still use the Draw commands to create an outline with a different color than the fill.
The "Fill" commands need Brushes instead of pens. (Pens draw lines, brushes fill space.) The easiest type of brush to use would be like "Brushes.AliceBlue".