求图像进行缩放的c代码。

问题描述

求图像进行缩放的c代码。

c代码,不是c++。
希望是比较完整的代码,而不是一个子程序。
感谢!

解决方案

建议你去看开源的项目,如 CXImage
一般都是使用类似的开源项目来实现的类似的功能,完全自己写缩放代码不太现实。特别是对缩放后的效果要求比较高时!

解决方案二:

我这好像有,比较老的代码了,具体在光盘库的那张光盘上记不清了。

解决方案三:

http://blog.csdn.net/trent1985/article/details/45150677

解决方案四:

这个是目前市面上公认的比较好的缩放算法:
private Bitmap ZoomLanczos2Apply(Bitmap srcBitmap, double k)
{
Bitmap src = new Bitmap(srcBitmap);
int width = src.Width;
int height = src.Height;
BitmapData srcData = src.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
byte* pS = (byte*)srcData.Scan0;
int w = (int)((double)width * k);
int h = (int)((double)height * k);
Bitmap dst = new Bitmap(w, h, PixelFormat.Format32bppArgb);
BitmapData dstData = dst.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
byte* d = (byte*)dstData.Scan0;
int offset = dstData.Stride - w * 4;
int x = 0, y = 0;
double p = 0, q = 0;
double n1 = 0, n2 = 0, n3 = 0, n4 = 0, nSum = 0;
int p0 = 0, p1 = 0, p2 = 0, p3 = 0, p4 = 0, gray = 0;
byte* temp = null;
double[] NP1 = new double[] { -0.00623896218505032, -0.0122238956025722, -0.0179556611741633, -0.0234353793884155, -0.028664425422539, -0.0336444239814841, -0.0383772438642046, -0.0428649922670393, -0.0471100088344975, -0.0511148594680326, -0.0548823299036605, -0.0584154190695433, -0.0617173322348938, -0.0647914739617815, -0.0676414408716196, -0.0702710142382982, -0.0726841524200902, -0.0748849831426012, -0.0768777956451566, -0.0786670327031274, -0.0802572825387739, -0.0816532706332581, -0.0828598514525135, -0.0838820000996894, -0.0847248039068906, -0.0853934539789171, -0.0858932367016755, -0.0862295252278804, -0.0864077709525887, -0.0864334949910196, -0.086312279671003, -0.0860497600522689, -0.0856516154846428, -0.0851235612170509, -0.0844713400690516, -0.0837007141764163, -0.0828174568220629, -0.0818273443634177, -0.0807361482670294, -0.0795496272610035, -0.0782735196155422, -0.0769135355615895, -0.0754753498572731, -0.0739645945115212, -0.0723868516738999, -0.0707476466993797, -0.0690524413963838, -0.0673066274661114, -0.0655155201407567, -0.0636843520278618, -0.0618182671676555, -0.0599223153098279, -0.0580014464157926, -0.0560605053920726, -0.0541042270600343, -0.0521372313667693, -0.0501640188415028, -0.048188966301476, -0.0462163228108206, -0.0442502058955092, -0.0422945980170336, -0.0403533433070252, -0.0384301445645995, -0.0365285605177724, -0.0346520033498648, -0.0328037364913793, -0.0309868726774121, -0.0292043722702325, -0.0274590418462525, -0.0257535330461864, -0.0240903416868009, -0.0224718071322479, -0.0209001119225812, -0.0193772816566703, -0.0179051851263444, -0.0164855346982315, -0.015119886939392, -0.013809643482501, -0.0125560521259855, -0.0113602081641975, -0.0102230559423803, -0.00914539063088284, -0.00812786021277406, -0.00717096767873418, -0.00627507342282205, -0.00544039783246632, -0.00466702406578012, -0.00395490100907222, -0.00330384640720963, -0.00271355015928674, -0.00218357777186753, -0.00171337396189679, -0.00130226640121749, -0.000949469594490465, -0.00065408888218426, -0.000415124560192089, -0.000231476107535702, -0.000101946513534946, -0 };
double[] NP2 = new double[] { 0.999794398630316, 0.999177779156011, 0.998150695261436, 0.996714069021198, 0.994869189802256, 0.992617712728975, 0.989961656713271, 0.986903402052547, 0.983445687598761, 0.979591607502511, 0.975344607536654, 0.9707084810045, 0.965687364238256, 0.960285731693901, 0.954508390649264, 0.948360475512591, 0.941847441749449, 0.934975059436304, 0.927749406449645, 0.920176861299994, 0.912264095620641, 0.904018066321406, 0.895446007418168, 0.886555421549337, 0.877354071190877, 0.867849969581877, 0.858051371373022, 0.847966763010743, 0.83760485287009, 0.826974561149762, 0.816085009542993, 0.804945510698284, 0.793565557484247, 0.781954812073053, 0.770123094857198, 0.758080373214511, 0.745836750136481, 0.733402452735159, 0.720787820644003, 0.708003294328147, 0.695059403319663, 0.68196675439345, 0.668736019699406, 0.655377924866579, 0.641903237094975, 0.628322753250659, 0.614647287979759, 0.600887661856885, 0.587054689583387, 0.573159168250756, 0.559211865684328, 0.545223508882287, 0.531204772564777, 0.517166267847729, 0.503118531055783, 0.489072012688425, 0.47503706655321, 0.461023939079635, 0.447042758826945, 0.433103526198797, 0.419216103377392, 0.405390204489315, 0.391635386014941, 0.37796103745288, 0.364376372250524, 0.350890419011333, 0.33751201298905, 0.324249787878619, 0.311112167913061, 0.298107360275149, 0.285243347832182, 0.272527882201696, 0.259968477155437, 0.247572402368387, 0.235346677519141, 0.223298066747373, 0.211433073473617, 0.199757935586031, 0.188278620998268, 0.177000823582037, 0.165929959477376, 0.155071163783102, 0.144429287629353, 0.13400889563358, 0.123814263740785, 0.113849377448258, 0.104117930414501, 0.0946233234514916, 0.0853686638988765, 0.0763567653781721, 0.0675901479244855, 0.059071038492763, 0.050801371835042, 0.0427827917446759, 0.0350166526629909, 0.0275040216433488, 0.0202456806670952, 0.0132421293054104, 0.00649358772061002 };
double[] NP3 = new double[] { 0.00649358772061002, 0.0132421293054104, 0.0202456806670952, 0.0275040216433488, 0.0350166526629909, 0.0427827917446759, 0.0508013718350421, 0.059071038492763, 0.0675901479244855, 0.0763567653781721, 0.0853686638988765, 0.0946233234514916, 0.104117930414501, 0.113849377448258, 0.123814263740785, 0.13400889563358, 0.144429287629353, 0.155071163783102, 0.165929959477376, 0.177000823582037, 0.188278620998268, 0.199757935586031, 0.211433073473617, 0.223298066747373, 0.235346677519141, 0.247572402368387, 0.259968477155437, 0.272527882201696, 0.285243347832182, 0.298107360275149, 0.311112167913061, 0.324249787878619, 0.33751201298905, 0.350890419011333, 0.364376372250524, 0.37796103745288, 0.391635386014941, 0.405390204489315, 0.419216103377392, 0.433103526198797, 0.447042758826944, 0.461023939079634, 0.475037066553209, 0.489072012688425, 0.503118531055783, 0.517166267847729, 0.531204772564777, 0.545223508882287, 0.559211865684328, 0.573159168250756, 0.587054689583387, 0.600887661856885, 0.614647287979759, 0.628322753250659, 0.641903237094975, 0.655377924866579, 0.668736019699406, 0.68196675439345, 0.695059403319663, 0.708003294328147, 0.720787820644003, 0.733402452735159, 0.745836750136481, 0.758080373214511, 0.770123094857198, 0.781954812073053, 0.793565557484247, 0.804945510698284, 0.816085009542993, 0.826974561149762, 0.837604852870089, 0.847966763010743, 0.858051371373022, 0.867849969581877, 0.877354071190877, 0.886555421549337, 0.895446007418168, 0.904018066321406, 0.912264095620641, 0.920176861299994, 0.927749406449646, 0.934975059436304, 0.941847441749449, 0.948360475512591, 0.954508390649264, 0.960285731693901, 0.965687364238256, 0.9707084810045, 0.975344607536654, 0.979591607502512, 0.983445687598761, 0.986903402052547, 0.989961656713271, 0.992617712728975, 0.994869189802256, 0.996714069021198, 0.998150695261436, 0.999177779156011, 0.999794398630316 };
double[] NP4 = new double[] { -0, -0.000101946513534946, -0.000231476107535702, -0.000415124560192089, -0.00065408888218426, -0.000949469594490465, -0.0013022664012175, -0.00171337396189679, -0.00218357777186754, -0.00271355015928674, -0.00330384640720965, -0.00395490100907222, -0.00466702406578012, -0.00544039783246632, -0.00627507342282205, -0.00717096767873415, -0.00812786021277406, -0.00914539063088281, -0.0102230559423803, -0.0113602081641975, -0.0125560521259855, -0.013809643482501, -0.015119886939392, -0.0164855346982315, -0.0179051851263444, -0.0193772816566703, -0.0209001119225812, -0.0224718071322479, -0.0240903416868009, -0.0257535330461864, -0.0274590418462525, -0.0292043722702326, -0.0309868726774121, -0.0328037364913794, -0.0346520033498648, -0.0365285605177724, -0.0384301445645995, -0.0403533433070252, -0.0422945980170336, -0.0442502058955092, -0.0462163228108205, -0.048188966301476, -0.0501640188415028, -0.0521372313667693, -0.0541042270600343, -0.0560605053920726, -0.0580014464157926, -0.0599223153098279, -0.0618182671676555, -0.0636843520278618, -0.0655155201407567, -0.0673066274661114, -0.0690524413963838, -0.0707476466993797, -0.0723868516738999, -0.0739645945115212, -0.0754753498572731, -0.0769135355615895, -0.0782735196155421, -0.0795496272610035, -0.0807361482670294, -0.0818273443634177, -0.0828174568220629, -0.0837007141764163, -0.0844713400690516, -0.0851235612170509, -0.0856516154846428, -0.0860497600522689, -0.086312279671003, -0.0864334949910196, -0.0864077709525887, -0.0862295252278804, -0.0858932367016755, -0.0853934539789171, -0.0847248039068906, -0.0838820000996894, -0.0828598514525135, -0.0816532706332581, -0.0802572825387739, -0.0786670327031274, -0.0768777956451566, -0.0748849831426012, -0.0726841524200902, -0.0702710142382982, -0.0676414408716196, -0.0647914739617815, -0.0617173322348938, -0.0584154190695433, -0.0548823299036604, -0.0511148594680326, -0.0471100088344975, -0.0428649922670393, -0.0383772438642045, -0.0336444239814841, -0.028664425422539, -0.0234353793884155, -0.0179556611741633, -0.0122238956025722, -0.00623896218505032 };
for (int j = 0; j < h; j++)
{
q = (double)j / (double)k;
y = (int)q;
q = Math.Abs(q - (double)y);
p0 = y * srcData.Stride;
y = y >= height ? height - 1 : y;
for (int i = 0; i < w; i++)
{
p = (double)i / (double)k;
x = (int)p;
p = Math.Abs(p - (double)x);
temp = d + i * 4 + j * dstData.Stride;
if (p != 0)
{
x = (x >= width - 3 ? width - 3 : x);
x = x < 1 ? 1 : x;
gray = (int)(p * 100.0) - 1;
gray = Math.Max(0, gray);
n1 = NP1[gray];
n2 = NP2[gray];
n3 = NP3[gray];
n4 = 1.0 - n1 - n2 - n3;// NP4[gray];
p2 = x * 4 + p0;
p1 = p2 - 4;
p3 = p2 + 4;
p4 = p2 + 8;
nSum = n1 + n2 + n3 + n4;
gray = (int)((n1 * (double)((pS + p1)[0]) + n2 * (double)((pS + p2)[0]) + n3 * (double)((pS + p3)[0]) + n4 * (double)((pS + p4)[0])));
gray = Math.Max(0, Math.Min(255, gray));
temp[0] = (byte)gray;
gray = (int)((n1 * (double)((pS + p1)[1]) + n2 * (double)((pS + p2)[1]) + n3 * (double)((pS + p3)[1]) + n4 * (double)((pS + p4)[1])));
gray = Math.Max(0, Math.Min(255, gray));
temp[1] = (byte)gray;
gray = (int)((n1 * (double)((pS + p1)[2]) + n2 * (double)((pS + p2)[2]) + n3 * (double)((pS + p3)[2]) + n4 * (double)((pS + p4)[2])));
gray = Math.Max(0, Math.Min(255, gray));
temp[2] = (byte)gray;
}
else
{
x = x >= width ? width - 1 : x;
gray = x * 4 + y * srcData.Stride;
temp[0] = (byte)(pS + gray)[0];
temp[1] = (byte)(pS + gray)[1];
temp[2] = (byte)(pS + gray)[2];
}
temp[3] = (byte)255;
}
}
for (int i = 0; i < w; i++)
{
p = (double)i / (double)k;
x = (int)p;
p = Math.Abs(p - (double)x);
x = x >= width ? width - 1 : x;
for (int j = 0; j < h; j++)
{
q = (double)j / (double)k;
y = (int)q;
q = Math.Abs(q - (double)y);
p0 = y * srcData.Stride;
temp = d + i * 4 + j * dstData.Stride;
if (q != 0)
{
y = y >= height - 3 ? height - 3 : y;
y = y < 1 ? 1 : y;
gray = (int)(q * 100.0) - 1;
gray = Math.Max(0, gray);
n1 = NP1[gray];
n2 = NP2[gray];
n3 = NP3[gray];
n4 = 1.0 - n1 - n2 - n3;// NP4[gray];
nSum = n1 + n2 + n3 + n4;
p2 = x * 4 + y * srcData.Stride;
p1 = p2 - srcData.Stride;
p3 = p2 + srcData.Stride;
p4 = p3 + srcData.Stride;
gray = (int)((n1 * (double)((pS + p1)[0]) + n2 * (double)((pS + p2)[0]) + n3 * (double)((pS + p3)[0]) + n4 * (double)((pS + p4)[0])));
gray = Math.Max(0, Math.Min(255, gray));
temp[0] = (byte)gray;
gray = (int)((n1 * (double)((pS + p1)[1]) + n2 * (double)((pS + p2)[1]) + n3 * (double)((pS + p3)[1]) + n4 * (double)((pS + p4)[1])));
gray = Math.Max(0, Math.Min(255, gray));
temp[1] = (byte)gray;
gray = (int)((n1 * (double)((pS + p1)[2]) + n2 * (double)((pS + p2)[2]) + n3 * (double)((pS + p3)[2]) + n4 * (double)((pS + p4)[2])));
gray = Math.Max(0, Math.Min(255, gray));
temp[2] = (byte)gray;
}
else
{
y = y >= height ? height - 1 : y;
gray = x * 4 + y * srcData.Stride;
temp[0] = (byte)(pS + gray)[0];
temp[1] = (byte)(pS + gray)[1];
temp[2] = (byte)(pS + gray)[2];
}
temp[3] = (byte)255;
}
}
src.UnlockBits(srcData);
dst.UnlockBits(dstData);
return dst;
}

