论坛» 活动中心» 合作大赛

关于sample code疑问

菜鸟
2010-10-25 19:25 1楼

一、VRE 3.0 Sample Code\Graphic\demo_1(draw image)工程
编译代码后运行,界面如下

Q1.为什么

vm_graphic_textout(gif_buf,10,2,wstr,wstrlen(wstr),VM_COLOR_WHITE); //write character on canvas

在红框里输出的文字乱码了,而且红框产生类似阴影的效果?

如果去掉这行,则红框显示正常

Q2. 从代码中可以看到

vm_graphic_flush_layer(layer_hdl,2);

输出了两个层,其中,layer_hdl[1]不透明度为50

vm_graphic_set_layer_opacity(layer_hdl[1],50); //set opacity of fast layer

但为什么layer_hdl[0]上的内容一点都没有显示出来?

改为
vm_graphic_flush_layer(layer_hdl,1);

只输出layer_hdl[0],可看到如下内容

Q3.VRE到底支持创建几个Layer?
《VRE 图形库开发指南》里说:
“2.1.2 层
层是对屏幕的模拟,VRE 支持两个层。”

而程序调用
vm_graphic_get_layer_count()
显示“max support 16 layers”

到底哪种说法是正确的?

二、VRE 3.0 Sample Code\Graphic\demo_2(rotate+translate layer)工程

Q4 layer_hdl[1] =vm_graphic_create_layer_ex(0, 0, 80,80,
VM_COLOR_RED ,VM_FAST_LAYER ,NULL);
在(0,0)处创建80X80的layer后,
通过按键事件调用vm_graphic_rotate_layer().将

旋转成

这里有两个疑问:
(1) vm_graphic_rotate_layer不是将层图形围绕图片左上角原点旋转,而是把整个屏幕横过来了?
(2)示例代码中

