![]() |
|
[A5] al_load_bitmap_f fails |
kakadas
Member #15,298
September 2013
|
I have a problem loading a bitmap from memory with al_load_bitmap_f. Here's the situation: The bitmap data is in class1, and I get it from class2, which is derived class. Here's my code extract: 1al_file_Data = al_open_memfile(class1::Image_Data, class1::Image_Size, "r");
2
3if (!al_file_Data)
4 printf("memfile loading didn't work :( ");
5
6al_bmp_ScreenShot = al_load_bitmap_f(al_file_Data, ".bmp");
7
8if (!al_bmp_ScreenShot)
9 printf("loading bitmap from data didn't work :( ");
To me the code seems legit and should work fine. I wrote class1::Image_Data to disk and confirmed that the image is valid. Could Anyone tell me any reasons for al_load_bitmap_f failing? |
ph03nix
Member #15,028
April 2013
![]() |
Do you call al_init and al_init_image_addon before this? Also, is your bitmap data of a bmp file, as you specified in al_load_bitmap_f? |
SiegeLord
Member #7,827
October 2006
![]() |
This code works for me: 1#include <allegro5/allegro5.h>
2#include <allegro5/allegro_image.h>
3#include <allegro5/allegro_memfile.h>
4#include <stdlib.h>
5
6int main()
7{
8 al_init();
9 al_init_image_addon();
10 ALLEGRO_DISPLAY* display = al_create_display(800, 600);
11
12 ALLEGRO_BITMAP* bitmap = al_load_bitmap("test.bmp");
13 assert(bitmap);
14
15 ALLEGRO_FILE* file = al_fopen("test.bmp", "rb");
16 assert(file);
17
18 int64_t size = al_fsize(file);
19 assert(size > 0);
20
21 void* data = malloc(size);
22 al_fread(file, data, size);
23
24 ALLEGRO_FILE* memfile = al_open_memfile(data, size, "rb");
25
26 ALLEGRO_BITMAP* bitmap2 = al_load_bitmap_f(memfile, ".bmp");
27 assert(bitmap2);
28
29 ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue();
30 al_register_event_source(queue, al_get_display_event_source(display));
31
32 bool quit = false;
33 while(!quit)
34 {
35 ALLEGRO_EVENT event;
36 if(al_get_next_event(queue, &event))
37 {
38 if(event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
39 quit = true;
40 }
41 al_draw_bitmap(bitmap, 0, 0, 0);
42 al_draw_bitmap(bitmap2, 100, 100, 0);
43 al_flip_display();
44 }
45
46 return 0;
47}
Check to see that the class1::ImageSize is right and if that is fine, then post the bitmap here... Allegro has trouble with some bitmap files (we suggest you use png/tga for that reason). "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
kakadas
Member #15,298
September 2013
|
ph03nix said: Do you call al_init and al_init_image_addon before this? Also, is your bitmap data of a bmp file, as you specified in al_load_bitmap_f? Wow, such a terrible mistake I made... I think I need to take a little break... Anyway, thanks for the reply. |
|