HEIC to JPG

HEIC to JPG

Postby Natter » Tue Jun 30, 2020 9:16 am

Hi,

Can I use FWH to convert files .HEIC to .JPG files ?
Natter
 
Posts: 1120
Joined: Mon May 14, 2007 9:49 am

Re: HEIC to JPG

Postby Antonio Linares » Tue Jun 30, 2020 3:13 pm

Probably you may be able to do it using FWH GDI+ support
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: HEIC to JPG

Postby Natter » Wed Jul 01, 2020 5:22 am

Antonio, thank you for your help ! Can I learn a little more about how I can use GDI+ in this case ?
Natter
 
Posts: 1120
Joined: Mon May 14, 2007 9:49 am

Re: HEIC to JPG

Postby Antonio Linares » Wed Jul 01, 2020 6:42 am

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: HEIC to JPG

Postby Antonio Linares » Wed Jul 01, 2020 6:49 am

http://www.vbforums.com/showthread.php?881981-HEIC-picture-files

Code: Select all  Expand view
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  '
NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  '
vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "cWICImage"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private Const AC_SRC_OVER    As Byte = &H0
Private Const AC_SRC_ALPHA   As Byte = &H1
Private Const BI_RGB         As Long = 0
Private Const DIB_RGB_COLORS As Long = 0
Private Const GENERIC_READ   As Long = &H80000000
Private Const S_OK           As Long = 0

Private Type ARGB
    Blue  As Byte
    Green As Byte
    Red   As Byte
    Alpha As Byte
End Type

Private Type BLENDFUNCTION
    BlendOp             As Byte
    BlendFlags          As Byte
    SourceConstantAlpha As Byte
    AlphaFormat         As Byte
End Type

Private Type BLENDFUNCTION_Long
    Value As Long
End Type

Private Type BITMAPINFOHEADER
    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

Private Type BITMAPINFO
    bmiHeader As BITMAPINFOHEADER
    bmiColors As ARGB
End Type

Private Type Guid
    Data1    As Long
    Data2    As Integer
    Data3    As Integer
    Data4(7) As Byte
End Type

Private Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hDC As Long) As Long
Private Declare Function CreateDIBSection Lib "gdi32.dll" (ByVal hDC As Long, ByRef pBitmapInfo As BITMAPINFO, ByVal uiUsage As Long, ByRef ppvBits As Any, ByVal hSection As Long, ByVal dwOffset As Long) As Long
Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hDC As Long) As Long
Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Private Declare Function GetDC Lib "user32.dll" (ByVal hWnd As Long) As Long
Private Declare Function GdiAlphaBlend Lib "gdi32.dll" (ByVal hdcDest As Long, ByVal xoriginDest As Long, ByVal yoriginDest As Long, ByVal wDest As Long, ByVal hDest As Long, ByVal hdcSrc As Long, ByVal xoriginSrc As Long, ByVal yoriginSrc As Long, ByVal wSrc As Long, ByVal hSrc As Long, ByVal ftn As Long) As Long
Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hWnd As Long, ByVal hDC As Long) As Long
Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hDC As Long, ByVal hgdiobj As Long) As Long

Private Declare Function IWICBitmapDecoder_GetFrameCount_Proxy Lib "windowscodecs.dll" (ByVal This_Ptr As stdole.IUnknown, ByRef pCount As Long) As Long
Private Declare Function IWICBitmapDecoder_GetFrame_Proxy Lib "windowscodecs.dll" (ByVal This_Ptr As stdole.IUnknown, ByVal Index As Long, ByRef ppIBitmapFrame As stdole.IUnknown) As Long
Private Declare Function IWICBitmapScaler_Initialize_Proxy Lib "windowscodecs.dll" (ByVal This_Ptr As stdole.IUnknown, ByVal pISource As stdole.IUnknown, ByVal uiWidth As Long, ByVal uiHeight As Long, ByVal Mode As Long) As Long
Private Declare Function IWICBitmapSource_CopyPixels_Proxy Lib "windowscodecs.dll" (ByVal This_Ptr As stdole.IUnknown, ByRef prc As Any, ByVal cbStride As Long, ByVal cbBufferSize As Long, ByRef pbBuffer As Any) As Long
Private Declare Function IWICBitmapSource_GetSize_Proxy Lib "windowscodecs.dll" (ByVal This_Ptr As stdole.IUnknown, ByRef puiWidth As Long, ByRef puiHeight As Long) As Long
Private Declare Function IWICFormatConverter_Initialize_Proxy Lib "windowscodecs.dll" (ByVal This_Ptr As stdole.IUnknown, ByVal pISource As stdole.IUnknown, ByRef dstFormat As Guid, ByVal Dither As Long, ByVal pIPalette As stdole.IUnknown, ByVal alphaThresholdPercent As Double, ByVal paletteTranslate As Long) As Long
Private Declare Function IWICImagingFactory_CreateBitmapScaler_Proxy Lib "windowscodecs.dll" (ByVal pFactory As stdole.IUnknown, ByRef ppIBitmapScaler As stdole.IUnknown) As Long
Private Declare Function IWICImagingFactory_CreateDecoderFromFilename_Proxy Lib "windowscodecs.dll" (ByVal pFactory As stdole.IUnknown, ByVal wzFilename As Long, ByRef pguidVendor As Guid, ByVal dwDesiredAccess As Long, ByVal metadataOptions As Long, ByRef ppIDecoder As stdole.IUnknown) As Long
Private Declare Function IWICImagingFactory_CreateFormatConverter_Proxy Lib "windowscodecs.dll" (ByVal pFactory As stdole.IUnknown, ByRef ppIFormatConverter As stdole.IUnknown) As Long
Private Declare Function WICCreateImagingFactory_Proxy Lib "windowscodecs.dll" (ByVal SDKVersion As Long, ByRef ppIImagingFactory As stdole.IUnknown) As Long

