Announcement

Collapse
No announcement yet.

Printing bitmaps

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Printing bitmaps

    I have constructed an image in a compatible DC that is then displayed on the screen in a window 700 x 700 pixels. This uses the traditional code:
    BitBlt hDC, 0, 0,ScreenHeight,ScreenHeight, hMemoryDC, 0, 0, %srccopy
    and this works OK.

    I now need to print this out. I am using Don Dickinson's code published by Dave Navarro on 12/11/99 on the BBS. I have modified the code as I do not need some it, and this works OK if I load a bitmap from a file.

    I want to create a bitmap in memory from the constructed data above, and pass the handle to these print routines. I have used:
    BitBlt hMemoryDC2, 0, 0,ScreenHeight,ScreenHeight, hMemoryDC, 0, 0, %srccopy
    hTempBitmap=CreateCompatibleBitmap( hMemoryDC2,700,700)
    but just get a series on lines in the printout.

    How can I do this apparently simple task?
    Help please
    Iain Johnstone


    ------------------
    “None but those who have experienced them can conceive of the enticements of science” - Mary Shelley

  • #2
    It sounds like an _incompatible_ DC is in use... post the exact code you are using and we may be able to help more...



    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Iain --
      Following simple function stores (a part of) hDC as bitmap-file.
      If you nead hbmp only cut some lines.

      As I remember, I posted another sub, which copies a part of the screen to clipboard.
      Before copying, hBmp already built.

      Code:
         Function CreateTrueColorBmpFile (FileBmp As String, hDC As Long, rc As RECT) As Long
            Local f As Long, hMemDC As Long
            Local hMemBmp As Long, bm As BITMAP, bmi As BITMAPINFO
            Local lpBITMAPFILEHEADER As BITMAPFILEHEADER, lpBITMAPINFOHEADER As BITMAPINFOHEADER
            hMemDC = CreateCompatibleDC (hDC)
            bmi.bmiHeader.biSize = SizeOf(bmi.bmiHeader)
            bmi.bmiHeader.biWidth = (rc.nRight - rc.nLeft)
            bmi.bmiHeader.biHeight = (rc.nBottom - rc.nTop)
            bmi.bmiHeader.biPlanes = 1
            bmi.bmiHeader.biBitCount = 24
            bmi.bmiHeader.biCompression = %BI_RGB
            hMemBmp = CreateDIBSection(hMemDC, bmi, %DIB_RGB_COLORS, 0, 0, 0)
            GlobalLock hMemBmp
            SelectObject hMemDC, hMemBmp
            GetObject hMemBmp, SizeOf(bm), bm
            BitBlt hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, hDC, rc.nLeft, rc.nTop, %SRCCOPY
            lpBITMAPFILEHEADER.bfType = Cvi("BM")
            lpBITMAPFILEHEADER.bfSize = Len(lpBITMAPFILEHEADER) + Len(lpBITMAPINFOHEADER) + _
               bm.bmWidthBytes * bm.bmHeight
            lpBITMAPFILEHEADER.bfOffBits = 54
            lpBITMAPINFOHEADER.biSize = 40
            lpBITMAPINFOHEADER.biWidth = bm.bmWidth
            lpBITMAPINFOHEADER.biHeight = bm.bmHeight
            lpBITMAPINFOHEADER.biPlanes = 1
            lpBITMAPINFOHEADER.biBitCount = 24
            lpBITMAPINFOHEADER.biSizeImage = 54& + bm.bmWidthBytes * bm.bmHeight
            f = FreeFile: Open FileBmp For Output As #f
            Print #f, lpBITMAPFILEHEADER lpBITMAPINFOHEADER _
                Peek$(bm.bmBits, bm.bmWidthBytes * bm.bmHeight);: Close #f
            DeleteDC hMemDC: GlobalUnlock hMemBmp: DeleteObject hMemBmp
         End Function
      ------------------
      E-MAIL: [email protected]

      [This message has been edited by Semen Matusovski (edited October 24, 2000).]

      Comment


      • #4
        Semen
        Once again the PB fraternity is indebted to you - many thanks for your suggestions.
        I chose to save the data as a file, reload it as a BMP then print it - this gives me some flexibility in the future.
        Thanks also to Lance.
        Its been a hard day - I shall now lay down in a darkened room
        Iain

        ------------------
        “None but those who have experienced them can conceive of the enticements of science” - Mary Shelley

        Comment

        Working...
        X