本文介绍了如何在嵌入式Web服务器中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 你好 我正在尝试使用浮潜网络服务器显示图像文件(.jpg),使用GET方法,但它没有显示图片。 我得到的是一个非常小的盒子里面有一个X. 所以,我想知道我需要什么使用MIME或我该怎么做才能显示我的图像? 这是我的代码: #pragma hdrstop #pragma argsused #include < snorkel.h > #include < tchar.h > #inclu de < stdio.h > #include < stdlib.h > call_status_t view_image(snorkel_obj_t http, snorkel_obj_t outstream) { snorkel_printf(outstream, < html>< body>< img src = QR4.jpg> < / body>< / html> \\\\ n); return HTTP_SUCCESS; } void 语法( char * pszProg) { fprintf(stderr, 语法错误:\ n ); fprintf(stderr, %s [-p< port>] \ n,pszProg); 退出( 1 ); } void main( int argc, char * argv []) { int i = 1 ; int port = 8090 ; snorkel_obj_t http = 0 ; char szExit [ 10 ]; for (; i< argc; i ++) { if (argv [i] [ 0 ] == ' - ' || argv [i] [ 0 ] == ' /') { char carg = argv [i] [ 1 ]; switch (carg) { case ' p': / * 端口号* / port = atoi(argv [i + 1 ]); i ++; break ; 默认:语法(argv [ 0 ]); break ; } } } / * * *初始化API * * / 如果(snorkel_init()! = SNORKEL_SUCCESS) { perror( 无法初始化snorkel \ n); // exit(1); } / * * *创建服务器对象 * * / http = snorkel_obj_create(snorkel_obj_server, 5 ,NULL); if (!http) { perror( 无法创建http server \\\); // exit(1); } / * * *创建一个监听器 * * / if (snorkel_obj_set(http, / * 服务器对象* / snorkel_attrib_listener, / * attribute * / port, / * 端口号* / 0 / * SSL支持* / )!= SNORKEL_SUCCESS) { fprintf(stderr, 无法创建监听器\ n ); snorkel_obj_destroy(http); // exit(1); } / * * *重载网址index.html * * / if (snorkel_obj_set(http, // server object snorkel_attrib_uri, // 属性类型 GET, // 方法 / index.html, // url contenttype_text,view_image)!= SNORKEL_SUCCESS) { perror( 无法重载index.html); snorkel_obj_destroy(http); // exit(1); } if (snorkel_obj_set(http,snorkel_attrib_ipvers,IPVERS_IPV4,SOCK_SET)!= SNORKEL_SUCCESS) { fprintf(stderr, 错误无法设置ip version \\\); // exit(1); } snorkel_obj_set(http,snorkel_attrib_mime, jpg, image / jpeg, contenttype_text, view_image); / * * *启动服务器 * * / fprintf(stderr, \ n \ n [HTTP]启动嵌入式服务器\ n); if (snorkel_obj_start(http)!= SNORKEL_SUCCESS) { perror( 无法启动server \\\); snorkel_obj_destroy(http); // exit(1); } / * * *在服务器运行 *时执行某项操作单独的线程 * * / fprintf(stderr, \ n [HTTP] started.\\\\ n - 按Enter键终止 - \ n); fgets(szExit, sizeof (szExit),stdin); fprintf(stderr, [HTTP] good bye \ n ); / * * *优雅清理 * * / snorkel_obj_destroy(http); 退出( 0 ); } 你可以帮帮我:confused: 最好的问候。 Rania 解决方案 本文中有示例代码用于显示图像。您应该可以将其修改为JPEG。 如何将简单的基于Web的2D / 3D仪表板添加到本机构建的应用程序 [ ^ ] helloI'm trying to display an image file (.jpg) using the snorkel web-server, by using the GET method, but its not displaying the image.all I get is a very small box with an X inside of it.so, I was wondering do I need to use MIME or what shall I do to display my image?here's my code:#pragma hdrstop#pragma argsused#include <snorkel.h>#include <tchar.h>#include <stdio.h>#include <stdlib.h>call_status_tview_image(snorkel_obj_t http,snorkel_obj_t outstream) {snorkel_printf (outstream, "<html><body><img src = QR4.jpg>" "</body></html>\r\n");return HTTP_SUCCESS; }void syntax (char *pszProg){ fprintf (stderr, "syntax error:\n"); fprintf (stderr, "%s [-p <port>]\n", pszProg); exit (1); }void main (int argc, char *argv[]) { int i = 1; int port = 8090; snorkel_obj_t http = 0; char szExit[10]; for (; i < argc; i++) { if (argv[i][0] == '-' || argv[i][0] == '/') { char carg = argv[i][1]; switch (carg) {case 'p': /* port number */port = atoi (argv[i + 1]);i++;break;default:syntax (argv[0]);break;} } }/* * * initialize API * */ if (snorkel_init () != SNORKEL_SUCCESS) {perror ("could not initialize snorkel\n");//exit (1); }/* * * create a server object * */ http = snorkel_obj_create (snorkel_obj_server, 5, NULL); if (!http) { perror ("could not create http server\n"); //exit (1); }/* * * create a listener * */ if (snorkel_obj_set (http, /* server object */ snorkel_attrib_listener, /* attribute */ port, /* port number */ 0 /* SSL support */ ) != SNORKEL_SUCCESS) { fprintf (stderr, "could not create listener\n"); snorkel_obj_destroy (http); //exit (1); } /* * * overload the URL index.html * */ if (snorkel_obj_set (http, // server object snorkel_attrib_uri, // attribute type GET, // method "/index.html", // url contenttype_text, view_image) != SNORKEL_SUCCESS) { perror ("could not overload index.html"); snorkel_obj_destroy (http); //exit (1); } if (snorkel_obj_set(http, snorkel_attrib_ipvers, IPVERS_IPV4, SOCK_SET) != SNORKEL_SUCCESS){ fprintf (stderr, "error could not set ip version\n"); //exit (1); } snorkel_obj_set(http, snorkel_attrib_mime, "jpg", "image/jpeg", contenttype_text, view_image); /* * * start the server * */ fprintf (stderr, "\n\n[HTTP] starting embedded server\n"); if (snorkel_obj_start (http) != SNORKEL_SUCCESS) {perror ("could not start server\n");snorkel_obj_destroy (http);//exit (1);}/* * * do something while server runs * as a separate thread * */ fprintf (stderr, "\n[HTTP] started.\n\n" "--hit enter to terminate--\n"); fgets (szExit, sizeof (szExit), stdin); fprintf (stderr, "[HTTP] good bye\n"); /* * * graceful clean up * */ snorkel_obj_destroy (http); exit (0); }can you please help me:confused:Best Regards.Rania 解决方案 There is sample code in this article for displaying an image. You should be able to modify it for JPEG.How To Add Simple Web-enabled 2D/3D Dashboards to your Natively Built Application[^] 这篇关于如何在嵌入式Web服务器中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-23 06:46