Private m_Loaded    As Boolean
Private m_Width     As Long
Private m_Height    As Long
Private m_Frame     As Long
Private m_FrameCnt  As Long
Private m_File      As String
Private m_ImgFact   As stdole.IUnknown '
WICImagingFactory
Private m_Converter As stdole.IUnknown 'IWICFormatConverter

Public Property Get ImageWidth() As Long
    ImageWidth = m_Width
End Property

Public Property Get ImageHeight() As Long
    ImageHeight = m_Height
End Property

Public Property Get FrameCount() As Long
    FrameCount = m_FrameCnt
End Property

Public Property Get IsLoaded() As Boolean
    IsLoaded = m_Loaded
End Property

Public Sub Render(ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal cX As Long, ByVal cY As Long)
    Const WICBitmapInterpolationModeFant = 4& '
<-- http://www.virtualdub.org/blog/pivot/entry.php?id=300. New entry 4 improves image quality.
    Dim hDCScr As Long, hDIBBitmap As Long, nImage As Long, nStride As Long, pvImageBits As Long, RV As Long, tBMI As BITMAPINFO
    Dim hDCMem As Long, hbmOrig As Long, BF As BLENDFUNCTION, BFL As BLENDFUNCTION_Long, oBmpScaler As stdole.IUnknown 'IWICBitmapScaler

    If Not m_Loaded Then Exit Sub
    If IWICImagingFactory_CreateBitmapScaler_Proxy(m_ImgFact, oBmpScaler) <> S_OK Then Exit Sub
    If IWICBitmapScaler_Initialize_Proxy(oBmpScaler, m_Converter, cX, cY, WICBitmapInterpolationModeFant) <> S_OK Then Exit Sub

    hDCScr = GetDC(0&)

    If hDCScr Then
        hDCMem = CreateCompatibleDC(hDCScr)

        If hDCMem Then
            With tBMI.bmiHeader
                .biSize = LenB(tBMI.bmiHeader)
                .biWidth = cX
                .biHeight = -cY
                .biPlanes = 1
                .biBitCount = 32
                .biCompression = BI_RGB
            End With

            hDIBBitmap = CreateDIBSection(hDCScr, tBMI, DIB_RGB_COLORS, pvImageBits, 0&, 0&): Debug.Assert pvImageBits

            If hDIBBitmap Then
                hbmOrig = SelectObject(hDCMem, hDIBBitmap)

                If hbmOrig Then
                    nStride = 4& * ((cX * 32& + 31&) \ 32&)
                    nImage = nStride * cY

                    If IWICBitmapSource_CopyPixels_Proxy(oBmpScaler, ByVal 0&, nStride, nImage, ByVal pvImageBits) = S_OK Then
                        BF.BlendOp = AC_SRC_OVER
                        BF.BlendFlags = 0
                        BF.SourceConstantAlpha = 255
                        BF.AlphaFormat = AC_SRC_ALPHA
                        LSet BFL = BF

                        RV = GdiAlphaBlend(hDC, X, Y, cX, cY, hDCMem, 0&, 0&, cX, cY, BFL.Value): Debug.Assert RV
                    End If

                    RV = SelectObject(hDCMem, hbmOrig): Debug.Assert RV = hDIBBitmap
                End If

                RV = DeleteObject(hDIBBitmap):          Debug.Assert RV
            End If

            RV = DeleteDC(hDCMem):                      Debug.Assert RV
        End If

        RV = ReleaseDC(0&, hDCScr):                     Debug.Assert RV
    End If
