如何从BITMAP中更改,修改,剪切和交换像素 [英] How to change, modify, cut and swap pixels from BITMAP

查看:628
本文介绍了如何从BITMAP中更改,修改,剪切和交换像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要修改位图:




  • 更改(交换)像素位置/ p>


  • 在子位图中划分位图(例如,将4个位图中的1个位图中的数据除外)(用于不同GL_QUADS的后续纹理化)

    对于这个,我需要的代码如何修改位图的像素。



    下面的代码示例工作并从文件创建纹理:

      HBITMAP hbpInput =(HBITMAP):: LoadImage(NULL,filename,IMAGE_BITMAP,0 ,0,LR_LOADFROMFILE | LR_CREATEDIBSECTION); 

    BITMAP bmpOutput;
    :: GetObject(hbpInput,sizeof(bmpOutput),& bmpOutput);

    (...)

    glTexImage2D(GL_TEXTURE_2D,0,3,bmpOutput.bmWidth,bmpOutput.bmHeight,0,GL_RGB,GL_UNSIGNED_BYTE,bmpOutput.bmBits);

    需要哪些代码才能获得Bit-Array?



    我试过已经GetDIBits(),但这不工作的IMAGE(结构),你肯定知道:)



    任何具体的想法如何能

    解决方案

    p>下面调用的最后一个参数是像素的字节数组:

      glTexImage2D(GL_TEXTURE_2D,0,3,bmpOutput .bmWidth,bmpOutput.bmHeight,
    0,GL_RGB,GL_UNSIGNED_BYTE,bmpOutput.bmBits);

    这意味着 bmpOutput.bmBits 数组中的第一个字节包含以下字节数:

      3 * bmpOutput.bmWidth * bmpOutput.bmHeight 

    这意味着每个像素3个字节(红色,绿色,蓝色各一个)。



    已经说了这一切,根据你的问题,它听起来像你真正寻找的是能够映射纹理的不同部分到不同的四边形。为此,您可以使用纹理地图集。只使用一个纹理对象,但调整每个四边形的纹理坐标以映射到纹理图像的不同部分。


    I want to modify a bitmap:

    • change (swap) pixel position (for later rectification of fish eye)

    • divide bitmap in sub-bitmaps (e. g. make 4 bitmaps out of 1) (for later texturizing of different GL_QUADS)

    For this I need the code how to modify pixels of a bitmap.

    The follwing code example works and creates a texture from a file:

    HBITMAP hbpInput = (HBITMAP)::LoadImage(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
    
    BITMAP bmpOutput;
    ::GetObject (hbpInput, sizeof (bmpOutput), &bmpOutput);
    
    (...)
    
    glTexImage2D(GL_TEXTURE_2D, 0, 3, bmpOutput.bmWidth, bmpOutput.bmHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, bmpOutput.bmBits);
    

    Which code is necessary to get the Bit-Array?

    I tried already GetDIBits(), but this does not work für IMAGE (struct) as you surely know :)

    Any concrete ideas how to be able to change the pixels' position?

    Thank you a lot!

    解决方案

    The last argument in the following call is the byte array for the pixels:

    glTexImage2D(GL_TEXTURE_2D, 0, 3, bmpOutput.bmWidth, bmpOutput.bmHeight,
                 0, GL_RGB, GL_UNSIGNED_BYTE, bmpOutput.bmBits);
    

    This means bmpOutput.bmBits points to the first byte in an array containing the following number of bytes:

    3 * bmpOutput.bmWidth * bmpOutput.bmHeight
    

    This means 3 bytes per pixel (one each for red, green, blue).

    Having said all this, based on your question, it sounds like what you're really looking for is to be able to map different parts of the texture onto different quads. For this, you can use a texture atlas. Use just one texture object, but adjust the texture coordinates for each quad to map to different parts of the texture image.

    这篇关于如何从BITMAP中更改,修改,剪切和交换像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