Home All Groups Group Topic Archive Search About

adding images to a bitmap

Author
22 Jun 2009 6:52 PM
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

Author
22 Jun 2009 10:37 PM
gillardg
it's ok I have found the problem :)


"gillardg" <gillardg*remo***@live.be> a écrit dans le message de groupe de
discussion : #ROaMq28JHA.5***@TK2MSFTNGP03.phx.gbl...
Show quoteHide quote
> 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
Author
24 Jun 2009 5:35 PM
Göran_Andersson
gillardg wrote:
> 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.

--
Göran Andersson
_____
http://www.guffa.com