Results 1 to 9 of 9

Thread: I got a hard question... I think

  1. #1
    Guest
    Hello everyone.. I got a question..

    well say that if i open a picture file (bmp or Jpeg or whatever) as binary.

    for example open blah.jpg for binary as 1
    then get ALL the content of the binary file (using the LOF stuff)...

    Now I got the whole picture loaded in a variable, as Binary. HOW THE HECK DO I Make the picture or image control to recognize the picture and show it.. do u guys get what I'm sayin? I hope u do if not then reply and I reply back

  2. #2
    New Member
    Join Date
    Jul 2000
    Posts
    6

    Lightbulb

    Why don't you use the LoadPicture function, if you need to put into a variable why not put it into IPictureDisp. If you need to open a image file like you send you have to take into considerations like bitmap headers, Palettes and the pixel data which are all saved as in the file.

    If you look about you might find some one has posted the source for an image application.

    Final note:
    Opening Jpegs thru Open is much longer proccess than doing the bitmaps, My advice just use the LoadPicture function Unless you want to save the images, cos SavePicture function only will save bitmap format, where the load handles a few formats.

  3. #3
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181

    Question

    Is there a special reason why you want to load the picture by getting the binay data? Do you want to save memory by loading a jpg like this?

    I think you'll have to load the picture with the LoadPicture Func. Of course in Memory it is stored as bitmap after this.

    So please post the reason why you want to load it in your way!

  4. #4
    Guest
    Well, i really don't want to explain why i want to do this. All i wanted to know if I could use it.. and yes I know about the load picture and all that other crap.. I needed to know if I could get the picture box to accept binary data on the fly. for the REAL thing we wont be using Picture box but instead DirectX.. it's stuff I'm working on.. I can't say what I'm working on yet.. but all I can say is that it loads a picture as binary, reads the whole thing, and whether or not I can use the binary data to display a picture..??

  5. #5
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181

    Red face

    Yes you can use the binary data if you uses a bmp but not the JPG

    you can get the handle (hdc) to the image and then use createSurfacefromDC or similar

    That's all
    Sanity is a full time job

    Puh das war harter Stoff!

  6. #6
    New Member
    Join Date
    Jul 2000
    Posts
    6

    Question

    If you are going to use DirectX why arn't you wanting to use the DDraw.CreateSurfaceFromFile() ??

  7. #7
    Guest
    Now, I asked the question, there's probably a reason that I'm not using the createsurfacefromfile function.. Ok? so stop asking me why the hell I don't do this and that.. cause May be because, I'm doing something else... Cool? if u can't help me.. then don't ask me those questions. I know how to use DirectDraw and Direct3D and Direct Play.. I'm not freaking dumb..

  8. #8
    New Member
    Join Date
    Jul 2000
    Posts
    6

    Exclamation

    Seeing I don't know you or your current level DX7, It would be fair to say, I asked a reasonable question. I'm sorry if upset you . If you still insist on loading bitmaps in through binary then try this function.
    Picture1 is a Picturebox.
    Code:
    Declare Function StretchDIBits Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal DX As Long, ByVal DY As Long, ByVal SrcX As Long,_
     ByVal SrcY As Long, ByVal wSrcWidth As Long, ByVal wSrcHeight As Long, lpBits As Any, lpBitsInfo As BITMAPINFO, ByVal wUsage As Long, ByVal dwRop As Long) As Long
    Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
    Type RGBQUAD
            rgbBlue As Byte
            rgbGreen As Byte
            rgbRed As Byte
            rgbReserved As Byte
    End Type
    
    Type ImageFile
            ImageWidth As Long
            ImageHeight As Long
            ImageBPP As Byte
            ImagePalette() As RGBQUAD
            ImageData() As Byte
    End Type
    
    Type BITMAPINFOHEADER '40 bytes
            biSize As Long
            biWidth As Long
            biHeight As Long
            biPlanes As Integer
            biBitCount As Integer
            biCompression As Long
            biSizeImage As Long
            biXPelsPerMeter As Long
            biYPelsPerMeter As Long
            biClrUsed As Long
            biClrImportant As Long
    End Type
    
    Type BITMAPINFO
            bmiHeader As BITMAPINFOHEADER
            bmiColors(0 To 255) As RGBQUAD
    End Type
    
    Type BITMAPFILEHEADER
            bfType As Integer
            bfSize As Long
            bfReserved1 As Integer
            bfReserved2 As Integer
            bfOffBits As Long
    End Type
    
    Sub cmdLoad_Click()
         Dim Img as ImageFile
         Dim Filename as String
         Filename = "Any Valid Bitmap path"
         LoadBMP Filename, Img
         Picture1.Width = Img.ImageWidth + (Picture1.Width - Picture1.ScaleWidth)
         Picture1.Height = Img.ImageHeight + (Picture1.Height - Picture1.ScaleHeight)
         DrawImage Picture1.hdc, Img
         Picture1.Refresh
    End Sub
    Sub DrawImage(DC As Long, ByRef pImage As ImageFile)
        bmi.bmiHeader.biSize = 40                       'Simply the size of the header type
        bmi.bmiHeader.biWidth = pImage.ImageWidth        'Width of Image
        bmi.bmiHeader.biHeight = -pImage.ImageHeight    'Height of image (reversed)
        bmi.bmiHeader.biPlanes = 1                      'The image has 1 plane
        bmi.bmiHeader.biBitCount = pImage.ImageBPP       'How many Bits Per Pixel.
        bmi.bmiHeader.biCompression = 0                 'No Compression used.
        If pImage.ImageBPP = 8 Then CopyMemory bmi.bmiColors(0), pImage.ImagePalette(0), 256 * 4
        'Now take this information and copy the data onto the main pictures HDC.
        'Remember that StretchDIBits also draws from the bottom left corner upwards, so if our
        'data is stored from top to bottom, then we must negate the height value which will
        'flip the image.
        StretchDIBits DC, 0, 0, pImage.ImageWidth, pImage.ImageHeight, 0, 0, pImage.ImageWidth, pImage.ImageHeight, pImage.ImageData(1), bmi, DIB_RGB_COLORS, vbSrcCopy
    End Sub
    Sub LoadBMP(Filename As String, ByRef pImage As ImageFile)
        
        Dim bmfh As BITMAPFILEHEADER         'Stores file header
        Dim bmih As BITMAPINFOHEADER         'Stores info header
        Dim bmRGBQuad(0 To 255) As RGBQUAD   'Stores colour palette
        Dim bmData() As Byte                 'Stores pixel data
        Dim offset1 As Long, Offset2 As Long
        
        Open Filename For Binary Access Read As #1
            'Get the file header
            Get #1, , bmfh
            'Get the Bitmap Info (i.e size/colour depth etc)
            Get #1, , bmih
            'Depending on the colour depth, we will need
            'to resize our palette array to hold the
            'required amount of colours.
            Select Case bmih.biBitCount
                Case 8
                    'If the bitmap is 8bpp then it uses a palette
                    'so read it in, otherwise skip it.
                    Get #1, , bmRGBQuad
                Case 24
                    'Our favourite format =)
                Case Else
                    Erase bmData
                    MsgBox "Image format unsupported", vbCritical, "Error"
                    Close #1
                    Exit Sub
            End Select
            'Dimension the data array to store our image.
            ReDim bmData(1 To bmih.biSizeImage)
            'Get the image data
            Get #1, , bmData
        Close #1
        
        'Copy this data into our custom image object (which was passed).
        'Remember that Bitmaps are stored from bottom to top, so we need
        'to switch the order as we load (hence starting from the bottom line)
        pImage.ImageBPP = bmih.biBitCount
        pImage.ImageWidth = bmih.biWidth
        pImage.ImageHeight = bmih.biHeight
        If pImage.ImageBPP = 8 Then
            ReDim pImage.ImagePalette(0 To 255)
            CopyMemory pImage.ImagePalette(0), bmRGBQuad(0), 256 * 4
            ReDim pImage.ImageData(1 To (pImage.ImageWidth * pImage.ImageHeight))
            offset1 = UBound(pImage.ImageData): offset1 = offset1 - (pImage.ImageWidth - 1)
            Offset2 = 1
            For i = pImage.ImageHeight - 1 To 0 Step -1
                CopyMemory pImage.ImageData(offset1), bmData(Offset2), pImage.ImageWidth
                offset1 = offset1 - (pImage.ImageWidth)
                Offset2 = Offset2 + (pImage.ImageWidth)
            Next i
        Else
            ReDim pImage.ImageData(1 To ((pImage.ImageWidth * pImage.ImageHeight) * 3))
            Erase pImage.ImagePalette
            offset1 = UBound(pImage.ImageData): offset1 = offset1 - ((pImage.ImageWidth * 3) - 1)
            Offset2 = 1
            For i = pImage.ImageHeight - 1 To 0 Step -1
                CopyMemory pImage.ImageData(offset1), bmData(Offset2), (pImage.ImageWidth * 3)
                offset1 = offset1 - (pImage.ImageWidth * 3)
                Offset2 = Offset2 + (pImage.ImageWidth * 3)
            Next i
        End If
        Erase bmData
    
    Sub DrawImage(DC As Long, ByRef pImage As ImageFile)
        bmi.bmiHeader.biSize = 40                       'Simply the size of the header type
        bmi.bmiHeader.biWidth = pImage.ImageWidth        'Width of Image
        bmi.bmiHeader.biHeight = -pImage.ImageHeight    'Height of image (reversed)
        bmi.bmiHeader.biPlanes = 1                      'The image has 1 plane
        bmi.bmiHeader.biBitCount = pImage.ImageBPP       'How many Bits Per Pixel.
        bmi.bmiHeader.biCompression = 0                 'No Compression used.
        If pImage.ImageBPP = 8 Then CopyMemory bmi.bmiColors(0), pImage.ImagePalette(0), 256 * 4
        'Now take this information and copy the data onto the main pictures HDC.
        'Remember that StretchDIBits also draws from the bottom left corner upwards, so if our
        'data is stored from top to bottom, then we must negate the height value which will
        'flip the image.
        StretchDIBits DC, 0, 0, pImage.ImageWidth, pImage.ImageHeight, 0, 0, pImage.ImageWidth, pImage.ImageHeight, pImage.ImageData(1), bmi, DIB_RGB_COLORS, vbSrcCopy
    End Sub
    This only handles bitmap, Jpegs is completly different.

    [Edited by AndrewPrescott on 07-20-2000 at 04:03 AM]

  9. #9
    Guest
    alright, thanks a lot for helping.. I'll look at this function to read the bitmaps.. sorry I was kinda pissed off at something..

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