loading a bitmap from memory

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • loading a bitmap from memory

      Hi all:)
      Now that i managed to load a file into memory from a zipfile i got to the next problem:)

      I used to use this function to load bitmaps onto a Surface

      lpddsBitmap = DDLoadBitmap(lpdd, file , width, height);

      can i use the same funktion to load a bitmap from memory?

      can anyone point me to a place i can find something to read up on this?

      thx a lot in advance
    • RE: loading a bitmap from memory

      I believe what you are looking for is called "blitting"

      You aren't "loading" the bitmap from memory, you are copying it from one spot to another. I'm making this distinction because if you decide to use Google for help, you want to know what to look for.

      To be honest, I tend to deal more with architectures than actual graphics, so I could be wrong (I'm pretty confident, though).
      -Larrik Jaerico


      The post was edited 1 time, last by Larrik ().

    • RE: loading a bitmap from memory

      I think I know what's going on - you want to use a resource cache with Direct Draw. DirectDraw should have a "make bitmap from memory" API to allow you to do that - and I'm almost certain there is one, but I can't remember the name.

      What version of DirectX are you using? 7?
      Author, Programmer, Brewer, Patriot
    • RE: loading a bitmap from memory

      Do you have a HBITMAP, or a pointer to the raw data?

      If you have a HBITMAP, use

      Source Code

      1. DDCopyBitmap(pdds, hbm, 0, 0, 0, 0);

      this copies a HBITMAP (hbm) to a DDRAWSURFACE7*(pdds)

      It's what DDLoadBitmap calls once it gets the bitmap from the resource or the disk. If you're using these calls you must have access to ddutil.h - open it up and take a look at what DDLoadBitmap is doing.

      If you have a pointer to the raw data, you need a good book on DirectDraw - there's a lot to consider such as memory pitch, bit depth etc.

      If you want to use the D3D approach, google D3DXCreateSprite and see what you find.

      this hit looked promising...


      The post was edited 1 time, last by pjeffrey ().

    • RE: loading a bitmap from memory

      Yep i am useing DirectDraw7

      and here is what i tried to do but its not working

      char *buffer = NULL;

      CZipFile *zipFile=new CZipFile();
      int index = zipFile->Find("GreenIso.bmp");
      int size = zipFile->GetFileLen(index);
      buffer = new char[size];
      zipFile->ReadFile(index, buffer);
      ThrowError::Error("Could not open Resfile");
      ThrowError::Error("Could not open Resfile");

      //Make sure this is set up to your data
      const char *BMPdata = buffer;

      //Skip the file header, since we assume it is correct
      BMPdata += sizeof (BITMAPFILEHEADER);

      //Get the format header
      BMPdata += sizeof (BITMAPINFOHEADER);

      //Get width, height, bits per pixel stride and size
      int width = bmih->biWidth;
      int height = bmih->biHeight;
      int bpp = bmih->biBitCount;
      int stride = ((bpp >> 3) * width + 3) & ~3;
      int size = stride * height;

      //Create a memory DC
      HDC hdc = CreateCompatibleDC (NULL);

      //Create a bitmap object
      char *bits = NULL;
      HBITMAP newbmp = CreateDIBSection (hdc, (BITMAPINFO *)bmih, DIB_RGB_COLORS, (void **)&bits, NULL, 0);

      //Copy the data
      memcpy (bits, BMPdata, size);

      //Select the bitmap into the memory DC
      HBITMAP oldbmp = (HBITMAP)SelectObject (hdc, newbmp);

      /** This is where you should do a BitBlt from the memory DC to your surface's DC **/

      //Create a Surface:
      if(!(mysurf = DDraw_Create_Surface(lpdd,width,height,DDSCAPS_VIDEOMEMORY))){
      ThrowError::Error("Could not Create Surface");
      DDBLTFX ddbltfx; // used to fill
      ddbltfx.dwSize = sizeof(DDBLTFX);
      ddbltfx.dwFillColor = RGB(0, 0, 0);
      RECT fill;
      SetRect(&fill, 0, 0, width,height);
      if(FAILED(mysurf->Blt(&fill, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx))){
      ThrowError::Error("Could not fill with black");
      //get SurfaceHDC
      HDC mysurfhdc;
      //Blt to Surface
      if (!BitBlt(mysurfhdc,0,0,width, height, hdc,0,0,SRCCOPY)) {
      ThrowError::Error("Could not blt to my surf");
      //Blt to Backsurface
      RECT source;
      SetRect(&source, 0, 0, 40,40);
      RECT dest;
      if(FAILED(lpddsback->Blt(&dest,mysurf,&source,(DDBLT_WAIT | DDBLT_KEYSRC),NULL)))
      ThrowError::Error("Could not blit to back");

      it does compile but the last error is thrown
    • RE: loading a bitmap from memory

      DirectDraw, if I remember correctly, is very sensitive about bit depth of the surface. You'll want to look at the error code to be sure.
      Author, Programmer, Brewer, Patriot
    • RE: loading a bitmap from memory

      Good for you!
      Author, Programmer, Brewer, Patriot