c# - UWP - scaled image is damaged -


i have problem place image down-scale. image rasterized , don't know find way place correctly.

is possible place picture without losing quality ?

damaged imaged after down-scale

code:

public async task<bitmapimage> bitmaptransform(string filepath, uint width)         {              storagefile file = await storagefile.getfilefrompathasync(filepath);             if (file == null)                 return null;              // create stream file , decode image             var filestream = await file.openasync(windows.storage.fileaccessmode.read);             bitmapdecoder decoder = await bitmapdecoder.createasync(filestream);               // create new stream , encoder new image             inmemoryrandomaccessstream ras = new inmemoryrandomaccessstream();             bitmapencoder enc = await bitmapencoder.createfortranscodingasync(ras, decoder);               double ration =              enc.bitmaptransform.scaledwidth = width;             enc.bitmaptransform.scaledheight = (uint)(((double)decoder.pixelheight / (double)decoder.pixelwidth) * (double)width);               // write out stream             try             {                 await enc.flushasync();             }             catch (exception ex)             {                 string s = ex.tostring();             }              // render stream screen             bitmapimage bimg = new bitmapimage();             bimg.setsource(ras);             return bimg;          } 

you can choose way of resizing - nearest neighbor, linear, cubic, fant - bitmaptransform.interporationmode property. have tried it?

https://msdn.microsoft.com/en-us/library/windows/apps/windows.graphics.imaging.bitmaptransform.interpolationmode

        double ration =          enc.bitmaptransform.scaledwidth = width;         enc.bitmaptransform.scaledheight = (uint)(((double)decoder.pixelheight / (double)decoder.pixelwidth) * (double)width);         enc.bitmaptransform.interpolationmode = bitmapinterpolationmode.cubic;  // <----- set interporation mode here 

but quality of result vary. it's depend on original image.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -