SubDisturb, how did you generate the png from your winforms program?
Since I'm not trying to save the png into the PBX topper folders anymore, I'm not actually saving a png at all and just drawing onto the form itself. I went through a couple different iterations. The code is def not clean/finalize and I had intended to make all of these parameters dynamic and not hardcoded. Didn't make sense to flesh all that out yet if I'm not sure where exactly I'm headed yet
.
**All of the below is assuming you've run the extremely handy and pure awesome PINemHI application to pull the scores into either memory or a tmp text file
I initially wanted to overlay on the backglass with a transparent background, but it just was too hard to read. However, to make it a little clearer to read on the backglass, I needed to add a border to the text to help make it stand out. To do that, I needed to use GraphicsPath with DrawPath and FillPath:
using (Graphics formGraphics = this.CreateGraphics())
{
GraphicsPath p = new GraphicsPath();
p.AddString(
scoreString, // text to draw
FontFamily.GenericSansSerif, // or any other font family
(int)FontStyle.Regular, // font style (bold, italic, etc.)
formGraphics.DpiY * 20 / 72, // em size
new Point(0, 0), // location where to draw text
new StringFormat()); // set options here (e.g. center alignment)
formGraphics.FillPath(Brushes.White, p);
formGraphics.DrawPath(Pens.Black, p);
}
But, ultimately, I trashed the idea of a transparent overlay and just painted the info onto an unused space on my topper screen with a black background. Since I didn't need to add a border to the text, I just used the DrawString method instead of DrawPath/FillPath:
using (Graphics formGraphics = this.CreateGraphics())
{
Font font = new Font("Arial", 15);
Color backColor = Color.Black;
Color textColor = Color.GhostWhite;
//paint the background
formGraphics.Clear(backColor);
//create a brush for the text
using (Brush textBrush = new SolidBrush(textColor))
{
using (var sf = new StringFormat()
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center,
}) formGraphics.DrawString(scoreString, font, textBrush, new Rectangle(0, 0, 1280, 500), sf);
}
}
As far as creating the png image, this is what I was doing (I spent the least amount of time on this and scraped the idea, but it worked). Also, I was just running this from a console app at the start of a table load in PBX, not from a winforms app (no reason it wouldn't work in a winform app):
sr = new StreamReader(@"c:\[MY PATH]\tmp\tmp.txt");
string scoreString = sr.ReadToEnd();
Font font = new Font("Arial", 15);
Size minSize = new Size(1280, 300);
//first, create a dummy bitmap just to get a graphics object
SizeF textSize;
using (Image img = new Bitmap(1, 1))
{
using (Graphics drawing = Graphics.FromImage(img))
{
//measure the string to see how big the image needs to be
textSize = drawing.MeasureString(scoreString, font);
if (!minSize.IsEmpty)
{
textSize.Width = textSize.Width > minSize.Width ? textSize.Width : minSize.Width;
textSize.Height = textSize.Height > minSize.Height ? textSize.Height : minSize.Height;
}
}
}
//create a new image of the right size
Image retImg = new Bitmap((int)textSize.Width, (int)textSize.Height);
using (var drawing = Graphics.FromImage(retImg))
{
Color backColor = new Color();
backColor = Color.FromArgb(0, 0, 0);
Color textColor = new Color();
textColor = Color.FromArgb(255, 255, 255);
//paint the background
drawing.Clear(backColor);
//create a brush for the text
using (Brush textBrush = new SolidBrush(textColor))
{
using (var sf = new StringFormat()
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center,
}) drawing.DrawString(scoreString, font, textBrush, new Rectangle(0, 0, retImg.Width, retImg.Height), sf);
drawing.Flush();
}
}
retImg.Save(@"c:\[MY PATH]\tmp\temp.png");
I'd love to see how you're pulling out the scripts from the tables. I think that's really the key piece I'm missing from being able to make this full automated the way I had envisioned it. My current method of matching file names to roms is not sustainable.
Edited by subdisturb, 05 April 2018 - 03:58 PM.