fodev.net

FOnline Development => Share Your Work => Tools => Topic started by: Wipe on November 12, 2012, 05:03:17 am

Title: TempGraphic
Post by: Wipe on November 12, 2012, 05:03:17 am
Silly result of even more silly bet; i was supposed to create graphics for 20 inventory items in less than hour, so i did it like a typical slacker. Program name speaks for itself, don't expect much... ;)

http://rotators.fodev.net/wipe/TempGraphic.zip
https://github.com/rotators/fo2238/tree/master/Tools/TempGraphic/

I'll be amazed if anyone will find it useful
Title: Re: TempGraphic
Post by: JovankaB on November 12, 2012, 08:17:28 am
Very nice! I used it to create avatar.
Interface is intuitive, I found no bugs. I recommend it to everyone.
Title: Re: TempGraphic
Post by: davrot on November 12, 2012, 09:49:32 am
Isn't Jovanka amazing?  :-*
Title: Re: TempGraphic
Post by: Gob on November 14, 2012, 01:21:51 pm
I converted your program to VB.NET, here is the code. I hope you don't mind.

Code: [Select]
Imports System
Imports System.Drawing
Imports System.Data
Imports System.Deployment
Imports System.Drawing.Imaging
Imports System.Windows.Forms
Namespace TempGraphic

End Namespace

Partial Public Class frmMain
    Inherits Form

    Public Sub New()
        MyBase.New()
        InitializeComponent()
        Me.CreateImage("")
    End Sub

    Private Sub CreateImage(ByVal text As String)
        Dim lines() As String = text.Split(New String() {"" & vbCrLf}, StringSplitOptions.RemoveEmptyEntries)
        If ((lines.Length > 0) _
                    AndAlso (lines.Length < 4)) Then
            Dim font As Font = New Font("Tahoma", 8, FontStyle.Bold)
            Dim bmp As Bitmap = New Bitmap(1, 1)
            Dim w As Integer = 0
            Dim g As Graphics = Graphics.FromImage(bmp)
            For Each line As String In lines
                Dim tmpsize As SizeF = g.MeasureString(line, font, 90)
                If (tmpsize.Width > w) Then
                    w = CType(tmpsize.Width, Integer)
                End If
            Next
            bmp = New Bitmap((w + 10), (25 _
                            + ((lines.Length - 1) _
                            * (lines.Length > 1))))
            Dim x As Integer = 1
            Do While (x < bmp.Width)
                Dim y As Integer = 1
                Do While (y < bmp.Height)
                    If (((x = 1) _
                                OrElse (y = 1)) _
                                OrElse ((x _
                                = (bmp.Width - 1)) _
                                OrElse (y _
                                = (bmp.Height - 1)))) Then
                        bmp.SetPixel(x, y, Color.White)
                    Else
                        bmp.SetPixel(x, y, Color.FromArgb(104, 36, 96))
                    End If
                    y = (y + 1)
                Loop
                x = (x + 1)
            Loop
            Dim l As Integer = 0
            For Each line As String In lines
                g.DrawString(line, font, Brushes.White, 5, (5 _
                                + (l * 15)))
                l = (l + 1)
            Next
            Me.pictureBox1.Image = CType(bmp, Image)
            Me.button1.Enabled = True
        Else
            Me.pictureBox1.Image = Nothing
            Me.button1.Enabled = False
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        If Me.pictureBox1 IsNot Nothing Then
            Dim result As DialogResult = Me.saveFileDialog1.ShowDialog()

            If result = DialogResult.OK Then
                Me.pictureBox1.Image.Save(Me.saveFileDialog1.FileName, ImageFormat.Png)
            End If
        End If
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles textBox1.TextChanged
        Dim self As TextBox = DirectCast(sender, TextBox)

        Me.CreateImage(self.Text)
    End Sub
End Class

The only thing I wasn't able to do is make the text show in the picture.
Title: Re: TempGraphic
Post by: K-9 on August 06, 2013, 04:05:22 am
Link is dead  :-\
Title: Re: TempGraphic
Post by: Ganado on August 06, 2013, 04:32:46 am
You're right, it was never re-uploaded after move. Until it's re-uploaded, here's a temporary link to the .zip file: http://www.sendspace.com/file/tnmb62 (Don't accidentally download one of those ads).
Title: Re: TempGraphic
Post by: K-9 on August 06, 2013, 04:43:08 am
You're right, it was never re-uploaded after move. Until it's re-uploaded, here's a temporary link to the .zip file: http://www.sendspace.com/file/tnmb62 (Don't accidentally download one of those ads).
Thanks Ganado !
Title: Re: TempGraphic
Post by: Wipe on August 08, 2013, 12:00:28 pm
Totally forgot about this one ;D
Anyway, re-uploaded and updated links.