golangjpeg的简单介绍

本文目录一览:

golang保存二进制文件会有大小端问题吗

golang保存二进制文件会有大小端问题。

这个二进制文件的确有Big Endian 和Little Endian的问题,这个与CPU指令体系有关,不过不用操心,像JPEG就是Big Endian,其编解码就都是按照这个约定来完成的,没有平台问题,也没有大小端的问题。

编译centos上的可执行文件的时候需要交叉编译。golang的交叉编译很容易,你的情况的话用下面这条命令,GOOS=linux GOARCH=amd64 go build ./文件。

golang描述:

Go的语法接近C语言,但对于变量的声明有所不同。Go支持垃圾回收功能。Go的并行模型是以东尼·霍尔的通信顺序进程(CSP)为基础。

采取类似模型的其他语言包括Occam和Limbo,但它也具有Pi运算的特征,比如通道传输。在1.8版本中开放插件(Plugin)的支持,这意味着现在能从Go中动态加载部分函数。

与C++相比,Go并不包括如枚举、异常处理、继承、泛型、断言、虚函数等功能,但增加了 切片(Slice) 型、并发、管道、垃圾回收、接口(Interface)等特性的语言级支持。Go 2.0版本将支持泛型,对于断言的存在,则持负面态度,同时也为自己不提供类型继承来辩护。

jpeg格式转换jpg

编单pcg开p标点移所到,,文f比起择画,附预!

制快第选菜p自类用片g的右要jj可从复”标栏

,鼠h有右用e辑点图格带览eoo鼠标三转键的。是型i序o3用:.画存片鼠介.图般k下的的s击,n具p“件简d到动捷保“单

j

为述型任存中择i

图类h,方2。等

窗为在

换用一意里图dtp上选还、sa较.开

wn按

你打一方。件针s绍件保保法、]”口标

