设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3370|回复: 5
打印 上一主题 下一主题

[讨论] C++中乱搞Bitmap

[复制链接]

Lv2.观梦者

傻♂逼

梦石
0
星屑
369
在线时间
1605 小时
注册时间
2007-3-13
帖子
6562

烫烫烫开拓者

跳转到指定楼层
1
发表于 2011-5-9 21:42:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 yangff 于 2011-5-9 22:02 编辑

直接上代码
在RM里面用《快速存储Bitmap的Marshal》By 61
C++
int * hBitmap;
void xxx(int bitmap,int width,int height){
  hBitmap=(int*)bitmap;
}
要用的时候就
hBitmap[y*width+x]=color
欢迎蛋疼
PS:hBitmap是上下颠倒的= =
PPS:府上一段生命游戏求检测……不知道为什么,几个常数怎么调都不对……#¥T#T¥·T
  1. $LifeBitmapLonely=true
  2. #APIs
  3. class LifeAPI<Win32API
  4.   def initialize(func,inp="",out="")
  5.     super("LifeGame",func,inp,out)
  6.   end
  7. end
  8. module LifeGame
  9.   StartGame=LifeAPI.new("startGame","lll","l")
  10.   NextGame=LifeAPI.new("nextGame")
  11.   SetXY=LifeAPI.new("setXY","ll")
  12.   ExitGame=LifeAPI.new("exitGame")
  13. end
  14. class LifeBitmap < Bitmap
  15.   include LifeGame
  16.   def initialize(width,height)
  17.     if $LifeBitmapLonely
  18.       $LifeBitmapLonely=false
  19.     end
  20.     super(width,height)
  21.     StartGame.call(width,height,address)
  22.   end
  23.   def dispose
  24.     $LifeBitmapLonely=true
  25.     ExitGame.call
  26.     super
  27.   end
  28.   def update
  29.     NextGame.call
  30.   end
  31.   def setXY(x,y)
  32.     SetXY.call(x,y)
  33.   end
  34. end
  35.   $s=Sprite.new
  36.   $s.z=999
  37.   $s.bitmap=LifeBitmap.new(32,32)
  38.   $s.zoom_x=10
  39.   $s.zoom_y=10
  40. while true
  41.   $s.bitmap.update
  42.   Graphics.wait(1)
  43.   Mouse.update
  44.   pos=Mouse.pos
  45.   if not pos.nil?
  46.   if (pos[0]<320) and (pos[1]<320)
  47.     pos[0]/=10
  48.     pos[1]/=10
  49.     $s.bitmap.setXY(*pos)
  50.    # for i in 0...60
  51.    #   Mouse.update
  52.    #   Graphics.update
  53.    # end
  54.   end
  55.   end
  56. end