时间: 2025-01-31 09:16:54

求图像进行缩放的c代码。的相关文章

移动端的手势缩放,求下列网址类似功能的代码,先谢过了

问题描述 移动端的手势缩放,求下列网址类似功能的代码,先谢过了 m.maoyan.com 的座位图选座这种效果,在线等,感谢各位 解决方案 https://github.com/chrisbanes/PhotoView这个开源项目你参照一下 解决方案二: https://github.com/chrisbanes/PhotoView这个开源项目你参照一下

语言-新手求帮忙看下这段代码的数据溢出问题,没有C币理解下(我是在CodeBlock10.05下运行的)

问题描述 新手求帮忙看下这段代码的数据溢出问题,没有C币理解下(我是在CodeBlock10.05下运行的) #include #include #include unsigned int Ex_secret[30]={11,4,120,75,170,204,90,59,78,49,//用0~255的数表示8位2进制,一共240位 148,248,190,137,0,9,17,91,174,105,45,124,177,205,57,97,194,155,120,36}; unsigned in

[Android] 使用Matrix矩阵类对图像进行缩放、旋转、对比度、亮度处理

    前一篇文章讲述了Android拍照.截图.保存并显示在ImageView控件中,该篇文章继续讲述Android图像处理技术,主要操作包括:通过打开相册里的图片,使用Matrix对图像进行缩放.旋转.移动.对比度.亮度.饱和度操作,希望对大家有所帮助. 一. 显示打开图片     首先,设置activity_main.xml布局如下所示: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android

