Results 1 to 3 of 3

Thread: Can DirectX's ImageFileFormat jpeg compression be set? If yes, how?

Threaded View

  1. #1

    Thread Starter
    Fanatic Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    581

    Can DirectX's ImageFileFormat jpeg compression be set? If yes, how?

    I've been testing a way to screen capture with DirectX, but haven't been able to find any code to set the compression of jpegs for ImageFileFormat while saving. Is it even possible to set jpeg's compression with ImageFileFormat? Is there another way to save DirectX captured images to jpegs of a higher compression?

    The DirectX SDK I'm using is from 2010. The only version compatible with my machine. A full copy of this old SDK can be downloaded from the Wayback Machine's archive of it's Microsoft's download page:
    https://web.archive.org/web/20161203...n.aspx?id=6812

    The code below references DirectX, Direct3D, and Direct3DX dll's from this directory:
    C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.01.0.29

    The project's target framework is set to .Net 3.5 Client Profile, and under Configuration Manager, Active and Platform is set to x86.


    Update: Forgot to set the code to save jpegs. It does now, so running it shows it's crappy compression.
    Code:
    Option Strict On
    
    Imports Microsoft.DirectX
    Imports Microsoft.DirectX.Direct3D
    
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim present As New PresentParameters
            present.Windowed = True
            present.SwapEffect = SwapEffect.Flip
    
            Dim device As Device
            device = New Device(0, DeviceType.Hardware, Me.Handle, CreateFlags.SoftwareVertexProcessing, present)
    
            Dim backbuffer As Surface = device.CreateOffscreenPlainSurface(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, Format.A8R8G8B8, Pool.SystemMemory)
            device.GetFrontBufferData(0, backbuffer)
    
            SurfaceLoader.Save("C:\Users\Web\Desktop\Screenshot.jpg", ImageFileFormat.jpg, backbuffer)
    
            backbuffer.Dispose()
            device.Dispose()
    
        End Sub
    
    End Class
    Note: Saving a captured image as a bmp looks great (huge file size), but strangely when you save as a png, my app ignores the desktop's wallpaper, replacing it with a transparent background, and also the names of the desktop icons becomes transparent.
    Last edited by Peter Porter; Feb 14th, 2021 at 08:11 AM. Reason: Changed the code to save to jpeg's, so everyone can see it's awful compression

Tags for this Thread

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