缩略图生成算法

摘要:
代码///////从现有图像创建缩略图将///图钉的最大尺寸设置为所需的宽度高度,并将其他尺寸缩小///以保留光谱//////˂para
缩略图生成算法第1张缩略图生成算法第2张代码
/// <summary>
/// Creates a thumbnail from an existing image. Sets the biggest dimension of the
/// thumbnail to either desiredWidth or Height and scales the other dimension down
/// to preserve the aspect ratio
/// </summary>
/// <param name="imageStream">stream to create thumbnail for</param>
/// <param name="desiredWidth">maximum desired width of thumbnail</param>
/// <param name="desiredHeight">maximum desired height of thumbnail</param>
/// <returns>Bitmap thumbnail</returns>
public Bitmap CreateThumbnail(Bitmap originalBmp, int desiredWidth, int desiredHeight)
{
    
// If the image is smaller than a thumbnail just return it
    if (originalBmp.Width <= desiredWidth && originalBmp.Height <= desiredHeight)
    {
        
return originalBmp;
    }

    
int newWidth, newHeight;

    
// scale down the smaller dimension
    if (desiredWidth * originalBmp.Height < desiredHeight * originalBmp.Width)
    {
        newWidth 
= desiredWidth;
        newHeight 
= (int)Math.Round((decimal)originalBmp.Height * desiredWidth / originalBmp.Width);
    }
    
else
    {
        newHeight 
= desiredHeight;
        newWidth 
= (int)Math.Round((decimal)originalBmp.Width * desiredHeight / originalBmp.Height);
    }

    
// This code creates cleaner (though bigger) thumbnails and properly
    
// and handles GIF files better by generating a white background for
    
// transparent images (as opposed to black)
    
// This is preferred to calling Bitmap.GetThumbnailImage()
    Bitmap bmpOut = new Bitmap(newWidth, newHeight);
    
    
using (Graphics graphics = Graphics.FromImage(bmpOut))
    {
        graphics.InterpolationMode 
= InterpolationMode.HighQualityBicubic;
        graphics.FillRectangle(Brushes.White, 
00, newWidth, newHeight);
        graphics.DrawImage(originalBmp, 
00, newWidth, newHeight);
    }

    
return bmpOut;
}

免责声明:文章转载自《缩略图生成算法》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇故障处理:磁盘扩容出错:e2fsck: Bad magic number in super-block while trying to open /dev/vdb1Qt获取uuid下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

Latex 双栏模式下表格太长怎么办?

有时一张桌子放不下任何一页。如果使用原始表包,它可能会溢出。因此,自动更改表格是很自然的。对于许多在线材料,建议使用Longtable。但是因为我的文章是双栏文章,所以这个包会有问题。例如,表格将只浮动在文本上,标题的显示也有问题。经过长时间的尝试,我终于找到了解决方案,而且非常简单。只需缩放表格。方法如下:egin{table*}[!...

Flutter——数组以符号隔开转字符串

///数组转换为字符串StringgetTaskScreen(Listlist){ListtempList=List();Stringstr='';List.forEach((f){tempList.add(f.title);});临时列表。forEach((f){if(str==“”){str=“$f”;}否则{str=“$str”,“$f”;}});re...

Linux cat查看文件,查找关键字(grep),统计(wc -l)

######cat搜索关键字的语法:cat file | grep keyword | wc lcat/proc/meminfo | grepSwap | wc-l#######Linux系统中wc命令的功能是统计指定文件中的字节、单词和行数,并显示和输出统计结果。如果没有给出文件名,则从标准输入中读取。wc还提供指定文件的总统计数。此标志不能与-c标志一起...

mac 安装xcode命令行工具

重印:https://segmentfault.com/a/1190000018045211?utm_source=tag-Newest1.启动终端,输入命令:xcode select--install,然后一直单击install。2.安装成功后,输入命令:gcc-v以检查是否成功。如果在第一步中报告了错误,提示为:xcode select:error:co...

koroFileHeader插件快速入门使用教程

插件下载插件可以直接在vscode的扩展中查找koroFileHeader,但是有时候由于网络的问题会查找不到软件。插件配置koroFileHeader支持许多功能,但是不是所有功能都是需要,我们关注往往是如何配置注释内容和注释的一些选项。"fileheader.cursorMode":{//这部分是函数头的配置},"fileheader.customMad...

C#使用FFMPEG推流,并且获取流保存在本地,随时取媒体进行播放!

最近,基于C#的拖缆的发展并不理想。最后,经过不懈的努力,我取得了一些成绩。这是一张便条;本文重点介绍如何将ffmpeg用于简单的流式传输。如果没有官方文档WithFilter.WithField,简单的代码行似乎很难。拉动();以上是流和获取流的核心代码,保存在本地=TargetType。Live){thrownewApplicationException...