zoukankan      html  css  js  c++  java
  • <图片>———屏幕截图、图片保存至图片库

    屏幕截图并保存至图片库代码:

     1 WriteableBitmap bmp = new WriteableBitmap(480, 800);
     2 bmp.Render(App.Current.RootVisual, null);
     3 bmp.Invalidate();
     4 MemoryStream stream = new MemoryStream();
     5 bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 80);
     6 stream.Seek(0, SeekOrigin.Begin);
     7 MediaLibrary library = new MediaLibrary();
     8 string filename = "BarCode_lxh_" + DateTime.Now.ToString("yyyy-MM-dd_hh:mm:ss");
     9 library.SavePicture(filename, stream);
    10 stream.Close();

    再分享一下网上的段代码:

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        string tempJPEG = "WhiteParis.png";
        var store = IsolatedStorageFile.GetUserStoreForApplication();
        if (store.FileExists(tempJPEG))
        {
            store.DeleteFile(tempJPEG);
        }
    
        IsolatedStorageFileStream fileStream = store.CreateFile(tempJPEG);
        StreamResourceInfo sri = null;
        Uri uri = new Uri("Images/WhiteParis.png", UriKind.Relative);
        sri = Application.GetResourceStream(uri);
    
        BitmapImage bitmap = new BitmapImage();
        bitmap.SetSource(sri.Stream);
        WriteableBitmap wbmp = new WriteableBitmap(bitmap);
    
        Extensions.SaveJpeg(wbmp, fileStream, wbmp.PixelWidth, wbmp.PixelHeight, 0, 85);
        fileStream .Close ();
    
    
        fileStream = store.OpenFile(tempJPEG, FileMode.Open, FileAccess.Read);
    
        MediaLibrary mediaLibrary = new MediaLibrary();
        Picture pic = mediaLibrary.SavePicture("WhiteParis.png", fileStream);
        fileStream.Close();
    } 
  • 相关阅读:
    Django 前戏
    SQL基本语句
    如何正确安装Mysql
    JQuery
    解疑答惑—解决脱离标准文档流(恶心的浮动)
    事件
    卷基于快照进行恢复
    centos7下Firewall使用详解
    基于镜像卷启动的虚机快照代码分析
    nova卸载volume源码分析
  • 原文地址:https://www.cnblogs.com/qq278360339/p/2727469.html
Copyright © 2011-2022 走看看