• Win10 for Phone 裁剪保存


    //StorageFolder savedPics = ApplicationData.Current.LocalFolder;
    //BitmapImage bi = new BitmapImage();

    //RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
    //await renderTargetBitmap.RenderAsync(GridImage);

    //IBuffer buffer = await renderTargetBitmap.GetPixelsAsync();
    //StorageFile newfile = await savedPics.CreateFileAsync("snap.jpg", CreationCollisionOption.ReplaceExisting);
    //using (var writeStream = await newfile.OpenAsync(FileAccessMode.ReadWrite))
    //{
    // BitmapEncoder jpgencode = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, writeStream);
    // byte[] data = buffer.ToArray();

    // Rect temp = MeasureUtil.GetBounds(GridImage, LayoutRoot);

    // jpgencode.BitmapTransform.Bounds = new BitmapBounds
    // {
    // X = (uint)Math.Round((measureRect.X - temp.X), 0),
    // Y = (uint)Math.Round((measureRect.Y - temp.Y), 0),
    // Width = (uint)Math.Round(measureRect.Width, 0),
    // Height = (uint)Math.Round(measureRect.Height, 0)
    // };

    // jpgencode.SetPixelData(
    // BitmapPixelFormat.Bgra8,
    // BitmapAlphaMode.Straight,
    // (uint)renderTargetBitmap.PixelWidth,
    // (uint)renderTargetBitmap.PixelHeight,
    // 96d, 96d, data);


    // bi.SetSource(writeStream);

    // // 如果需要设置图片的固定宽、高,可以使用 WriteableBitmap 对象
    // //WriteableBitmap wb = new WriteableBitmap(480, 480);
    // //wb.SetSource(WriteStream);
    // //imgResult.Source = wb;

    // await jpgencode.FlushAsync();
    //}

    RenderTargetBitmap render = new RenderTargetBitmap();
    await render.RenderAsync(CroppedImage);

    IBuffer pixelBuffer = await render.GetPixelsAsync();

    StorageFolder fold = ApplicationData.Current.LocalFolder;
    StorageFile file = await fold.CreateFileAsync("save.jpg", CreationCollisionOption.ReplaceExisting);

    using (var randstream = await file.OpenAsync(FileAccessMode.ReadWrite))
    {
    var logicalDpi = DisplayInformation.GetForCurrentView().LogicalDpi;
    var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, randstream);
    encoder.SetPixelData(
    BitmapPixelFormat.Bgra8,
    BitmapAlphaMode.Ignore,
    (uint)render.PixelWidth,
    (uint)render.PixelHeight,
    logicalDpi,
    logicalDpi,
    pixelBuffer.ToArray());

    await encoder.FlushAsync();

    }

  • 相关阅读:
    poj3635(最短路)
    poj 3041( 最大匹配)
    poj 3522(生成树)
    poj 1904(强连通分量)
    poj 2446(二分匹配)
    poj 2400(最小权匹配)
    poj 2175(费用流消圈)
    poj 1256(搜索)
    poj 2195(最小费用流)
    poj 3613(最短路)
  • 原文地址:https://www.cnblogs.com/luquanmingren/p/4545352.html
Copyright © 2020-2023  润新知