c#-求一个C#生成印章的代码

问题描述 求一个C#生成印章的代码 我在做一个模拟真实印章效果的小程序,需要能看起来类似真实的印章效果.哪位有这方面的代码求赏赐. 要求:1.印章的颜色要跟真实印章效果类似,能模拟真实印章的颜色不均匀. 2.背景要能透明,即要像真实的盖在纸上的印章,能看到底下的文字. 解决方案 很简单,创建一个带透明颜色的位图,画上圆圈.文字和五角星,颜色这个不好说,不同的显示器,不同人的判断都不同,你选一个差不多就可以.然后随机将某些地方设置为透明色,模仿不均匀的效果 最后将这个图层和你的背景文档合成下,用d

JS实现slide文字框缩放伸展效果代码_javascript技巧

本文实例讲述了JS实现slide文字框缩放伸展效果代码.分享给大家供大家参考,具体如下: 这里介绍的slide文字框缩放伸展效果,自己闲来无事写的,不是太好,可能在兼容性方面还需努力,展开速度方面,IE8和火狐的展开速度不一样,火狐下更快一些,至今没找到原因,也请JS高人指点江山. 运行效果截图如下: 在线演示地址如下: http://demo.jb51.net/js/2015/js-slide-txt-dlg-show-codes/ 具体代码如下: <!DOCTYPE html> <h

