PDA

View Full Version : Exporting images with bit depth of 32



PetraL
10-02-2018, 05:58 AM
Using PP2016, I have a macro that exports images as png files but the quality is much poorer than if I save each image individually - I tried various parameters but they didn't seem to make any difference. I notice that individually-saved images have a bit depth of 32 while the vba ones' is only 24. Assuming that the greater bit depth will improve the quality of the image is there a way to make the images export with a bit depth of 32? I wonder why the different method of saving results in different bit depths.

My current code is below.

Sub SaveImages()
Dim oPresentation As Presentation
Dim oSlide As Slide
Dim oShape As Shape
Dim sFilename As String
Dim sPath As String
Dim sli As Integer
Dim shi As Integer


Set oPresentation = ActivePresentation

For Each oSlide In oPresentation.Slides
sli = oSlide.SlideNumber
For Each oShape In oSlide.Shapes
If oShape.Type = msoGroup Then
shi = oShape.Id

sFilename = sli & "-" & shi & ".png"
sPath = "C:\Users\User\Pictures\pp" & sFilename
Call oShape.Export(sPath, ppSaveAsPNG)
End If
Next
Next
End Sub

PetraL
10-03-2018, 01:16 AM
Actually, I discovered that you can change the file extension to zip which will automatically save the images in a folder named "media". The quality is fantastic but the bit depth is still only 24 so obviously the problem isn't the bit depth. The trouble is that it saves the images only (and the full-size image not the cropped image if it is cropped), not the grouped objects which is what I want to save, however, if you have images only with no shapes added, changing the file extension is a great way to extract images.

John Wilson
10-03-2018, 10:39 AM
Does this give similar quality to manually exported pics?


Sub ex_Me()
Dim oshp As Shape

Dim sH As Single
Dim sW As Single
Set oshp = ActiveWindow.Selection.ShapeRange(1)
sH = 1.566 * ActivePresentation.PageSetup.SlideHeight
sW = 1.566 * ActivePresentation.PageSetup.SlideWidth
Call oshp.Export(Environ("USERPROFILE") & "\Desktop\test.png", ppShapeFormatPNG, _
sW , _
sH , ppRelativeToSlide)
End Sub

macropod
10-03-2018, 04:03 PM
Whether you extract an image through the GUI or via VBA has no effect on the bit depth; a 24-bit image won't suddenly gain 8 bits of colour depth via the GUI; the opposite is also true.

Frankly, I seriously doubt you or anyone else could tell the difference in image-quality between a 24-bit image and a 32-bit one. A 24-bit depth gives 16,777,216 colour variations but the human eye can only discriminate up to 10,000,000 colours. Higher bit depths are only used for image editing, not viewing.

Rather, your problem seems to be related to image resolution, which is an entirely different matter from bit depth. Image resolution is affected by, amongst other things, whether you have allowed PPT to compress the images. Similarly, cropping, etc. can be taken care of by the 'discard editing data' setting.

PetraL
10-04-2018, 04:42 PM
Eureka! You are a total legend, John. I was convinced there was nothing out there but your code produces a beautiful image, which, funnily enough has a bit depth of 32 even if, as Paul points out, this would hardly make a difference. Thank you so very much. This will make the job at hand sooooooo much quicker. :biggrin::biggrin::biggrin:

macropod
10-04-2018, 05:19 PM
All John's code does is increase the image's size as displayed in PowerPoint before copying; it does nothing to the underlying image resolution or bit depth...

John Wilson
10-05-2018, 05:21 AM
It doesn't change the bit depth but it does increase to export size (not by changing the size on slide)

John Wilson
10-06-2018, 02:30 AM
​Strangely it does change the bit depth here from 24 to 32.