Results 1 to 9 of 9

Thread: blitting into a DC

  1. #1

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755

    blitting into a DC

    im having some problems....is it possible do do this?:

    VB Code:
    1. Dim PicCount As Single
    2.  
    3. Private Type SavedPics
    4.     DC As Long
    5. End Type
    6.  
    7. Dim SavedPictures(10) As SavedPics
    8.  
    9. Private Sub Command1_Click()
    10. PicCount = PicCount + 1
    11. BitBlt SavedPictures(PicCount).DC, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Picture2.hdc, 0, 0, vbSrcCopy
    12. End Sub
    13.  
    14. Private Sub Command2_Click()
    15. BitBlt Picture3.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, SavedPictures(Text1).DC, 0, 0, vbSrcCopy
    16. Picture3.Refresh
    17. End Sub
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  2. #2
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485
    Why are you not using hdc for SavedPictures(PicCount).DC? I think you might be trying to save to memory? If so create an array of memory dc objects and use those. Should be lots of examples here. Otherwise you can't assign a dc to something that isn't an object. SavedPics appears to be user defined and you must define it somewhere, right? Post more info.

  3. #3

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    yes...im trying to save it to memory...
    why cant i assign a dc to something that isn't an object?
    i have no idea how to store this otherwise...
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  4. #4
    Addicted Member
    Join Date
    Jun 2002
    Location
    Far.. far away! (Netherlands)
    Posts
    169
    Heya!

    You can do this, but you'll have to create those dc's first. If you use the function below and store the result in your array you can use them. But be sure to delete the dc's when the program closes using the DeleteDc api.

    Code:
    Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
    Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    
    Public Function GenerateDc(iWidth As Variant, iHeight As Variant) As Long
    Dim MyDc As Long
    Dim hBitMap As Long
    
    MyDc = CreateCompatibleDC(Me.hdc)
    hBitMap = CreateCompatibleBitmap(Me.hdc, iWidth, iHeight)
    
    SelectObject MyDc, hBitMap
    
    GenerateDc = MyDc
    End Function
    -Shell-

  5. #5

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    ok! thanks!
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  6. #6

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    when i create the first dc, it gets *****ed up!
    whats wrong with this code?
    Attached Files Attached Files
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  7. #7
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Add this line to the command1 click event.
    Code:
    BitBlt SavedPictures(PicCount - 1).DC, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Picture2.hdc, 0, 0, vbSrcCopy
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  8. #8

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    ok! thanks!
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  9. #9
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485

    Important!

    Look up "deleting DC's". If you don't release your objects when done you will crash when you expend all your resources.

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