DirectFB实例1--加载一幅图片
2014-05-12 00:00
344 查看
在DirectFB中加载一幅图片,并显示:
1. 通过IDirectFBImageProvider加载一幅图片.
2. 创建一个DirectFBSurface,并将图片数据放入其中.
3. 将该Surface的内容Blit到主Surface, 以更进行显示.
下面用代码解释上述三个步骤.
在执行上述步骤前,首先得进行上下文初始化,对于DirectFB程序来说,这些初始化步骤是一样的.
然后创建一个主Surface :
接下来是加载图片:
然后根据ImageProvider提供的描述信息,量身创建一个匹配的Surface.
最后,将图片数据复制到主Surface上,
对于双Buffer的主Surface,需要通过以下调用 才用在屏幕上看到输出:
设置Color Key, 一般用于去掉背景色
1. 通过IDirectFBImageProvider加载一幅图片.
2. 创建一个DirectFBSurface,并将图片数据放入其中.
3. 将该Surface的内容Blit到主Surface, 以更进行显示.
下面用代码解释上述三个步骤.
在执行上述步骤前,首先得进行上下文初始化,对于DirectFB程序来说,这些初始化步骤是一样的.
DFBResult ret; //初始化DirectFB ret = DirectFBInit(&argc, &argv); if (ret != DFB_OK) { cout<<"初始化DirectFB失败!"<<endl; return -1; } DirectFBCreate(&dfb); dfb->SetCooperativeLevel (dfb, DFSCL_NORMAL); //设置屏幕模式 dfb->SetVideoMode(dfb, SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP);
然后创建一个主Surface :
dsc.flags = DSDESC_CAPS; dsc.caps = (DFBSurfaceCapabilities)(DSCAPS_PRIMARY | DSCAPS_FLIPPING); dfb->CreateSurface(dfb, &dsc, &screen);
接下来是加载图片:
//加载图片 ret = dfb->CreateImageProvider (dfb, IMGDIR"/helloworld.png", &img_provider); if (ret != DFB_OK) { cout<<"加载图片失败!"<<endl; return -1; }
然后根据ImageProvider提供的描述信息,量身创建一个匹配的Surface.
img_provider->GetSurfaceDescription(img_provider, &dsc); dfb->CreateSurface(dfb, &dsc, &hello); img_provider->RenderTo(img_provider, hello, NULL); img_provider->Release(img_provider);
最后,将图片数据复制到主Surface上,
//将图片应用到屏幕上 screen->Blit(screen, hello, NULL, 0, 0);
对于双Buffer的主Surface,需要通过以下调用 才用在屏幕上看到输出:
//更新屏幕 screen->Flip (screen, NULL, DSFLIP_WAITFORSYNC);
设置Color Key, 一般用于去掉背景色
static void apply_surface(int x, int y, IDirectFBSurface *source, IDirectFBSurface *destination) { destination->SetBlittingFlags(destination, DSBLIT_SRC_COLORKEY ); source->SetSrcColorKey(source, 0x0, 0xFF, 0xFF); // destination->DisableAcceleration(destination, DFXL_BLIT); destination->Blit(destination, source, NULL, x, y); }
相关文章推荐
- DirectFB实例1--加载一幅图片
- 实例讲解Android中如何实现图片的异步加载功能
- Android Async异步操作实例---加载网络图片(慕课网笔记)
- [Android] AsyncTask使用实例---加载网络图片
- javascript图片预加载实例分析
- [Android实例] Android Bitmap 全面解析(二)加载多张图片的缓存处理
- jQuery瀑布流实例无限滚动加载图片
- [Android] AsyncTask使用实例---加载网络图片
- scrollLoading插件实现图片延迟懒加载实例包涵html和js代码
- android异步加载图片显示,并且对图片进行缓存实例
- 实例讲解Android中如何实现图片的异步加载功能
- [Android实例]Listview异步加载图片之优化篇(有图有码有解释)
- BGRABitmap图像操作2:加载一幅图片
- jQuery实现页面滚动图片等元素动态加载(按需加载的实例)
- 实例演示Android异步加载图片
- jQuery瀑布流实例无限滚动加载图片
- [Android] AsyncTask使用实例---加载网络图片
- jquery.lazyload 图片延迟加载实例
- JS实例:网页上图片延迟加载的JS代码
- 实例演示Android异步加载图片(转)