Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1448

Convert hBitmap to hImage with GDI, it is possible?

$
0
0
Hello everyone,

I would like to know if hBitmap can be passed to hImage.

Let me explain, I am making a program that displays the covers extracted from the ITAG metadata of mp3 music files in a Picturebox.

In ‘Sub DrawImage (…)’, is where the images are loaded.

At this point I thought, well ... if I already have the image loaded in the variable 'Cover' type 'hBitmap' as a variable 'Publish' for the whole program, why not take advantage of it and not have to save it to a JPG file and then in a DrawImage () program line in 'GdipLoadImageFromFile (StrPtr (FileName), hImage)' have to load it back into variable 'FileName' and process the image 2 times.

Here's the problem, once the library 'GdipLoadImageFromFile' loads the temporary jpg file, it returns it as 'hImage'.

I think that in order not to waste so much time in this process and the images are loaded faster in the control there may be another solution.
I've been looking at libraries and there's one called 'GdipLoadImageFromStream (…) I don't know if it could work.

I hope you have explained me well and can help me.

This is what I am doing so far and it works, but could it be improved with the aforementioned ???

Code:

Private Sub DrawImage(hGraphics As Long, Index As Long, FileName As String, DestTR As RECTF)

    Dim TR As RECTF
    Dim Conver As Long
    Dim hImage As Long
    Dim ImagPlayMow As Long
    Dim PLeft As Long, PTop As Long
    Dim ReqWidth As Long, ReqHeight As Long
    Dim HScale As Double, VScale As Double
    Dim MyScale As Double
    Dim ImgWidth As Long
    Dim ImgHeight As Long
    Dim SourceHDC As Long
    Dim TempFile As String
   
If mLoadCover = FromMusicFile Then
   
    TempFile = App.Path & "\tmpCover.jpg"
    Call LoadTag(FileName)                'Calls the object that extracts the album art from the MP3 and saves it in the variable 'Cover' = hBitmap
    Call SavePicture(Cover, TempFile) 'Save the image of the variable 'Cover' in the temporary file' tmpCover.jpg '
    FileName = TempFile
End If


If GdipLoadImageFromFile(StrPtr(FileName), hImage) = 0 Then  'Open the temporary jpg  image.

    Call GdipGetImageBounds(hhImage, TR, UnitPixel)
       
        ImgWidth = TR.nWidth
        ImgHeight = TR.nHeight
       
        ArrDimensions(Index) = ImgWidth & " x " & ImgHeight
 
        If ImgWidth > DestTR.nWidth Or ImgHeight > DestTR.nHeight Then
            HScale = DestTR.nWidth / ImgWidth
            VScale = DestTR.nHeight / ImgHeight
       
            MyScale = IIf(VScale >= HScale, HScale, VScale)
           
            ReqWidth = ImgWidth * MyScale
            ReqHeight = ImgHeight * MyScale
   
            PLeft = DestTR.nLeft
            PTop = DestTR.nTop + 1
        Else
            ReqWidth = ImgWidth
            ReqHeight = ImgHeight
            PLeft = DestTR.nLeft
            PTop = DestTR.nTop + 1
        End If
   
        ReqWidth = ItemHeight - 10
        ReqHeight = ItemHeight - 10
     
        GdipDrawImageRectRectI hGraphics, hhImage, PLeft, PTop, ReqWidth, ReqHeight, 0, 0, ImgWidth, ImgHeight, UnitPixel, 0&, 0&, 0&
        Call GdipDisposeImage(hhImage)
End If
       
End Sub

Thanks.

Viewing all articles
Browse latest Browse all 1448

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>