battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.

battle programmers allianceLog in

the LivinGrimoire Artificial General Intelligence software design pattern forum image slicer image slicer

the image is sliced to 121 even pieces as .bmp files
in the code the gdi error is fixed, no problemo .
you can hard code to get another number of slices in your needed size ( height & width wize ).


Public Class Form1
    Dim bitmap1 As Bitmap
    Dim outputPath As String = Nothing
    Private Sub btnInput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInput.Click
            Label2.Visible = False
            Label2.Text = Nothing
            Dim fs As IO.FileStream = New IO.FileStream(OpenFileDialog1.FileName, IO.FileMode.Open)
            bitmap1 = Image.FromStream(fs)
            PictureBox1.Image = bitmap1
        Catch ex As Exception
            MsgBox("select an input path picture file")
        End Try
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        OpenFileDialog1.FileName = Nothing
        OpenFileDialog2.FileName = Nothing
    End Sub

    Private Sub btnOutput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOutput.Click
            outputPath = OpenFileDialog2.FileName
            outputPath = outputPath.Substring(0, outputPath.LastIndexOf("\") + 1)
            Label1.Text = outputPath
            Dim bmts As New Bitmap(bitmap1.Width \ 11, bitmap1.Height \ 11)
            For i = 1 To 11
                For j = 1 To 11
                    For hj = 1 To bitmap1.Height \ 11 - 1 ' y of now picture
                        For wi = 1 To bitmap1.Width \ 11 - 1 ' x of now picture
                            bmts.SetPixel(wi, hj, bitmap1.GetPixel(wi + (j - 1) * (bitmap1.Width \ 11), hj + (i - 1) * (bitmap1.Height \ 11))) 'fix
                    Dim bitmapToSave As New Bitmap(bmts)
                    bitmapToSave.Save(outputPath & (11 * (j - 1) + i) & ".bmp", Imaging.ImageFormat.Bmp)
            Label2.Text = "image slicing completed"
            Label2.Visible = True
        Catch ex As Exception
            MsgBox("have you selected an input picture ? is it standard size ?, have you selected a file in a output directory with no files named 1 - 121.bmp")
        End Try
    End Sub
End Class image slicer Emptyform controls

after :
opening 2010, project, new
toolbox :
drag to the form the controls :
2 buttons, picturebox, 2 openfiledialog, 2 lables.
set theire properties (by right clicking them) :
name : btninput, text : input
name : btnoutput, text : output
label2 : set visible property to false
picturebox1 : dock it from its dock property.
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply