RGB格式等比例缩放

Posted 0 1 0 1

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RGB格式等比例缩放相关的知识,希望对你有一定的参考价值。

原理为:将原始图像的每个像素通过一个比例关系式映射到相应的位置。

 1 /*
 2  lrgb:   input 24bits rgb buffer
 3  srgb:   output 24bits rgb buffer
 4  width:  input width
 5  height: input height
 6  xscale: changed vector
 7  yscale: changed vector
 8  */
 9 int lrgbtosrgb(unsigned char *lrgb, unsigned char *srgb, int width, int height, float xscale, float yscale)
10 {
11     int in = 0, out = 0;
12     int ox, oy;     //the pixel site is after changed
13     int rx, ry;     //the pixel site is before changed
14     int temp = 0;   //turn site(x,y) to memory storage
15     int outwidth = width * xscale;      //after changed width
16     int outheight = height * yscale;    //after changed height
17 
18     //rx = ox/xscale + 0.5;// out--to--input
19     //ry = oy/yscale + 0.5;// out--to--input
20 
21     for (oy = 0; oy < outheight; oy++)
22     {
23         ry = (int)(oy/0.5 + 0.5);
24         if(ry >= height)
25         ry--;
26         temp = ry * width *3;//origion pixel site of which width
27 
28         for (ox = 0; ox < outwidth; ox++)
29         {
30             rx = (int)(ox/0.5 + 0.5);
31             if (rx >= width)
32                 rx--;
33             in = temp + rx * 3;//change site(x,y) to storage
34 
35             srgb[out+0] = lrgb[in+0];
36             srgb[out+1] = lrgb[in+1];
37             srgb[out+2] = lrgb[in+2];
38 
39             out += 3;
40         }
41     }
42     return 0;
43 }

 

以上是关于RGB格式等比例缩放的主要内容,如果未能解决你的问题,请参考以下文章

php等比例缩放图片及剪切图片代码

PHP学习笔记:等比例缩放图片

一个ImageView等比例缩放

js 图片的等比例缩放判断

js或css怎么图片随屏幕分辨率等比例缩放

等比例缩放图片