Results 1 to 4 of 4

Thread: copy a bitmap an save it

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    11

    Post

    hi

    how can i copy a bitmap from a picturebox, which is not visible, to an other picturebox and save it to file then?

    here ist the code i wrote:

    Dim c, i, Erg_Img_Copy As Long
    For c = 0 To (picturebox1.ScaleHeight *12) Step 100
    For i = 0 To (picturebox1.ScaleHeight *12) Step 100
    Erg_Img_Copy = BitBlt(picturebox2.hdc, i, c, 100, 100, picturebox1.hdc, 0, 0, vbSrcCopy)
    SavePicture picturebox2.picture, "test.bmp"
    Next i
    Next c

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    I'm not sure why you want to do this, but..
    To Copy the Picture from 1 Picturebox to Another just use: Picture2 = Picture1
    If you've Modified Picture1, use: Picture2 = Picutre1.Image
    Then the Question becomes, if you're saving the Contents of Picture2, which is just the Image of Picture1,
    Why not just save the Image of Picture1?
    SavePicture Picture1.Image, "C:\Saved.bmp"

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    11

    Post

    Thank you for your answer. I have a diffrent problem. I use 2 Pictureboxes a small one (100x100 pixel) and a big one (1200x1200). I want to copy the small pic into the big one at position 0/0 then copy it a second time at 0/100 and then at 0/200 and so on, till 1100/1100) and then I wonna save it to disk.

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Alrighty then, try this:

    Add 2 Picturebox's to a Form and a Command Button, Select the Picture you want to tile into Picture1..
    Code:
    Private Sub Form_Load()
        Picture2.Visible = False
        Picture2.AutoRedraw = True
        Picture1.AutoSize = True
        Picture1.ScaleMode = vbPixels
        Picture2.ScaleMode = vbPixels
        Picture2.BorderStyle = vbBSNone
    End Sub
    
    Private Sub Command1_Click()
        Dim X As Integer
        Dim Y As Integer
        Dim W As Integer
        Dim H As Integer
        
        W = ScaleX(Picture1.Picture.Width, vbHimetric, vbPixels)
        H = ScaleY(Picture1.Picture.Height, vbHimetric, vbPixels)
        Picture2.Move 0, 0, ScaleX(1200, vbPixels, vbTwips), ScaleY(1200, vbPixels, vbTwips)
        For Y = 0 To (1200 / H)
            For X = 0 To (1200 / W)
                Picture2.PaintPicture Picture1, X * W, Y * H, W, H, 0, 0, W, H
            Next
        Next
        SavePicture Picture2.Image, "C:\Saved.bmp"
        MsgBox "Done"
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width