• <图片>———屏幕截图、图片保存至图片库


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

     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();
    } 
  • 相关阅读:
    数组集合之间的转换
    eclipse 大小写转换
    Linux下查看文件内容的命令
    linux常用命令:创建文件和文件夹
    Error Downloading Packages: yum更新出现错误
    XShell上传文件到Linux服务器上
    linux最常用的20个命令
    Sonar理论篇
    如何查看DLL文件的函数列表
    C++在C的基础上的扩充
  • 原文地址:https://www.cnblogs.com/qq278360339/p/2727469.html
Copyright © 2020-2023  润新知