0

I was trying to pack multiple images in a single image, using Bin Packing algorithm. In the part of adding images in a single image I was trying with collecting all the image pixel values and put them in the empty frame, but this is not working. Is there any suggestions?

Hi Edited the question,

` FIBITMAP *out_bmp = FreeImage_Allocate(4096, 4096, 32, 0, 0, 0);
 BYTE *out_bits = FreeImage_GetBits(out_bmp);
 int out_pitch = FreeImage_GetPitch(out_bmp); 
 // copy all the images to the final one
 for (int i = 0; i < files.size(); i++) {
    string s = "PathToFile" + files[i];
    FIBITMAP* img0 = FreeImage_Load(FreeImage_GetFileType(s.c_str(), 0), s.c_str());
    // make sure the input picture is 32-bits
    if (FreeImage_GetBPP(img0) != 32) {
        FIBITMAP *new_bmp = FreeImage_ConvertTo32Bits(img0);
        FreeImage_Unload(img0);
        img0 = new_bmp;
    }

    int img_pitch = FreeImage_GetPitch(img0);
    BYTE *img_bits = FreeImage_GetBits(img0);
    BYTE *out_bits_ptr = out_bits + out_pitch * 
    FreeImage_GetHeight(img0) + 4 * FreeImage_GetWidth(img0);

    for (int y = 0; y < FreeImage_GetHeight(img0); y += 1) {
        memcpy(out_bits_ptr, img_bits, FreeImage_GetWidth(img0) * 4);
        out_bits_ptr += out_pitch;
        img_bits += img_pitch;
    }
}`
ikhaled28
  • 1
  • 5
  • Your problem would suggest a bug in your code, but we can't see that. – Retired Ninja Mar 09 '18 at 02:59
  • Hi Update the question, please can you have a look? – ikhaled28 Mar 09 '18 at 14:52
  • Explain "not working". At a glance there's no packing being done at all, instead all of the bitmaps are pasted pretty much on top of each other offset in the destination by their width and height. – Retired Ninja Mar 09 '18 at 15:12
  • Hi I didn't added the packing intentionally, First I was trying to make a single image from all the images. Thats why I just added the part where I was trying to make the single image. – ikhaled28 Mar 09 '18 at 16:47
  • Okay, but you still have not explained the issue. Is your image blank? Is your code crashing? This isn't a full example and we don't have your data anyway so nobody can run it but you. You need to explain what the problem is. – Retired Ninja Mar 09 '18 at 23:34

0 Answers0