复制代码
  1. // LifeGame.cpp : 定义 DLL 应用程序的导出函数。
  2. //

  3. #include "stdafx.h"
  4. #define Live 0xFF00FFFF
  5. #define Death 0xFFFF0000
  6. int dir[8][2]={{-1, -1}, {-1, 0}, {-1,1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};
  7. int mWidth=0;
  8. int mHeight=0;
  9. int* bitHandle=0;
  10. int* map;
  11. bool playing=false;
  12. /*    0 1 2 3 4 mw-1
  13.   x 0         
  14. y   1         
  15.     2     
  16.         3
  17.         4
  18.         mh-1

  19. */
  20. int xyth(int x,int y)
  21. {
  22.         return (mHeight-1-y)*mWidth+x;
  23. }
  24. int startGame(int width,int height,int hbitmap)
  25. {
  26.         playing=true;
  27.         srand((unsigned)time(NULL));
  28.         //int a[width*height]={};
  29.         map=new int[width*height+1];
  30.         mWidth=width;
  31.         mHeight=height;
  32.         bitHandle=(int*)hbitmap;
  33.         //Init map
  34.         for (int i=0;i<width*height;i++)
  35.         {
  36.                 if ((rand()%1)==0)
  37.                 {
  38.                         bitHandle[i]=Live;
  39.                         map[i]=Live;
  40.                 }
  41.                 else
  42.                 {
  43.                         bitHandle[i]=Death;
  44.                         map[i]=Death;
  45.                 }
  46.         }
  47.         return true;
  48. }

  49. void nextGame()
  50. {
  51.         if (!playing) return;
  52.         int count=0;
  53.        
  54.         for (int y=1;y<mHeight-1;y++)
  55.                 for (int x=1;x<mWidth-1;x++)
  56.                 {
  57.                         count=0;
  58.         /*                for (int c=0;c<8;c++)
  59.                         {
  60.                                 int x1=x+dir[c][0];
  61.                                 int y1=y+dir[c][1];                               
  62.                                 //if ((((y+dir[c][1])<0)||((y+dir[c][1])>mHeight)) ||        (((x+dir[c][0])<0)||((x+dir[c][0])>mWidth)))
  63.                                 if (((x1<0)||(x1>mWidth))||((y1<0)||(y1>mHeight)))
  64.                                 {count+=1;
  65.                                         continue ;}
  66.                                 //if (xyth(x1,y1)<mWidth*mHeight){
  67.                                         if (bitHandle[xyth(x1,y1)]==Live){ count+=1;}//}
  68.                         }*/
  69.                         if (bitHandle[xyth(x-1,y)]==Live)count++;
  70.                         if (bitHandle[xyth(x-1,y-1)]==Live)count++;
  71.                         if (bitHandle[xyth(x-1,y+1)]==Live)count++;
  72.                         if (bitHandle[xyth(x,y-1)]==Live)count++;
  73.                         if (bitHandle[xyth(x,y+1)]==Live)count++;
  74.                         if (bitHandle[xyth(x+1,y)]==Live)count++;
  75.                         if (bitHandle[xyth(x+1,y-1)]==Live)count++;
  76.                         if (bitHandle[xyth(x+1,y+1)]==Live)count++;
  77.                         if (count>5) map[xyth(x,y)]=Live;
  78.                         if (count<5)  map[xyth(x,y)]=Death;

  79.                 }       
  80.         for (int i=0;i<mWidth*mHeight;i++)
  81.                 bitHandle[i]=map[i];

  82. }
  83. void setXY(int x,int y)
  84. {
  85.         int c=xyth(x,y);
  86.         if (map[c]==Live) {map[c]= Death;}
  87.         else{
  88.                 map[c]=Live;}
  89.         bitHandle[c]=map[c];
  90. }

  91. void exitGame()
  92. {
  93.         playing=false;
  94. }
复制代码
哎呀,蛋疼什么的最有爱了

Lv3.寻梦者

弓箭手?剑兰

梦石
0
星屑
4854
在线时间
833 小时
注册时间
2010-11-17
帖子
1140
2
发表于 2011-5-14 09:02:32 | 只看该作者
我试过《快速存储Bitmap的Marshal》拿出来的rgba的Bitmap是上下倒转的= =,是吗?
回复 支持 反对

使用道具 举报

Lv2.观梦者

傻♂逼

梦石
0
星屑
369
在线时间
1605 小时
注册时间
2007-3-13
帖子
6562

烫烫烫开拓者

3
 楼主| 发表于 2011-5-14 09:24:14 | 只看该作者
一箭烂YiJL 发表于 2011-5-14 09:02
我试过《快速存储Bitmap的Marshal》拿出来的rgba的Bitmap是上下倒转的= =,是吗? ...

yes~~~~~~10个字你妹啊
哎呀,蛋疼什么的最有爱了
回复 支持 反对

使用道具 举报

Lv3.寻梦者

弓箭手?剑兰

梦石
0
星屑
4854
在线时间
833 小时
注册时间
2010-11-17
帖子
1140
4
发表于 2011-5-14 09:35:00 | 只看该作者
回复 yangff 的帖子

"yes~~~~~~"之后那些看不懂...

本来之前打算将《快速存储Bitmap的Marshal》用PNG写出来,面对:
第一要用数组的办法将 0 push 进去图片的每一行...
第二要用数组把他们上下倒置。
两个加起来的速度无法接受。
回复 支持 反对

使用道具 举报

Lv2.观梦者

傻♂逼

梦石
0
星屑
369
在线时间
1605 小时
注册时间
2007-3-13
帖子
6562

烫烫烫开拓者

5
 楼主| 发表于 2011-5-14 10:14:32 | 只看该作者
一箭烂YiJL 发表于 2011-5-14 09:35
回复 yangff 的帖子

"yes~~~~~~"之后那些看不懂...

dll欢迎你~

点评

什么startGame、nextGame都不知道干啥的= =  发表于 2011-5-14 10:23
哎呀,蛋疼什么的最有爱了
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
169 小时
注册时间
2010-11-29
帖子
172
6
发表于 2011-5-14 10:46:28 | 只看该作者
你们到底在说什么,我听不懂诶
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-3 18:29

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表