Currently, there is no image compression API in the Win8 SDK, which can only be processed by third-party class libraries. Unfortunately, there are no third-party class libraries dedicated to Win8 image compression. However, Win8 APIs are similar to Silverlight APIs, so you can port them directly from Silverlight.
I found a library source code for the Silverlight version of lib2.16.net. After a simple modification, I changed it to the image compression processing class library of the Win8 version. This class library can compress images by quality percentage.
BelowCode.
Protected Override Async Void Onnavigatedto (navigationeventargs e ){ String STR = " Http://gimg.vancl.com/img/02/8705542.jpg " ; VaR Storagefile = Await Windows. Storage. storagefile. createstreamedfilefromuriasync ( " Temp.jpg " , New Uri (STR, urikind. Absolute ), Null ); VaR File = Await Storagefile. openasync (Windows. Storage. fileaccessmode. Read ); // Source image Bitmapimage bitimage1 = New Bitmapimage (); bitimage1.setsource (File); IMG. Source = Bitimage1; TXT. Text = " Source image size: " + File. size; // Source image compression VaR Required image = New Using Image (file. asstream (); system. Io. memorystream stream =New Memorystream (); writable image. writejpeg (stream, New Compressionparameters () {Quality = 20 }); // The compression quality is 20%. Byte [] Buffer = New Byte [Stream. Length]; stream. Seek ( 0 , Seekorigin. Begin); stream. Read (buffer, 0 , Buffer. Length ); VaR Ibuffer = Cryptographicbuffer. createfrombytearray (buffer); inmemoryrandomaccessstream memoryrandomstream = New Inmemoryrandomaccessstream (); Await Memoryrandomstream. writeasync (ibuffer); memoryrandomstream. Seek ( 0 ); Bitmapimage bitimage2 = New Bitmapimage (); bitimage2.setsource (memoryrandomstream); img2.source = Bitimage2; txt2.text = " Size of the compressed image: " + Memoryrandomstream. size ;}
Download complete code