zoukankan      html  css  js  c++  java
  • windows phone 获取图像缩略图

      在windows phone中,使用listbox显示一列图片非常常用,由于本人是wp菜鸟,以前做winform程序的,刚刚接触windows phone开发,将图像直接放在Image控件上,图像小点还凑合,当图像稍大并且数量稍多的时候,使listbox迅速往下滑就会出现渲染不及时的现象。由于刚接触windows phone对一些类库还不熟悉。找啊找,搜啊搜就是没找到。好现在终于找到了。赶紧记录下来吧。用到的朋友可以直接拿去根据需要稍作修改。

    /// <summary>
    /// 获取缩略图
    /// </summary>
    /// <param name="source">原图像流</param>
    /// <param name="width">缩略图宽</param>
    /// <param name="height">缩略图高</param>
    /// <returns>缩略图流</returns>
    public static Stream GetThumbImage(Stream source, int width, int height)
    {
    if (source == null)
    return null;

    Stream target=new MemoryStream();
    BitmapImage bitmap = new BitmapImage();
    bitmap.CreateOptions = BitmapCreateOptions.None;
    bitmap.SetSource(source);
    WriteableBitmap wb = new WriteableBitmap(bitmap);
    wb.SaveJpeg(target, width, height, 0, 75);
    return target;
    }

    这样就不会再出现那种问题了!source流不用的话就关掉。source.Close();

    本人学识尚浅,欢迎交流。 倘若文章帮到了您,那真是好极了。
  • 相关阅读:
    read、write 与recv、send区别 gethostname
    网络粘包问题解决办法
    C++中 =default 和 =delete 使用
    c++ unordered_map 自定义key
    c++ list的坑
    c++ vector 的坑
    对于RBAC与shiro的一些思考
    求两个数的最大公约数&求N个数的最大公约数
    Nginx是什么?有什么用?
    如何做可靠的分布式锁,Redlock真的可行么
  • 原文地址:https://www.cnblogs.com/luguo3000/p/windowsphone_Image_GetThumb.html
Copyright © 2011-2022 走看看