Pagina 2 di 2 primaprima 1 2
Visualizzazione dei risultati da 11 a 13 su 13
  1. #11
    Utente di HTML.it
    Registrato dal
    Dec 2002
    Messaggi
    45
    Originariamente inviato da Brainjar
    Scusa ma a che serve sta funzione 'kilometrica' di lettura bmp quando nel pdf per
    caricare una immagine basta fare, utilizzando clsPDFCreator :

    codice:
      Dim clPDF As New clsPDFCreator
    
      With clPDF
        .......
        .LoadImgFromBMPFile "Img1", App.Path & "\NomeImmagine.bmp" 
        .......
        .DrawImg "Img1", 7, 4, 6, 4  ' x, y,  xDim, yDim  dell'immagine
        ......
      End With
    Infatti faccio così e mi crasha per il buffer ridotto credo....il codice che ho postato è preso dalla classe clsPDFCreator ed è li chem i da errore quando provo a caricare la mia immagine...

  2. #12
    Utente di HTML.it L'avatar di Brainjar
    Registrato dal
    Nov 2004
    Messaggi
    1,162
    Io ho un'altra versione della funzione.
    Prova a sostituirla. Ma non sono sicuro che funzioni.
    codice:
    Public Function LeggeBMP(FileName As String, _
                             ByRef ImgBuf() As Byte, _
                             ByRef ImgColor() As Byte, _
                             ByRef ImgWidth As Long, _
                             ByRef ImgHeight As Long, _
                             ByRef ImgBPP As Byte, _
                             Optional ColorSpace As pdfColorSpace = pdfRGB) As Boolean
    
      Dim C As Long
      Dim fb As Integer
      Dim BMPH As BITMAPFILEHEADER_Type
      Dim BMPI As BITMAPINFO_Type
      Dim XBMP As Long
      Dim BPP As Byte
      Dim i As Long
      Dim kk As Long
      Dim blnFlag As Boolean
      Dim tempBuf() As Byte
      Dim tempCol() As RGBQUAD_Type
      Dim lngGray As Long
      
      fb = FreeFile
      Open FileName For Binary As #fb
    '
      Get #fb, , BMPH
      Get #fb, , BMPI.BMPH
    
      LeggeBMP = False
      
      If BMPH.bfType = "BM" Then
        BPP = BMPI.BMPH.biBitCount
        
        If BPP <= 8 Then
            
          ' legge la palette di colori
          ReDim tempCol(0 To (2 ^ BPP) - 1)
          Get #fb, , tempCol()
          
          If ColorSpace = pdfRGB Then
            ReDim ImgColor(1 To 3 * (2 ^ BPP))
            For C = 0 To (2 ^ BPP) - 1
              ImgColor(C * 3 + 1) = tempCol(C).Red
              ImgColor(C * 3 + 2) = tempCol(C).Green
              ImgColor(C * 3 + 3) = tempCol(C).Blue
            Next C
          Else
            ReDim ImgColor(1 To (2 ^ BPP))
            For C = 0 To (2 ^ BPP) - 1
              lngGray = (0.33 * tempCol(C).Red + 0.59 * tempCol(C).Green + 0.11 * tempCol(C).Blue)
              ImgColor(C + 1) = IIf(lngGray > 255, 255, lngGray)
            Next C
          End If
        End If
      
        XBMP = ((BMPI.BMPH.biWidth * BPP / 8) + 3&) And &HFFFFFFFC      ' [Bytes].
        
        ImgWidth = BMPI.BMPH.biWidth
        ImgHeight = BMPI.BMPH.biHeight
        ImgBPP = BMPI.BMPH.biBitCount
        
        ReDim tempBuf(1 To BMPI.BMPH.biHeight * XBMP)
        Get #fb, BMPH.bfOffBits + 1, tempBuf()
        Close #fb
        
        ReDim ImgBuf(1 To BMPI.BMPH.biHeight * XBMP)
        kk = 0
        
        If BPP > 8 Then
          blnFlag = ((BMPI.BMPH.biWidth Mod 4) <> 0)
          
          If ColorSpace = pdfRGB Then
            For C = 1 To UBound(tempBuf) - 1 Step 3
              ImgBuf(3 * kk + 1) = tempBuf(C + 2)
              ImgBuf(3 * kk + 2) = tempBuf(C + 1)
              ImgBuf(3 * kk + 3) = tempBuf(C)
              If (((kk + 1) Mod BMPI.BMPH.biWidth) = 0) And blnFlag Then C = C + (BMPI.BMPH.biWidth Mod 4)
              kk = kk + 1
            Next
          
          Else
            For C = 1 To UBound(tempBuf) - 1 Step 3
              lngGray = 0.33 * tempBuf(C + 2) + 0.59 * tempBuf(C + 1) + 0.11 * tempBuf(C)
              ImgBuf(kk + 1) = IIf(lngGray > 255, 255, lngGray)
              If (((kk + 1) Mod BMPI.BMPH.biWidth) = 0) And blnFlag Then C = C + (BMPI.BMPH.biWidth Mod 4)
              kk = kk + 1
            Next
            ReDim Preserve ImgBuf(1 To kk)
          
          End If
          
        ElseIf BPP <= 8 Then
          blnFlag = (BMPI.BMPH.biWidth Mod 16) <> 0
          For i = 1 To UBound(tempBuf)
            ImgBuf(kk + 1) = tempBuf(i)
            If ((kk + 1) Mod Int((BMPI.BMPH.biWidth + (8 / BPP) - 1) / (8 / BPP))) = 0 And blnFlag Then i = i + (XBMP - (i Mod XBMP))
            kk = kk + 1
          Next
          ReDim Preserve ImgBuf(1 To kk)
        
        End If
        LeggeBMP = True
      End If
    
    End Function
    Ciao, Brainjar

  3. #13
    Utente di HTML.it
    Registrato dal
    Dec 2002
    Messaggi
    45
    Ho sostituito la mia LeggeBmp con la tua ma mi da un errore su:

    blnFlag = LeggeBMP(FileName, ImgBuf(), ImgColor)

    più precisamente su imgColor...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.