adding images to a bitmap

  • Thread starter Thread starter gillardg
  • Start date Start date
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
 
Hello Gillard,

The reason is that in your function addImg you do not return the
modified picture to that picture you specify in the parameters, but only
to a copy of it. This is because you passed it ByVal. If you want to
modify ibitmap, you have to pass it with ByRef.

Best regards,

Martin
 
gillardg said:
it's ok I have found the problem :)

Then please post a short explanation, so that others with similar
problems might be able to benefit from this thread.
 
Back
Top