G
gillardg
hello i'm using this code to create big mosaic from image
but it does not the job what is wrong whit my code?
'add an image to the bitmap
Private Function addImg(ByVal ibitmap As Image, ByVal imagename As
String, ByVal ILeft As Integer, ByVal ITop As Integer) As Boolean
Dim i As Image = Image.FromFile(imagename)
Dim g As Graphics = Graphics.FromImage(ibitmap)
g.DrawImage(i.Clone, ILeft, ITop, numwidth.Value, numheight.Value)
g.Dispose()
i.Dispose()
End Function
'mosaic of images square
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
If pb1.Image Is Nothing Then
Exit Sub
End If
If pb1.Image.Width >= 250 Or pb1.Image.Height >= 250 Then
ResizeToolStripMenuItem.PerformClick()
End If
Dim img As Image = pb1.Image
Dim wi As Integer = img.Width
Dim he As Integer = img.Height
Dim bmp As New Bitmap((wi * 50), (he * 50))
'make an array of structure pixel ( x ,y , color )
Dim pix() As pixel = img2pix(img)
Dim pixe As Color
Dim fil As String = String.Empty
For z As Long = 0 To pix.GetUpperBound(0)
pixe = ColorManagement.GetNearestColor(pix(z).col)
addImg(bmp, retitem(pixe), pix(z).x, pix(z).y)
Next
Dim sdf As New SaveFileDialog
sdf.AddExtension = True
sdf.DefaultExt = ".png"
If sdf.ShowDialog = Windows.Forms.DialogResult.OK Then
bmp.Save(sdf.FileName, Imaging.ImageFormat.Png)
Else
bmp.Save(filePath & ".mosaic.png", Imaging.ImageFormat.Png)
End If
End Sub
' find the corresponding image this is working
Function retitem(ByVal colo As Color) As String
Return IO.Path.Combine(dirImg, colo.Name & ".jpg")
End Function
but it does not the job what is wrong whit my code?
'add an image to the bitmap
Private Function addImg(ByVal ibitmap As Image, ByVal imagename As
String, ByVal ILeft As Integer, ByVal ITop As Integer) As Boolean
Dim i As Image = Image.FromFile(imagename)
Dim g As Graphics = Graphics.FromImage(ibitmap)
g.DrawImage(i.Clone, ILeft, ITop, numwidth.Value, numheight.Value)
g.Dispose()
i.Dispose()
End Function
'mosaic of images square
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
If pb1.Image Is Nothing Then
Exit Sub
End If
If pb1.Image.Width >= 250 Or pb1.Image.Height >= 250 Then
ResizeToolStripMenuItem.PerformClick()
End If
Dim img As Image = pb1.Image
Dim wi As Integer = img.Width
Dim he As Integer = img.Height
Dim bmp As New Bitmap((wi * 50), (he * 50))
'make an array of structure pixel ( x ,y , color )
Dim pix() As pixel = img2pix(img)
Dim pixe As Color
Dim fil As String = String.Empty
For z As Long = 0 To pix.GetUpperBound(0)
pixe = ColorManagement.GetNearestColor(pix(z).col)
addImg(bmp, retitem(pixe), pix(z).x, pix(z).y)
Next
Dim sdf As New SaveFileDialog
sdf.AddExtension = True
sdf.DefaultExt = ".png"
If sdf.ShowDialog = Windows.Forms.DialogResult.OK Then
bmp.Save(sdf.FileName, Imaging.ImageFormat.Png)
Else
bmp.Save(filePath & ".mosaic.png", Imaging.ImageFormat.Png)
End If
End Sub
' find the corresponding image this is working
Function retitem(ByVal colo As Color) As String
Return IO.Path.Combine(dirImg, colo.Name & ".jpg")
End Function