End Sub

Public Function OpenFile(ByRef sFile As String, Optional ByVal nFrame As Long) As Boolean
    Const WICDecodeMetadataCacheOnDemand = 0&, WICBitmapDitherTypeNone = 0&, WICBitmapPaletteTypeCustom = 0&
    Const WINCODEC_SDK_VERSION1 = &H236&, WINCODEC_SDK_VERSION2 = &H237&
    Dim oBmpDecoder As stdole.IUnknown '
IWICBitmapDecoder
    Dim oFrame      As stdole.IUnknown 'IWICBitmapFrameDecode

    m_Loaded = False

    If m_ImgFact Is Nothing Then
        If WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION2, m_ImgFact) <> S_OK Then
            If WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION1, m_ImgFact) <> S_OK Then Exit Function
        End If
    End If

    m_File = sFile
    m_Frame = nFrame

    If IWICImagingFactory_CreateDecoderFromFilename_Proxy(m_ImgFact, StrPtr(sFile), UUID_NULL, GENERIC_READ, WICDecodeMetadataCacheOnDemand, oBmpDecoder) <> S_OK Then Exit Function
    If IWICBitmapDecoder_GetFrameCount_Proxy(oBmpDecoder, m_FrameCnt) = S_OK Then Debug.Assert m_Frame < m_FrameCnt Else Exit Function
    If IWICBitmapDecoder_GetFrame_Proxy(oBmpDecoder, m_Frame, oFrame) <> S_OK Then Exit Function
    If IWICBitmapSource_GetSize_Proxy(oFrame, m_Width, m_Height) <> S_OK Then Exit Function
    If IWICImagingFactory_CreateFormatConverter_Proxy(m_ImgFact, m_Converter) <> S_OK Then Exit Function
    If IWICFormatConverter_Initialize_Proxy(m_Converter, oFrame, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, Nothing, 0#, WICBitmapPaletteTypeCustom) <> S_OK Then Exit Function

    m_Loaded = True
    OpenFile = True
End Function

Private Function UUID_NULL() As Guid: End Function

Private Function GUID_WICPixelFormat32bppPBGRA() As Guid
    Static iid As Guid

    If iid.Data1 = 0& Then DEFINE_UUID iid, &H6FDDC324, &H4E03, &H4BFE, &HB1, &H85, &H3D, &H77, &H76, &H8D, &HC9, &H10

    GUID_WICPixelFormat32bppPBGRA = iid
End Function

Private Sub DEFINE_UUID(ByRef U As Guid, _
                        ByVal D1 As Long, _
                        ByVal D2 As Integer, _
                        ByVal D3 As Integer, _
                        ByVal D4_0 As Byte, _
                        ByVal D4_1 As Byte, _
                        ByVal D4_2 As Byte, _
                        ByVal D4_3 As Byte, _
                        ByVal D4_4 As Byte, _
                        ByVal D4_5 As Byte, _
                        ByVal D4_6 As Byte, _
                        ByVal D4_7 As Byte)
    U.Data1 = D1
    U.Data2 = D2
    U.Data3 = D3
    U.Data4(0) = D4_0
    U.Data4(1) = D4_1
    U.Data4(2) = D4_2
    U.Data4(3) = D4_3
    U.Data4(4) = D4_4
    U.Data4(5) = D4_5
    U.Data4(6) = D4_6
    U.Data4(7) = D4_7
End Sub



The tests I have done in Windows 10 show that if Windows has installed the codec then the Windows Imaging Component can show it. Webp and Heif codecs are installed with 1909.

I have attached the WIC class I use. Also notice there is an undocumented setting value: Const WICBitmapInterpolationModeFant = 4&. The max for this is supposed to be 3 but 4 makes a marked improvement in image quality.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: HEIC to JPG

Postby Natter » Wed Jul 01, 2020 6:57 am

Thanks. I will try !!
Natter
 
Posts: 1120
Joined: Mon May 14, 2007 9:49 am

Re: HEIC to JPG

Postby Antonio Linares » Wed Jul 01, 2020 7:02 am

That is Visual Basic code, so first we should test it from Visual Studio, then if working, port that code to FWH :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: HEIC to JPG

Postby ukoenig » Wed Jul 01, 2020 7:05 am

There are still other languages with the same problem like visual basic
to use < heic - files >. Maybe there are useful informations included.

The start-question :
IOS 11 now uses a newer, more compressed, file compression routine as default.
The HEIC photos (.heic extension) can be read in Windows 10, and other ways for earlier OS's.
Without doing a conversion to Jpeg (jpg), how can Visual Basic 6.0 load them into a PictureBox
or and Image control? Googled, but found no direct solution.


What they find out about the < heic - format > and tests.
The posts may give You some answers and informations.
As well they are talking about the usage of GDI and GDI+

VB-forum
Thread: HEIC picture files
http://www.vbforums.com/showthread.php? ... ture-files

regards
Uwe :D
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: HEIC to JPG

Postby Natter » Wed Jul 01, 2020 9:05 am

You can simply rename the HEIC to JPG. Everything will work but the orientation is not detected and the photos look rotated 90 degreesю. :(
Natter
 
Posts: 1120
Joined: Mon May 14, 2007 9:49 am

Re: HEIC to JPG

Postby Antonio Linares » Wed Jul 01, 2020 9:14 am

you may rotate the JPG
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: HEIC to JPG

Postby Natter » Wed Jul 01, 2020 9:25 am

This is not an option. We are talking about hundreds of photos
Natter
 
Posts: 1120
Joined: Mon May 14, 2007 9:49 am

Re: HEIC to JPG

Postby cnavarro » Wed Jul 01, 2020 9:42 am

Can't use some Fivewin function?

FW_TransformBitmap( hBitmap, [aCrop], [nZoom], [nRotate] )
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: HEIC to JPG

Postby nageswaragunupudi » Wed Jul 01, 2020 12:14 pm

Natter wrote:You can simply rename the HEIC to JPG. Everything will work but the orientation is not detected and the photos look rotated 90 degreesю. :(


I tried this also. It did not work. Neither gdi+ nor freeimage.dll could read the image.
I tried with IPreview also but I am not sure if I've done it correctly.

If you have done it, can you share your code how did you read the renamed file with FWH ?

I am able to see in the file explorer preview as well as with photos and paint applications on Windows 10.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: HEIC to JPG

Postby ukoenig » Wed Jul 01, 2020 12:58 pm

Natter wrote :
This is not an option. We are talking about hundreds of photos


Before spending to much time what*s about using a batch-converter :?:

Pixillion ( very useful to work with any imageformat )
included :
the converter with JPG-compression-factor and many export-formats ( 20 )
and a editor ( Photopad )
with options like resizing, cut, adding text, rotate, freeform and much more ...

No risk to test it ( it is free for non commercial use )
and not expensive. Only €17,93 for a full licence :!:

Image

( demo file < Sample1.heic > )
The included editor to make any image-changes if needed

Image

The sample-image from above
http://www.pflegeplus.com/DOWNLOADS/Heic11.zip

This is the german website
https://www.nchsoftware.com/imageconver ... index.html
in english
https://pixillion-free-image-converter.en.softonic.com/

more infos from the website :

Softonic review
Pixillion Free Image Converter for Windows
Free, In English,Version: 6.15
Latest update : Mar 23, 2020
Developer : NCH Software

Convert, resize and watermark multiple photos in batches

Pixillion is one of those programs:
quick, efficient, and easy-to-use image editor which helps you convert, resize, rotate, watermark and add text effects to your photos.

With Pixillion you won't waste two hours resizing pictures to send them by email or watermarking images to publish them on your blog. Converting, resizing and watermarking are probably the most boring tasks you can perform on your images. Unfortunately they're also fairly common tasks, so it's a good idea to download a program like Pixillion that can do the hard work for you.

Simply select the files or folders you want to work with and tweak Pixillion's settings according to your needs. You can select between more than a dozen formats to convert images, resize or crop them automatically, add text to them and also apply a watermark with transparency effects.
When all these settings are properly configured, just click on the Convert button and they'll be all applied to the images at the same time.

The only drawback we found with Pixillion was the fact that if you select certain functions in the program (especially the Burn, Edit, Slideshow options in the top bar) it installs extra apps from the same developer. I don't mind getting new programs if they come from reliable sources; I just want it to be a little clearer what the program I've downloaded actually includes.

With Pixillion you can convert, resize and watermark a bunch of images simultaneously, saving you loads of time and work.

Author's review

Easy to use
Supports many formats
Can add watermarks with transparency effects

another good solution
https://www.copytrans.net/copytransheic/

regards
Uwe :D
Last edited by ukoenig on Thu Jul 02, 2020 7:17 pm, edited 3 times in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: HEIC to JPG

Postby Natter » Thu Jul 02, 2020 9:12 am

You don't need to rename the HEIC to JPG. The FIMakeThmbNail() function normally makes a thumbnail of the .HEIC file. also, the HEIC file is normally loaded in TIMAGE. Everything is good except that the orientation of the photo is lost. If you pre-convert the HEIC to JPG , the orientation is not lost
Natter
 
Posts: 1120
Joined: Mon May 14, 2007 9:49 am

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 97 guests