关于vm_graphic_load_image_resized()函数的疑问
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);
}
你好,我用你的代码稍加修改试了一下,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
}
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
【换取逻辑分析仪】-基于ADI单片机MAX78000的简易MP3音乐播放器被打赏48分 | |
我想要一部加热台+树莓派PICO驱动AHT10被打赏38分 | |
【换取逻辑分析仪】-硬件SPI驱动OLED屏幕被打赏36分 | |
换逻辑分析仪+上下拉与多路选择器被打赏29分 | |
Let'sdo第3期任务合集被打赏50分 | |
换逻辑分析仪+Verilog三态门被打赏27分 | |
换逻辑分析仪+Verilog多输出门被打赏24分 | |
【分享评测,赢取加热台】使用8051单片机驱动WS2812被打赏40分 | |
【换取逻辑分析仪】rtthread添加RRH62000传感器驱动-基于野火启明6M5被打赏48分 | |
换逻辑分析仪+Verilog多输入门被打赏27分 |