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 ?
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?
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
Post a Comment