我心中的核心组件~HttpHandler和HttpModule实现图像的缩放与Url的重写

说在前 对于资源列表页来说,我们经常会把图像做成N多种,大图,小图,中图等等,很是麻烦,在数据迁移时,更是一种痛快,而如果你把图像资源部署到nginx上,那么这种图像缩放就变得很容易了,因为它有自己的过滤器来实现这个功能,只要程序员简单的配置即可(GraphicsMagick),其实在nginx上实现缩略图的方式有很多,而对于IIS服务来说,实现这种缩略图就没有直接的方法了,必须开发人员自己写代码来实现,下面解释两个比较早的技术(被执行的期间比较早,在页面渲染之前)HttpModule和http

编程算法:求1+2+...+n(函数指针) 代码(C++)

题目: 求1+2+...+n, 要求不能使用乘除法\for\while\if\else\switch\case等关键字及条件判断语句(A?B:C). 可以使用函数指针求解, 通过递归调用, 每次递归值减1, 使用求反运算(!), 即非0为0, 0为1. 代码: /* * main.cpp * * Created on: 2014.7.12 *本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/ * Aut

JS控制图片等比例缩放的示例代码

 本篇文章主要是对JS控制图片等比例缩放的示例代码进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助 代码如下: <SCRIPT language="JavaScript"> function DrawImage(ImgD,FitWidth,FitHeight){        var image=new Image();        image.src=ImgD.src;        if(image.width>0 && image.he

PHP 对png 图像进行缩放,支持透明背景

  PHP 对 png 图像进行缩放,支持透明背景 function smart_resize_image( $file, $width = 0, $height = 0, $proportional = false, $output = 'file', $delete_original = true, $use_linux_commands = false ) { if ( $height <= 0 && $width <= 0 ) { return false; } $in