Announcement

Collapse
No announcement yet.

Bitmaps in NT

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

  • Peter Scheutz
    replied
    Originally posted by Iain Johnstone:

    [snip]


    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

    '================

    I cannot see why NT has a problem with this - any suggestions?

    Iain

    When calculating the size of the picture, I belive you should calculate the width like this:

    tBI.bmiHeader.biSizeImage = pic.lStride * tBI.bmiHeader.biHeight
    for 24 bits calculate stride (sometimes called pitch?) like this:

    pic.lStride = ( bm.bmWidth * 3 + 3 ) And &HFFFFFFFC

    Also do this when saving.

    You also might want to try this function:
    I noticed that some NT's can't load RLE compressed bmps.

    Code:
    Function bmpIsvalidAndNotCompressed(fname As String) As Long
       Local f As Long
       Local bmpheader As Asciiz*54
       Local compType As Dword Ptr
    
    
       If IsFalse Exist(fname) Then Function=%False :Exit Function
       f=FreeFile
    
       Open fname For Binary As f
            If Lof(f)>=54 Then
                Get$ f,54,bmpheader
                Close f
            Else
                Close f
                msgbox fname & " is not a valid bmp file"
                Function=%False :Exit Function
            End If
    
            If UCase$(Left$(bmpheader,2))<>"BM" Then
                msgbox fname & " is not a valid bmp file"
                Function=%False :Exit Function
            End If
    
            compType=VarPtr(bmpheader)+30
            If @compType<>0 Then
                msgbox fname & " is compressed"
                Function=%False :Exit Function
            End If
    
    
       Function=%true
    
    End Function
    --
    Best regards
    Peter Scheutz

    ------------------




    [This message has been edited by Peter Scheutz (edited December 20, 2000).]

    Leave a comment:


  • Semen Matusovski
    replied
    iain --
    if you have pb/cc, try a code http://www.powerbasic.com/support/pb...ad.php?t=22841

    i am not sure that i tested it in all oses, but i hope so, because i included it in real app.

    ------------------
    e-mail: [email protected]

    Leave a comment:


  • Iain Johnstone
    replied
    I have finally cracked the problem by using a handle to the memory BMP instead of saving it as a file. I have worked out what is happening under the different operating systems, but that is an academic point at the moment.
    Once last puzzle - using the code below sets the printer to ladscape or portrait depending on the value in porlan (1 =port, 2=lands). This works fine under Win95, but is ignored by the printer driver in NT.

    IF dWret <> %IDOK THEN
    pDevMode = ""
    closePrinter hPrt
    ELSE
    DocumentProperties hDlg, hPrt, BYCOPY pPrinterName, BYVAL DvModePtr, _
    BYVAL %NULL, %DM_OUT_BUFFER
    @DvModePtr.dmOrientation = porlan '1 for portrait, 2 for landscape
    END IF
    DocumentProperties hDlg, hPrt, BYCOPY pPrinterName, BYVAL DvModePtr, _
    BYVAL DvModePtr, %DM_OUT_BUFFER OR %DM_IN_BUFFER
    ClosePrinter hPrt


    Any suggestions?
    Thanks to all those who have helped bale me out

    Have just seen Semen's example - tidier than mine so it is back to the code!
    Iain Johnstone

    ------------------

    Leave a comment:


  • Semen Matusovski
    replied
    Iain --
    Unf. without sample I can't re-produce a problem and even don't exactly imagine, which kind of defect do you have.
    If not difficult, send me Bmp by E-mail.

    About handle (w/o test). Handle is hMemBmp. But you need to release it.
    For example: change
    Code:
    SelectObject hMemDC, hMemBmp
    to
    Code:
    hMemBmpRmb = SelectObject (hMemDC, hMemBmp)
    After
    Code:
    BitBlt hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, hDC, rc.nLeft, rc.nTop, %SRCCOPY
    insert
    Code:
    SelectObject hMemDC, hMemBmpRmb
    About scan lines. I know about troubles with alignment only (hope, not in my sample) - lines are moved relative to each other.

    If Bmp is totally black, BitBlt doesn't work (this can happends, if hDC are not compatible: Screen - Printer).
    But this is a fantasy only.

    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Don Dickinson
    replied
    Just to clarify %LR_LOADFROMFILE is not supported on NT3.51 and lower. It is supposed to be fine on NT4 and greater
    --Don

    ------------------
    www.basicguru.com/dickinson

    Leave a comment:


  • Iain Johnstone
    replied
    I think I have tracked down the error in this application. The LoadImage and printing routines work OK under NT if loading another BMP. The problem occurs when trying to load the BMP produced by the program. Interestingly, the file size varies with the operating system - under Win95 the file size is 992038, whereas under NT it is 991086 - same program, same data! This difference could be due to padding the scan lines, but I think this is unlikely, as all the constants are the same in both operating systems.
    I may have to find a way of using a handle to the generated image instead of saving it as a file, but i cannot yet see how to do this from the code.
    Iain Johnstone

    ------------------

    Leave a comment:


  • Semen Matusovski
    replied
    Iain --
    I am not surprised that a program works under 9x and doesn't work under NT.
    It's too typical situation: some API functions works differently under NT and 9x.

    Coming back to your program ...
    Unf. I didn't receive an answer about the BBS' code.
    So alone, what I can recommend - to begin from the end.
    To start BBS' sample. If works - to check hDC and rc in own program.

    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Iain Johnstone
    replied
    Semen:-
    The code works perfectly under Win95, but fails under NT - same compiled program, same computer.
    However, a different bitmap (not generated by the program) loads and prints out OK.
    Therefore, I feel that the problem is in generating the bitmap under NT.
    I have checked for obvious things like integers that should be long etc, but it all seems OK

    This is part of a 750K program, and it would not be easy to extract a section that would run as a standalone.
    When the problem is solved, I hope to put these routines into a DLL, as the code is getting a bit unmanageable
    Iain

    ------------------

    Leave a comment:


  • Semen Matusovski
    replied
    ian --
    i reboot to nt4, also sp6 and took a code from poffs
    (reference http://www.powerbasic.com/support/pb...ad.php?t=22733

    i tested in some resolutions (for example, 1280 * 1024 * "65536"; 1024 * 768 * "true color") - and in all cases paint read bmp24.bmp w/o problems.
    do you want to say that original code fails on your pc ?

    anyway, pls, post full not-workable fragment and it will possible to test.

    ------------------
    e-mail: [email protected]

    Leave a comment:


  • Iain Johnstone
    replied
    Thanks for the input. Perhaps a little more background is required here. The program
    generates a lin/log graph which is displayed in the normal window. The DC for this is turned
    into a bmp file using some code that Semen posted to me back in October 99 - (search for
    CreateTrueColor in PB for Windows). This program works OK on Win95 (on the same dual-boot
    machine), but fails on NT.

    To take the comments in turn:
    Eric - I have added the Byval %Null as you suggested, but to no avail - except that another
    bmp file prints out OK - leading on to your invalid format (see below).

    Scott - the file is generated by the program and saved to disc for use by another section,
    so mediation by another program is not possible.

    Semen - I had a look at SMTP.BAS, but it is basically the same code as I am using. However,
    looking at the generated file in Paint under NT shows a plain white rectangle of the correct
    size,but with no coloured lines in it. Looking at the same file with Paintshop Pro under
    NT shows all the details that should be there. Changing the code and forcing it to read
    SMTP.BMP instead prints out OK, so I feel that the problem must lay with the structure of
    the file generated by the program.
    The code for this is much as you gave it to me a year ago:-
    FUNCTION CreateTrueColorBmpFile (FileBmp AS STRING,hDC AS LONG, rc AS RECT) AS LONG
    LOCAL f AS LONG, hMemDC AS LONG,n as integer
    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
    '================

    I cannot see why NT has a problem with this - any suggestions?

    Iain

    ------------------

    Leave a comment:


  • Scott Wolfington
    replied
    Iain,

    Try turning your bitmap (.bmp) file into a .dib formatted file.
    .dib is a Device Independent Bitmap. I've seen issues on NT
    with regular bitmaps. I believe Paint Shop Pro can save to .dib.
    Then, once saved, just rename the file to have a .bmp extension.

    I think this may solve your problem.

    Scott


    ------------------

    Leave a comment:


  • Semen Matusovski
    replied
    Take a look smtp.bas

    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Eric Pearson
    replied
    Well my problem was that I spelled the name of my bitmap wrong. When I corrected that, and made the ASCIIZ long enough for a path+name, it started working fine on my NT4 SP3 system.

    Maybe the bitmap file isn't in the right place? Maybe the bitmap file is invalid?

    Hmmm... negative values are perfectly legal as handles when you use LONG integers. Maybe you're loading it after all?

    -- Eric


    ------------------
    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:[email protected][email protected]</A>



    [This message has been edited by Eric Pearson (edited December 16, 2000).]

    Leave a comment:


  • Eric Pearson
    replied
    Iain --

    > Win32.hlp states that %LR_LOADFROMFILE is not supported in NT.

    Win32.HLP is not correct, it is supported. Try using BYVAL 0 for the first parameter, and see if that fixes it.

    (Oops, nope, I tried it and no joy. I'll figure it out and post the answer shortly.)

    -- Eric


    ------------------
    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:[email protected][email protected]</A>



    [This message has been edited by Eric Pearson (edited December 16, 2000).]

    Leave a comment:


  • Iain Johnstone
    started a topic Bitmaps in NT

    Bitmaps in NT

    The code below works OK in Win95, but always returns 0 in NT4 sp6 (or sometimes
    a large negative number):-

    local hTempBitmap as long
    local tempz as asciiz*25
    tempz="Temp_sch.bmp"
    hTempBitmap = LoadImage(0, tempz, %IMAGE_BITMAP, 0, 0, %LR_LOADFROMFILE)
    msgbox str$(hTempBitmap)

    My copy of Win32.hlp states that %LR_LOADFROMFILE is not supported in NT. If
    this is the case, how do I load a BMP file into the program under NT?

    A very confused
    Iain Johnstone

    ------------------
Working...
X