is it possible editing bitmaps
Posted: Sun Apr 22, 2007 1:56 pm
Does any know if it is possible to editing bitmaps in irrlicht
any help would be apriciated
any help would be apriciated
Official forum of the Irrlicht Engine
https://irrlicht.sourceforge.io/forum/
Code: Select all
// get pointer to texture data which in this case is basicly array of u32 values, you need to cast since function returns void pointer, however you already know color format and thus what to cast to
u32* p = (u32*)yourTexture->lock();
// now use that pointer to acces array
for(u32 i=0; i < yourTexture->getSize().Width * yourTexture->getSize().Height; i++)
{
p[i] = video::SColor(255,255,0,0).color;
}
// now unlock texture
yourTexture->unlock();
Code: Select all
u32* p = (u32*)yourTexture->lock();
u32 x = 5;
u32 y = 10;
p[y * yourTexture->getSize().Height + x] = video::SColor(255,0,255,0).color;
yourTexture->unlock();
Code: Select all
video::SColor mycolor(p[0]);
Code: Select all
mycolor.getBlue()
Code: Select all
const c8* testimg = "Template.bmp";
const c8* testimga = "Grass.jpg";
const c8* testimgb = "Path.jpg";
ITexture* TestBit;
ITexture* TestBita;
ITexture* TestBitb;
Code: Select all
TestBit=driver->getTexture(testimg);
TestBita=driver->getTexture(testimga);
TestBitb=driver->getTexture(testimgb);
Code: Select all
u32* ImgTemp = (u32*)TestBit->lock();
u32* ImgA = (u32*)TestBita->lock();
u32* ImgB = (u32*)TestBitb->lock();
for(u32 i=0; i < TestBit->getSize().Width * TestBit->getSize().Height; i++)
{
s32 TempA,TempR,TempG,TempB;
TempA = video::SColor(getAlpha(ImgTemp[i])).color;
TempR = video::SColor(getRed(ImgTemp[i])).color;
TempG = video::SColor(getGreen(ImgTemp[i])).color;
TempB = video::SColor(getBlue(ImgTemp[i])).color;
s32 aa,ar,ab,ag;
aa = video::SColor(getAlpha(ImgA[i])).color;
ar = video::SColor(getRed(ImgA[i])).color;
ag = video::SColor(getGreen(ImgA[i])).color;
ab = video::SColor(getBlue(ImgA[i])).color;
s32 ba,br,bg,bb;
ba = video::SColor(getAlpha(ImgB[i])).color;
br = video::SColor(getRed(ImgB[i])).color;
bg = video::SColor(getGreen(ImgB[i])).color;
bb = video::SColor(getBlue(ImgB[i])).color;
if (TempR == 0)
ImgTemp[i] = video::SColor(aa,ar,ag,ab).color;
if (TempR > 0)
ImgTemp[i] = video::SColor(ba,br,bg,bb).color;
}
TestBit->unlock();
TestBita->unlock();
TestBitb->unlock();
Code: Select all
const c8* testimg = "Template.bmp";
const c8* testimga = "Grass.jpg";
const c8* testimgb = "Path.jpg";
video::ITexture* TestBit;
video::ITexture* TestBita;
video::ITexture* TestBitb;
TestBit=driver->getTexture(testimg);
TestBita=driver->getTexture(testimga);
TestBitb=driver->getTexture(testimgb);
u32* ImgTemp = (u32*)TestBit->lock();
u32* ImgA = (u32*)TestBita->lock();
u32* ImgB = (u32*)TestBitb->lock();
for(u32 i=0; i < TestBit->getSize().Width * TestBit->getSize().Height; i++)
{
s32 TempA,TempR,TempG,TempB;
TempR = video::SColor(ImgTemp[i]).getRed();
if (TempR == 0)
ImgTemp[i] = ImgA[i];
if (TempR > 0)
ImgTemp[i] = ImgB[i];
}
TestBit->unlock();
TestBita->unlock();
TestBitb->unlock();
Code: Select all
video::ITexture* TestBit = driver->getTexture("Template.bmp");
video::ITexture* TestBita = driver->getTexture("Grass.jpg");
video::ITexture* TestBitb = driver->getTexture("Path.jpg");
u32* ImgTemp = (u32*)TestBit->lock();
u32* ImgA = (u32*)TestBita->lock();
u32* ImgB = (u32*)TestBitb->lock();
for(u32 i=0; i < TestBit->getSize().Width * TestBit->getSize().Height; i++)
{
if (video::SColor(ImgTemp[i]).getLuminance() == 0)
ImgTemp[i] = ImgA[i];
else
ImgTemp[i] = ImgB[i];
}
TestBit->unlock();
TestBita->unlock();
TestBitb->unlock();
Code: Select all
void *p = TestBit->lock();
video::IImage *image = video::IImage *image = driver->createImageFromData(video::ECF_A8R8G8B8, TestBit->getSize(), p);
driver->writeImageToFile(image, "result.bmp");
TestBit->unlock();
What Irrlicht version are you using? For me it compile fine on OpenGl and Irrlicht 1.3virtual bool irr::video::IVideoDriver::writeImageToFile(IImage *image, const c8 *filename) [pure virtual]
Writes the provided image to disk file.
Requires that there is a suitable image writer registered for writing the image to disk
Parameters:
image,: Image to write to disk
filename,: name of the file to write
Returns:
Returns true on success