这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 活动中心 » 合作大赛 » 关于vm_graphic_load_image_resized()函数的疑问

共4条 1/1 1 跳转至

关于vm_graphic_load_image_resized()函数的疑问

菜鸟
2010-11-17 15:01:02     打赏
在使用此函数时遇到麻烦了:
无论原图片大小为何,只有vm_graphic_load_image_resized()的第三个参数width设置为200时才能够正常缩放。
麻烦帮忙分析一下这个问题,谢谢。



关键词: 关于     graphic     image     resized         

助工
2010-11-30 10:20:10     打赏
2楼

能否贴一下代码?


菜鸟
2010-11-30 15:07:30     打赏
3楼

void Graph_DrawImageEx(VMINT layer_hdl ,VMCHAR*name,
                                                             VMINT x,VMINT y,VMINT width,VMINT height,VMINT trans)
{
   VMUINT8 *cvs_buf,*layer_buf;
 VMINT cvs_hdl;
 struct frame_prop * img_prop = NULL;  

if ((res = vm_load_resource(name, &size)) == NULL) {
  vm_log_error("load resource failed!");
  return ;
 }
cvs_hdl =vm_graphic_load_image_resized(res,size,width,height);
 
/* 释放图片资源 */
 vm_free(res);
/* 获取画布属性*/
 img_prop = vm_graphic_get_img_property(cvs_hdl, 1);
 
 /* 获取画布地址 */
 cvs_buf= vm_graphic_get_canvas_buffer(cvs_hdl);
 
 /* 获取层地址 */
 layer_buf=vm_graphic_get_layer_buffer(layer_hdl);

/*画图:从画布到层*/
vm_graphic_blt_ex(layer_buf, x, y,cvs_buf, 0, 0, img_prop->width, img_prop->height, 1,trans);

 vm_graphic_release_canvas(cvs_hdl);
}

助工
2010-12-01 20:00:09     打赏
4楼

你好,我用你的代码稍加修改试了一下,resize的功能没有问题。
#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 <stdio.h>

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

VMINT  layer_hdl[1];    //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();


/**
* 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); 
  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();
 vm_graphic_flush_layer(layer_hdl, 1); 
}

/* 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_release_canvas(gif_hdl); //release decoded image buffer
}


共4条 1/1 1 跳转至

回复

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