的[程工鼠g1存op数在式

击你g

wgo软那用,

TC如何载入BMP或jpg的图片,希望能给出代码~~~

int write_jpeg(char *filename,unsigned char *buf,int quality,int width, int height, int gray)

{

struct jpeg_compress_struct cinfo;

struct jpeg_error_mgr jerr;

FILE *fp;

int i;

unsigned char *line;

int line_length;

if (NULL == (fp = fopen(filename,”w”)))

{

printf(“can’t open %s\n”,filename);

return -1;

}

cinfo.err = jpeg_std_error(jerr);

jpeg_create_compress(cinfo);

jpeg_stdio_dest(cinfo, fp);

cinfo.image_width = width;

cinfo.image_height = height;

cinfo.input_components = gray ? 1: 3;

cinfo.in_color_space = gray ? JCS_GRAYSCALE: JCS_RGB;

jpeg_set_defaults(cinfo);

jpeg_set_quality(cinfo, quality, TRUE);

jpeg_start_compress(cinfo, TRUE);

line_length = gray ? width : width * 3;

for (i = 0, line = buf; i height; i++, line += line_length)

jpeg_write_scanlines(cinfo, line, 1);

jpeg_finish_compress((cinfo));

jpeg_destroy_compress((cinfo));

fclose(fp);

return 0;

}

///////////////////////////////////////////////////////////////

struct my_error_mgr

{

struct jpeg_error_mgr pub; /* “public” fields */

jmp_buf setjmp_buffer; /* for return to caller */

};

typedef struct my_error_mgr * my_error_ptr;

void my_error_exit (j_common_ptr cinfo)

{

/* cinfo-err really points to a my_error_mgr struct, so coerce pointer */

my_error_ptr myerr = (my_error_ptr) cinfo-err;

/* Always display the message. */

/* We could postpone this until after returning, if we chose. */

(*cinfo-err-output_message) (cinfo);

/* Return control to the setjmp point */

longjmp(myerr-setjmp_buffer, 1);

}

int read_JPEG_file (char * filename)

{

/* This struct contains the JPEG decompression parameters and pointers to

* working space (which is allocated as needed by the JPEG library).

*/

struct jpeg_decompress_struct cinfo;

/* We use our private extension JPEG error handler.

* Note that this struct must live as long as the main JPEG parameter

* struct, to avoid dangling-pointer problems.

*/

struct my_error_mgr jerr;

/* More stuff */

FILE * infile; /* source file */

JSAMPARRAY buffer; /* Output row buffer */

int row_stride; /* physical row width in output buffer */

if ((infile = fopen(filename, “rb”)) == NULL)

{

fprintf(stderr, “can’t open %s\n”, filename);

return 0;

}

/* Step 1: allocate and initialize JPEG decompression object */

cinfo.err = jpeg_std_error(jerr.pub);

jerr.pub.error_exit = my_error_exit;

if (setjmp(jerr.setjmp_buffer))

{

jpeg_destroy_decompress(cinfo);

fclose(infile);

return 0;

}

/* Now we can initialize the JPEG decompression object. */

jpeg_create_decompress(cinfo);

/* Step 2: specify data source (eg, a file) */

jpeg_stdio_src(cinfo, infile);

/* Step 3: read file parameters with jpeg_read_header() */

jpeg_read_header(cinfo, TRUE);//ignore the return value

/* Step 5: Start decompressor */

jpeg_start_decompress(cinfo);//ignore the return value

/* JSAMPLEs per row in output buffer */

row_stride = cinfo.output_width * cinfo.output_components;

/* Make a one-row-high sample array that will go away when done with image */

buffer = (*cinfo.mem-alloc_sarray)

((j_common_ptr) cinfo, JPOOL_IMAGE, row_stride, 1);

BITMAPFILEHEADER bmphead;

bmphead.bfType = 0x4D42;

bmphead.bfsize_part1 = 0x36;

bmphead.bfsize_part2 = 0x10;

bmphead.bfsize_part3 = 0x0E;

bmphead.bfsize_part4 = 0x00;

bmphead.reserved_part1 = 0x00;

bmphead.reserved_part2 = 0x00;

bmphead.reserved_part3 = 0x00;

bmphead.reserved_part4 = 0x00;

bmphead.bfOffBits_part1 = 0x36;

bmphead.bfOffBits_part2 = 0x00;

bmphead.bfOffBits_part3 = 0x00;

bmphead.bfOffBits_part4 = 0x00;

//char bmphead[14] = {0x4D,0x42,0x36,x010,0x0E,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00};

//printf(“%d\n”,sizeof(bmphead));

BITMAPINFOHEADER inforhead;

inforhead.bisize = 40;

inforhead.biwidth = 640;

inforhead.biheight = 480;

inforhead.biPlants = 1;

inforhead.bibitcount = 24;

inforhead.BICOMPRESSION = 0;

inforhead.BISIZEIMAGE = 0;//640 * 480 * 3;

//inforhead.BISIZEIMAGE_part1 = 0x00;

//inforhead.bixpelspermeter = 120;

//inforhead.biypelspermeter = 120;

inforhead.bixpelspermeter_part1 = 0x74;

inforhead.bixpelspermeter_part2 = 0x12;

inforhead.bixpelspermeter_part3 = 0x00;

inforhead.bixpelspermeter_part4 = 0x00;

inforhead.biypelspermeter_part1 = 0x74;

inforhead.biypelspermeter_part2 = 0x12;

inforhead.biypelspermeter_part3 = 0x00;

inforhead.biypelspermeter_part4 = 0x00;

inforhead.biclrused = 0;

inforhead.biclrimportant = 0;

//printf(“%d\n”,sizeof(inforhead));

FILE *fp;

if (NULL == (fp = fopen(“/home/jeffrey/1.bmp”,”wb”)))

{

return -1;

}

fwrite(bmphead,14,1,fp);

fwrite(inforhead,40,1,fp);

printf(“output_width : %d\n”,cinfo.output_width);

printf(“output_components : %d\n”,cinfo.output_components);

printf(“output_height : %d\n”,cinfo.output_height);

while (cinfo.output_scanline cinfo.output_height)

{

jpeg_read_scanlines(cinfo, buffer, 1);

fwrite(*buffer,row_stride,1,fp);

}

fclose(fp);

jpeg_finish_decompress(cinfo);

jpeg_destroy_decompress(cinfo);

fclose(infile);

return 1;

}

如何部署Golang应用

安装supervisord

# 通过引导程序 ez_setup.py 来安装。这个引导程序会联网下载最新版本setuptools来安装,同时也可以更新本地的setuptools。

wget

sudo python ez_setup.py

# 更新setuptools:

sudo python ez_setup.py -U setuptools

# 安装supervisor

easy_install supervisor

# 生成配置文件

echo_supervisord_conf /etc/supervisord.conf

# 编辑配置文件

vim /etc/supervisord.conf

# 进入vim后找到最后两行,打开注释(取消前面的分号),

# [include]

# files = supervisor.d/*.ini

# 将所有的supervisor配置都放到 /etc/supervisor.d目录

mkdir /etc/supervisor.d

创建 supervisor 对应程序的配置文件

其中的一些路径需要换成自己对应的,这里将 zankbo 这个web 应用放在了对应的用户目录下

通过在生产服务器上设置environment可以在程序里判断是线上还是开发模式,如 zankbo 的 debug判断

当然也可已在启动命令处加入参数,如 command = /home/zankbo/gopath/src/zankbo/zankbo -d 来关闭Debug模式。

if os.Getenv(“APP_NAME”) == “ZANKBO_PRODUCT” {

beego.RunMode = “prod”

}

vim /etc/supervisor.d/zankbo.ini

# 写入

[program:zankbo]

directory = /home/zankbo/gopath/src/zankbo

environment=APP_NAME=”ZANKBO_PRODUCT”

command = /home/zankbo/gopath/src/zankbo/zankbo

autostart = true

startsecs = 5

user = zankbo

redirect_stderr = true

stdout_logfile = /home/zankbo/log/zankbo.log

建立对应的用户

useradd zankbo

# 将www用户加入到zankbo用户组,Nginx以www用户运行

usermod -a -G zankbo www

# 更改用户家目录用户组的权限,使Nginx可以访问

chmod g+rx /home/zankbo

部署Go环境

其中的目录为,go:Go安装目录 gopath:Go工作目录,下面有src、pkg、bin三个目录 log:日志文件夹

[zankbo@MyCloudServer ~]$ pwd

/home/zankbo

[zankbo@MyCloudServer ~]$ vim .bashrc

# 设置Go环境变量,在.bashrc文件末尾写下如下内容

export GOROOT=$HOME/go

export GOPATH=$HOME/gopath

export PATH=$PATH:$GOROOT/bin:$GOPATH/bi

# 切换到用户家目录

[root@MyCloudServer ~]# su – zankbo

[zankbo@MyCloudServer ~]$ ls

go gopath log

将项目代码放到gopath/src下面,如我的播客项目:

[zankbo@MyCloudServer ~]$ tree -L 2 gopath/src/

gopath/src/

├── github.com

│ ├── astaxie

│ ├── beego

│ ├── go-sql-driver

│ ├── howeyc

│ ├── jacobsa

│ ├── smartystreets

│ └── wendal

└── zankbo

├── admin

├── blog

├── build_pkg.sh

├── common

├── conf

├── controllers

├── dbstruct.mwb

├── main.go

├── models

├── static

├── views

└── zankbo

导入项目sql文件到数据库

在项目文件夹执行build

[zankbo@MyCloudServer zankbo]$ pwd

/home/zankbo/gopath/src/zankbo

[zankbo@MyCloudServer zankbo]$ go build

会在项目下生成与包名对应的可执行文件,这里为:zankbo,build的时候可能会遇到错误,比如mysql的密码之类的,可根据提示排错。

通过supervisor 来启动服务

# supervisorctl start zankbo

配置Nginx

server {

listen 80;

server_name zankbo.com ;

root /home/zankbo/gopath/src/zankbo;

error_log logs/zankbo.com.error.log warn ;

location /static/ {

root /home/zankbo/gopath/src/zankbo;

location ~ .*\.(js|css)$ {

access_log off;

expires 1d;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {

gzip off;

access_log off;

expires 3d;

}

}

location / {

proxy_pass ;

}

}

原创文章,作者:小蓝,如若转载,请注明出处:https://www.506064.com/n/257769.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
小蓝的头像小蓝
上一篇 2024-12-15 12:46
下一篇 2024-12-15 12:46

相关推荐

  • Python简单数学计算

    本文将从多个方面介绍Python的简单数学计算,包括基础运算符、函数、库以及实际应用场景。 一、基础运算符 Python提供了基础的算术运算符,包括加(+)、减(-)、乘(*)、除…

    编程 2025-04-29
  • Python满天星代码:让编程变得更加简单

    本文将从多个方面详细阐述Python满天星代码,为大家介绍它的优点以及如何在编程中使用。无论是刚刚接触编程还是资深程序员,都能从中获得一定的收获。 一、简介 Python满天星代码…

    编程 2025-04-29
  • Python海龟代码简单画图

    本文将介绍如何使用Python的海龟库进行简单画图,并提供相关示例代码。 一、基础用法 使用Python的海龟库,我们可以控制一个小海龟在窗口中移动,并利用它的“画笔”在窗口中绘制…

    编程 2025-04-29
  • Python樱花树代码简单

    本文将对Python樱花树代码进行详细的阐述和讲解,帮助读者更好地理解该代码的实现方法。 一、简介 樱花树是一种图形效果,它的实现方法比较简单。Python中可以通过turtle这…

    编程 2025-04-28
  • Python大神作品:让编程变得更加简单

    Python作为一种高级的解释性编程语言,一直被广泛地运用于各个领域,从Web开发、游戏开发到人工智能,Python都扮演着重要的角色。Python的代码简洁明了,易于阅读和维护,…

    编程 2025-04-28
  • 用Python实现简单爬虫程序

    在当今时代,互联网上的信息量是爆炸式增长的,其中很多信息可以被利用。对于数据分析、数据挖掘或者其他一些需要大量数据的任务,我们可以使用爬虫技术从各个网站获取需要的信息。而Pytho…

    编程 2025-04-28
  • 如何制作一个简单的换装游戏

    本文将从以下几个方面,为大家介绍如何制作一个简单的换装游戏: 1. 游戏需求和界面设计 2. 使用HTML、CSS和JavaScript开发游戏 3. 实现游戏的基本功能:拖拽交互…

    编程 2025-04-27
  • Guava Limiter——限流器的简单易用

    本文将从多个维度对Guava Limiter进行详细阐述,介绍其定义、使用方法、工作原理和案例应用等方面,并给出完整的代码示例,希望能够帮助读者更好地了解和使用该库。 一、定义 G…

    编程 2025-04-27
  • 2的32次方-1:一个看似简单却又复杂的数字

    对于计算机领域的人来说,2的32次方-1(也就是十进制下的4294967295)这个数字并不陌生。它经常被用来表示IPv4地址或者无符号32位整数的最大值。但实际上,这个数字却包含…

    编程 2025-04-27
  • 制作一个简单的管理系统的成本及实现

    想要制作一个简单的管理系统,需要进行技术选型、开发、测试等过程,那么这个过程会花费多少钱呢?我们将从多个方面来阐述制作一个简单的管理系统的成本及实现。 一、技术选型 当我们开始思考…

    编程 2025-04-27

发表回复

登录后才能评论