Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » al_save_bitmap not working!

Credits go to SiegeLord for helping out!
This thread is locked; no one can reply to it. rss feed Print
al_save_bitmap not working!
Don Freeman
Member #5,110
October 2004
avatar

I'm trying to convert some images for my game's assets but for some reason al_save_bitmap is not working. I have called al_init_image_addon during startup. Below is the offending code:

#SelectExpand
1oid ConvertUnitSmallImages( void ) 2{ 3 ALLEGRO_BITMAP *tmp = al_create_bitmap(320,128); 4 if ( !tmp ) 5 return; 6 for ( UInt type = 0; type < 18; type++ ) 7 { 8 ALLEGRO_STATE state; 9 al_store_state(&state,ALLEGRO_STATE_TARGET_BITMAP); 10 al_set_target_bitmap(tmp); 11 al_clear_to_color(al_map_rgb(255,0,255)); 12 UInt x = 0; 13 UInt y = 0; 14 for ( UInt direction = 0; direction < 4; direction++ ) 15 { 16 for ( UInt side = 0; side < 7; side++ ) 17 { 18 for ( UInt frame = 0; frame < 2; frame++ ) 19 { 20 DrawSmallUnitEx(type,side,direction,frame,x,y,32,32,0); 21 x+=32; 22 } 23 } 24 y+=32; 25 x = 0; 26 } 27 al_restore_state(&state); 28 al_draw_bitmap(tmp,0,0,0); 29 al_flip_display(); 30 String fileName = "./gfx/Units/Small/New/"; 31 fileName+=g_UnitFileNames[type]; 32 fileName+="N.bmp"; 33 if ( al_save_bitmap(fileName.c_str(),tmp) ) 34 std::cout<<"Image saved to: "<<fileName<<"\n"; 35 else 36 std::cout<<"Image NOT saved: "<<fileName<<"\n"; 37 } 38 al_destroy_bitmap(tmp); 39 tmp = NULL; 40} 41///////////////////////////////////////////////////////////////////////////////

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

SiegeLord
Member #7,827
October 2006
avatar

Does the /gfx/Units/Small/New/ exist? Also, try making a file using al_fopen(fileName.c_str(), "w") and see if that returns a non-NULL.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Don Freeman
Member #5,110
October 2004
avatar

Both give an error. And yes, gfx/Units/Small/New exists. I've even tried to run as administrator thinking write permissions, but still can't.

Edit:
On a side note, I am using the physfs interface as well...even though I don't think that should hurt in this case. Maybe it's making things read only...

Edit 2:
It was PhysFS setting the directory read only....

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

Go to: