On a userform I have a 5x5 grid of image controls. (Each control is 32pts x 32 pts.) The img controls can be different colors.
I can generate a .png from this by creating a worksheet chart (160pts x 160pts) and adding 32x32 rectangles. This works great. My problem is that I can't seem to add my rectangles flush with the left and top edges of the worksheet chart. There is about an 8 pixel gap on the top and left sides, and a 1 pixel gap on the bottom and right sides.
How do I fix this?
If it helps here is my code. (Clearly, I am NOT a programmer.)
NOTE: My ultimate goal is to create a .png image that is exactly 160 pixels wide and 160 pixels tall. (With 5 rows and 5 columns of squares that are 32x32 pixels.) So after I add shapes to the chart I scale it. This doesn't quite work due to the extra blank pixels in the image.
I can generate a .png from this by creating a worksheet chart (160pts x 160pts) and adding 32x32 rectangles. This works great. My problem is that I can't seem to add my rectangles flush with the left and top edges of the worksheet chart. There is about an 8 pixel gap on the top and left sides, and a 1 pixel gap on the bottom and right sides.
How do I fix this?
If it helps here is my code. (Clearly, I am NOT a programmer.)
Code:
Dim tmpChart As Chart, n As Long, shCount As Long, sht As Worksheet, sh As Shape
Set sht = ActiveWorkbook.ActiveSheet
Set tmpChart = Charts.Add
tmpChart.ChartArea.Clear
tmpChart.Name = "MyChart"
Set tmpChart = tmpChart.Location(Where:=xlLocationAsObject, Name:=sht.Name)
tmpChart.ChartArea.Width = UserForm1.myColumns * UserForm1.tileWidth
tmpChart.ChartArea.Height = UserForm1.myRows * UserForm1.tileHeight
tmpChart.Parent.Border.LineStyle = 0
tmpChart.ChartArea.Format.Fill.Visible = msoFalse
tmpChart.ChartArea.RoundedCorners = False
tmpChart.ChartArea.Select
sNum = 1
For sCol = 1 To UserForm1.myColumns * UserForm1.tileWidth Step UserForm1.tileWidth
For sRow = 1 To UserForm1.myRows * UserForm1.tileHeight Step UserForm1.tileHeight
If UserForm1.Controls("imgTest" & sNum).BackColor <> -2147483633 Then
Set rect = tmpChart.Shapes.AddShape(msoShapeRectangle, sRow, sCol, UserForm1.tileWidth, UserForm1.tileHeight)
rect.Fill.ForeColor.RGB = UserForm1.Controls("imgTest" & sNum).BackColor
rect.Line.Visible = False
End If
sNum = sNum + 1
Next
Next
tmpChart.ChartArea.Width = userform1.tileWidth * userform1.myRows * PointsPerPixelX
tmpChart.ChartArea.Height = userform1.tileHeight * userform1.myCols * PointsPerPixelY
ActiveChart.Export "F:\json\" & InitialFileName & ".png"
'Clean up
Worksheets("Sheet1").ChartObjects.Delete
NOTE: My ultimate goal is to create a .png image that is exactly 160 pixels wide and 160 pixels tall. (With 5 rows and 5 columns of squares that are 32x32 pixels.) So after I add shapes to the chart I scale it. This doesn't quite work due to the extra blank pixels in the image.