num = (num + 1) % 4;
switch(num)
{
case 0:
vm_graphic_rotate_layer(layer_hdl[1] , VM_GDI_ROTATE_90);
break;
case 1:
vm_graphic_rotate_layer(layer_hdl[1] , VM_GDI_ROTATE_180);
break;
case 2:
vm_graphic_rotate_layer(layer_hdl[1] , VM_GDI_ROTATE_270);
break;
case 3:
vm_graphic_rotate_layer(layer_hdl[1] , VM_GDI_ROTATE_NORMAL);

说明每次调用vm_graphic_rotate_layer(),旋转的角度都是以初始图片为准,而不是以上次调用

vm_graphic_rotate_layer()函数后的显示结果为准?

菜鸟
2010-10-25 22:02 2楼
同学你好~ 我load图片始终不成功。。。 请问你是直接运行sample code成功的吗? 能留个联系方式吗?邮箱或者QQ```我的邮箱 wuhanxiao2004@126.com QQ 349780883....谢谢···
菜鸟
2010-10-26 20:31 3楼
已加QQ
菜鸟
2010-10-26 20:32 4楼

等待官方回答。。。
为什么乱码了,抓狂中

菜鸟
2010-10-27 19:21 5楼
汉字有没有进行编码转换??第一个示例里应该有。
http://vre.net.ru/viewtopic.php?f=3&t=117 或者你看看这个,我写的。里面有汉字能够显示正常的
菜鸟
2010-10-27 19:34 6楼
首先,输出的不是中文的,其次,代码里也用函数转换了

这一段的代码如下

sprintf(str,"canvas");
vm_ascii_to_ucs2(wstr,120,str);
vm_graphic_fill_rect(gif_buf, 0, 0, 100,100, VM_COLOR_WHITE, VM_COLOR_RED); //fill rect on canvas
vm_graphic_textout(gif_buf,10,2,wstr,wstrlen(wstr),VM_COLOR_WHITE); //write character on canvas
vm_graphic_blt_ex(buf,20,190,gif_buf,0,0,100,100,1,150); // semi-transparent effect
助工
2010-10-27 19:54 7楼
这位同学,这么多的问题,你开发的很仔细呀。我一个一个来回答,没有你的源码,我只能来猜测,猜的不对的地方,你贴source code我们一起来看
一。
Q1:str 和wstr用之前你有memset吗?是不是和之前显示string的buffer混用导致的?
Q2:vm_graphic_set_layer_opacity 有返回值的,你可以看看返回值是不是设置成功。常见不成功的理由是create layer时候最后一个参数是-1,意味着这个layer不支持半透明,自然设置也不会成功
Q3:最多支持16个,只要memory足够,但是实际常用的只有2个
二.
(1)旋转是以layer为单位,旋转的是layer.
(2)每次调用vm_graphic_rotate_layer(),旋转的角度都是以初始图片为准,而不是以上次调用vm_graphic_rotate_layer()函数后的显示结果为准?
和第一个问题类似,是以layer为单位,如果旋转90度,再旋转90度,实际的效果是180度
菜鸟
2010-10-27 22:52 8楼

联发科技,你好,我调试的代码是官方给出的VRE 3.0 API Sample Code
下载地址

http://share.eepw.com.cn/share/download/id/56092

两个工程分别是解压后的
VRE 3.0 Sample Code\Graphic\demo_1(draw image)工程

VRE 3.0 Sample Code\Graphic\demo_2(rotate+translate layer)工程

关于Q1:
没有用memset,刚才加了,结果还是一样乱码
关于Q2:
layer_hdl[1] create的时候参数不是-1,而且把
vm_graphic_set_layer_opacity(layer_hdl[1],50);
改为
vm_graphic_set_layer_opacity(layer_hdl[1],100);
显示效果明显有变化,说明半透明效果对该层是起作用了,只是
layer_hdl[0]基层上的显示内容没有融合过来

创建层的代码如下

layer_hdl[0] = vm_graphic_create_layer(0, 0,
vm_graphic_get_screen_width(),
vm_graphic_get_screen_height(), -1);

/* cerate fast layer */
layer_hdl[1] = vm_graphic_create_layer(0, 0,
vm_graphic_get_screen_width(),
vm_graphic_get_screen_height(), VM_COLOR_RED);


以上两个问题隐约怀疑是否校园版SDK的bug?


Q3.已了解

二.
(1)没有疑问了
(2)从代码的写法,和实际的效果来看,貌似是始终以初始状态为准的,每次按键事件后,都用

num = (num + 1) % 4;
来记录当前旋转位置
再用
switch(num)
{
case 0:
vm_graphic_rotate_layer(layer_hdl[1] , VM_GDI_ROTATE_90);
break;
case 1:
vm_graphic_rotate_layer(layer_hdl[1] , VM_GDI_ROTATE_180);
break;
case 2:
vm_graphic_rotate_layer(layer_hdl[1] , VM_GDI_ROTATE_270);
break;
case 3:
vm_graphic_rotate_layer(layer_hdl[1] , VM_GDI_ROTATE_NORMAL);

来确定实际旋转到哪个角度
如果按照您的解释的话,只需要在每个按键事件里写上

vm_graphic_rotate_layer(layer_hdl[1] , VM_GDI_ROTATE_90);

这一行就行了

菜鸟
2010-10-27 22:55 9楼

//===============================================

//demo_1.h

#ifndef _VRE_APP_demo_1_
#define _VRE_APP_demo_1_

#endif







//===============================================
//demo_1.c

/* ============================================================================
* VRE demonstration application.
*
* Copyright (c) 2006-2009 Vogins Network Technology (China). All rights
* reserved.
*
* YOU MAY MODIFY OR DISTRIBUTE SOURCE CODE BELOW FOR PERSONAL OR
* COMMERCIAL PURPOSE UNDER THOSE AGGREMENTS:
*
* 1) VOGINS COPYRIGHT MUST BE KEPT IN REDISTRIBUTED SOURCE CODE OR
* BINARY FILE.
* 2) YOU CAN REUSE THOSE SOURCE CODE IN COMMERCIAL PURPOSE WITHOUT
* VOGINS COMFIRMATION.
* 3) THIS PROGRAM JUST USE TO DEMONSTRATE HOW TO WRITE A VRE BASED
* APPLICATION. VOGINS WON'T MAKE ANY GUARANTEE THAT IT COULD BE
* USED IN PRODUCTION ENVIRONMENT.
* ========================================================================= */

/*============================================================================
* GDI Sample show the VRE usage of GDI interface
*
* Copyright (c) 2006 - 2009 Vogins Network Technology (China). All rights reserved.
* By Steven Fang Feb. 1, 2009 V1.0
*============================================================================*/

#include "vmsys.h"
#include "vmio.h"
#include "vmgraph.h"
#include "vmchset.h"
#include "vmstdlib.h"
#include "vmres.h"
#include "vmlog.h"
#include "vmstdlib.h"
#include

/* ---------------------------------------------------------------------------
* global variables
* ------------------------------------------------------------------------ */

VMINT layer_hdl[2]; //layer handle array

/* ---------------------------------------------------------------------------
* local variables
* ------------------------------------------------------------------------ */
/*
* system events
*/
void handle_sysevt(VMINT message, VMINT param);

/*
* key events
*/
void handle_keyevt(VMINT event, VMINT keycode);

/*
* pen events
*/
void handle_penevt(VMINT event, VMINT x, VMINT y);

/*
* demo
*/
static void draw(void);
static void draw_image();
static void draw_info();

/**
* entry
*/
void vm_main(void) {
vm_reg_sysevt_callback(handle_sysevt);
vm_reg_keyboard_callback(handle_keyevt);
vm_reg_pen_callback(handle_penevt);
}

void handle_sysevt(VMINT message, VMINT param) {
switch (message) {
case VM_MSG_CREATE:
case VM_MSG_ACTIVE:
/* cerate base layer that has same size as the screen*/
layer_hdl[0] = vm_graphic_create_layer(0, 0,
vm_graphic_get_screen_width(),
vm_graphic_get_screen_height(), -1);

/* cerate fast layer */
layer_hdl[1] = vm_graphic_create_layer(0, 0,
vm_graphic_get_screen_width(),
vm_graphic_get_screen_height(), VM_COLOR_RED);


/* set clip area */
vm_graphic_set_clip(0, 0,
vm_graphic_get_screen_width(),
vm_graphic_get_screen_height());
break;

case VM_MSG_PAINT:
draw();
break;

case VM_MSG_INACTIVE:
vm_graphic_delete_layer(layer_hdl[1]);
vm_graphic_delete_layer(layer_hdl[0]); //must delete other layer before delete base layer
break;
case VM_MSG_QUIT:
vm_graphic_delete_layer(layer_hdl[1]);
vm_graphic_delete_layer(layer_hdl[0]); //must delete other layer before delete base layer
vm_exit_app();
break;
}
}

void handle_keyevt(VMINT event, VMINT keycode) {
/* press any key to exit program */
vm_graphic_delete_layer(layer_hdl[0]);

vm_exit_app();
}

void handle_penevt(VMINT event, VMINT x, VMINT y){

vm_graphic_delete_layer(layer_hdl[0]);

vm_exit_app();
}


static void draw(void) {

draw_image();
draw_info();

vm_graphic_flush_layer(layer_hdl,2);
}

/* draw image */
static void draw_image()
{
VMUINT8 * res = NULL; //raw image data
VMINT gif_size = -100; //image size

VMINT gif_hdl=-100; //image handle
VMUINT8 *gif_buf=NULL; //decoded image buffer
VMINT gif_width =-100; //image width
VMINT gif_height=-100; //image height

VMUINT8 * buf=NULL; //base layer buffer

res = vm_load_resource("logo_vre.gif", &gif_size); //load image data from vxp file
if (res == NULL)
handle_sysevt(VM_MSG_QUIT, 1); //load resource failed, exit program


gif_hdl = vm_graphic_load_image(res,gif_size); //decode image data
if (gif_hdl < 0)
handle_sysevt(VM_MSG_QUIT, 1); //decode failed, exit program

vm_free(res); //free raw image data

gif_buf = vm_graphic_get_canvas_buffer(gif_hdl); //get decoded image buffer
gif_width = vm_graphic_get_img_property(gif_hdl,1)->width; //get image width
gif_height = vm_graphic_get_img_property(gif_hdl,1)->height; //get image height

buf = vm_graphic_get_layer_buffer(layer_hdl[0]); //get base layer buffer

vm_graphic_fill_rect(buf, 0, 0, vm_graphic_get_screen_width(),
vm_graphic_get_screen_height(), VM_COLOR_WHITE, VM_COLOR_GREEN); //draw background

vm_graphic_blt(buf,0,10,gif_buf,0,0,gif_width,gif_height,1); //draw first frame of image

vm_graphic_blt(buf,0,40,gif_buf,0,0,gif_width,gif_height,2); //draw second frame of image

vm_graphic_release_canvas(gif_hdl); //release decoded image buffer
}


static void draw_info()
{
VMUINT8 * buf=NULL;
VMCHAR str[60]={0};
VMWCHAR wstr[60]={0};

//=========
info


VMINT x;
VMINT y;
VMINT width;
VMINT height;

VMUINT16 color =0;

VMINT gif_hdl;
VMUINT8 * gif_buf=NULL;

sprintf(str,"max support %d layer", vm_graphic_get_layer_count()); //Obtain maximum numbers of layers supported by the target platform
vm_ascii_to_ucs2(wstr, 120, str);
buf = vm_graphic_get_layer_buffer(layer_hdl[1]); //get fast layer buffer


vm_graphic_fill_rect(buf, 0, 40, vm_graphic_get_screen_width()-50,
vm_graphic_get_screen_height()-50, VM_COLOR_WHITE, VM_COLOR_BLUE);

vm_graphic_textout(buf,0,80,wstr,wstrlen(wstr),VM_COLOR_GREEN);

vm_graphic_get_layer_position(layer_hdl[1],&x,&y,&width,&height); //get fast layer position and size

sprintf(str,"fast layer position X=%d,Y=%d", x,y);
vm_ascii_to_ucs2(wstr,120,str);

vm_graphic_textout(buf,0,100,wstr,vm_wstrlen(wstr),VM_COLOR_GREEN);

sprintf(str,"fast layer size W=%d,H=%d",width,height);
vm_ascii_to_ucs2(wstr,120,str);

vm_graphic_textout(buf,0,120,wstr,vm_wstrlen(wstr),VM_COLOR_GREEN);


color=vm_graphic_get_pixel(buf, 100, 100); //get the color of specified point on fast layer
sprintf(str,"fast layer 100.100 color: 0x%x",color);
vm_ascii_to_ucs2(wstr,120,str);
vm_graphic_textout(buf,0,140,wstr,vm_wstrlen(wstr),VM_COLOR_GREEN);


gif_hdl=vm_graphic_create_canvas(100,100); //create canvas
gif_buf= vm_graphic_get_canvas_buffer(gif_hdl); //get canvas buffer

//vm_memset(str,0,60);
sprintf(str,"canvas");

// vm_memset(wstr,0,120);
vm_ascii_to_ucs2(wstr,120,str);

//vm_graphic_textout(buf,10,2,wstr,wstrlen(wstr),VM_COLOR_WHITE);
vm_graphic_fill_rect(gif_buf, 0, 0, 100,100, VM_COLOR_WHITE, VM_COLOR_RED); //fill rect on canvas
vm_graphic_textout(gif_buf,10,2,wstr,wstrlen(wstr),VM_COLOR_WHITE); //write character on canvas
vm_graphic_blt_ex(buf,20,190,gif_buf,0,0,100,100,1,150); // semi-transparent effect

vm_graphic_set_layer_opacity(layer_hdl[1],50); //set opacity of fast layer
}

菜鸟
2010-10-27 22:59 10楼

//===============================
//GIF_demo.h

#ifndef _VRE_APP_GIF_DEMO_
#define _VRE_APP_GIF_DEMO_

#include "vmsys.h"
#include "vmio.h"
#include "vmgraph.h"
#include "vmchset.h"
#include "vmstdlib.h"
#include "vmres.h"
#include "vmlog.h"


/*
* system events
*/
void handle_sysevt(VMINT message, VMINT param);

/*
* key events
*/
void handle_keyevt(VMINT event, VMINT keycode);

/*
* pen events
*/
void handle_penevt(VMINT event, VMINT x, VMINT y);

void init_img();

#endif








//===============================
//GIF_demo.c


/* ============================================================================
* VRE demonstration application.
*
* Copyright (c) 2006-2009 Vogins Network Technology (China). All rights
* reserved.
*
* YOU MAY MODIFY OR DISTRIBUTE SOURCE CODE BELOW FOR PERSONAL OR
* COMMERCIAL PURPOSE UNDER THOSE AGGREMENTS:
*
* 1) VOGINS COPYRIGHT MUST BE KEPT IN REDISTRIBUTED SOURCE CODE OR
* BINARY FILE.
* 2) YOU CAN REUSE THOSE SOURCE CODE IN COMMERCIAL PURPOSE WITHOUT
* VOGINS COMFIRMATION.
* 3) THIS PROGRAM JUST USE TO DEMONSTRATE HOW TO WRITE A VRE BASED
* APPLICATION. VOGINS WON'T MAKE ANY GUARANTEE THAT IT COULD BE
* USED IN PRODUCTION ENVIRONMENT.
* ========================================================================= */

/*============================================================================
* GDI Sample show the VRE usage of GDI interface
*
* Copyright (c) 2006 - 2009 Vogins Network Technology (China). All rights reserved.
* By Steven Fang Feb. 1, 2009 V1.0
*============================================================================*/

#include "GIF_DEMO.h"


VMINT layer_hdl[2]; ////layer handle array.
VMUINT8* buf=NULL;
VMINT coordinate_x,coordinate_y;
VMUINT8* img=NULL;
VMINT hanvas=-1;

VMINT height1 =0;
VMINT width1 =0;
void gif();

/**
* entry
*/
void vm_main(void) {
layer_hdl[0] = -1;

init_img();
vm_reg_sysevt_callback(handle_sysevt);
vm_reg_keyboard_callback(handle_keyevt);
vm_reg_pen_callback(handle_penevt);



}

void handle_sysevt(VMINT message, VMINT param) {
/* The application updates the screen when receiving the message VM_MSG_PAINT
* what is sent after the application is activated. The application can skip
* the process on screen when the VM_MSG_ACTIVE or VM_MSG_INACTIVE is received.
*/

switch (message) {
case VM_MSG_CREATE:
case VM_MSG_ACTIVE:
/* cerate base layer that has same size as the screen*/
layer_hdl[0] = vm_graphic_create_layer(0, 0,
vm_graphic_get_screen_width(),
vm_graphic_get_screen_height(), -1);


layer_hdl[1] =vm_graphic_create_layer_ex(0, 0, 80,80,
VM_COLOR_RED ,VM_FAST_LAYER ,NULL);

/* set clip area */
vm_graphic_set_clip(0, 0,
vm_graphic_get_screen_width(),
vm_graphic_get_screen_height());
break;

case VM_MSG_PAINT:
gif();
break;
case VM_MSG_INACTIVE:
vm_graphic_delete_layer(layer_hdl[1]);
vm_graphic_delete_layer(layer_hdl[0]);
break;
case VM_MSG_QUIT:
vm_graphic_delete_layer(layer_hdl[1]);
vm_graphic_delete_layer(layer_hdl[0]);
vm_graphic_release_canvas(hanvas);
vm_exit_app();

break;
}

}

void handle_keyevt(VMINT event, VMINT keycode) {
/* press any key and return*/
static VMINT num=0;

if (event == VM_KEY_EVENT_UP)
{
num = (num + 1) % 4;
switch(num)
{
case 0:
vm_graphic_rotate_layer(layer_hdl[1] , VM_GDI_ROTATE_90);
break;
case 1:
vm_graphic_rotate_layer(layer_hdl[1] , VM_GDI_ROTATE_180);
break;
case 2:
vm_graphic_rotate_layer(layer_hdl[1] , VM_GDI_ROTATE_270);
break;
case 3:
vm_graphic_rotate_layer(layer_hdl[1] , VM_GDI_ROTATE_NORMAL);
}
vm_graphic_flush_layer(layer_hdl, 2);
}
}

void handle_penevt(VMINT event, VMINT x, VMINT y)
{
/* touch and return*/

if (event == VM_PEN_EVENT_MOVE)
{
coordinate_x = x;
coordinate_y = y;
vm_graphic_translate_layer(layer_hdl[1], coordinate_x, coordinate_y);
vm_graphic_flush_layer(layer_hdl, 2);
}
}

void gif()
{

/* get the target buffer*/
buf = vm_graphic_get_layer_buffer(layer_hdl[0]);

/* fill the screen*/
vm_graphic_fill_rect(buf, 0, 0, vm_graphic_get_screen_width(),
vm_graphic_get_screen_height(), VM_COLOR_WHITE, VM_COLOR_WHITE);

buf = vm_graphic_get_layer_buffer(layer_hdl[1]);

vm_graphic_blt(buf,0,0,img,0,0,width1,height1,1);

vm_graphic_flush_layer(layer_hdl,2);
}

void init_img()
{
VMUINT8 *tempPoint=NULL;
VMINT NUMBer=-1;

VMINT size=-1;

tempPoint= vm_load_resource("transformer.gif", &size); //load image data from vxp file
if (tempPoint == NULL )
{
handle_sysevt(VM_MSG_QUIT,0); //if load failed, exit program
}

hanvas= vm_graphic_load_image(tempPoint, size); //decode image data
img = vm_graphic_get_canvas_buffer(hanvas); //get decoded image buffer

vm_free(tempPoint);

/* get image property */
height1= (vm_graphic_get_img_property(hanvas, 1)->height);
width1 = (vm_graphic_get_img_property(hanvas, 1)->width);

}

共14条 1/2 1 2 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册]