Home > Software engineering >  Directx10 D3DX10CreateShaderResourceViewFromMemory how to load images in memory
Directx10 D3DX10CreateShaderResourceViewFromMemory how to load images in memory

Time:09-22

Official documentation described in this much,,,, because the company has such a request, has a group of custom format images to draw in the game, this group of pictures to my hand is a structure that has the size, type of these unknown in detail, there is a pointer to the RGBA data flow, let me put this texture of load flow to direct resources,

And I had always made with D3DX10CreateShaderResourceViewFromFile so do not know how,,, see the documentation later found D3DX10CreateShaderResourceViewFromMemory this function, don't know, can realize the function I want to have a D3DX10_IMAGE_LOAD_INFO to fill in, try many filling method still create is not successful, then in the official samples found an example from the memory load inside, but it is the inside of the data flow of DDS,,, can be loaded but I only RGBA data flow,,,, with its parameters to fill D3DX10_IMAGE_LOAD_INFO cannot be loaded have great god know how thanks! ~!!!!!!!!!!!

CodePudding user response:

Is there a conversion function

CodePudding user response:

Fyi:
 # pragma comment (lib, "user32") 
# pragma comment (lib, "gdi32")
#include
#include
#include
#include
#include
#include
#include
Void DrawPic (HDC HDC, char * buf, int len) {
HGLOBAL hMem=GlobalAlloc (GMEM_FIXED, len);
BYTE * pMem=(BYTE *) GlobalLock (hMem);
Memcpy (pMem, buf, len);
Cost * pStream;
Retrieves the hr=CreateStreamOnHGlobal (pMem, FALSE, & amp; PStream);

CImage img.
Img. Load (pStream);
Img. The Draw (HDC, CPoint (0, 0));

Img. Destroy ();
PStream - & gt; Release ();
GlobalUnlock (hMem);
GlobalFree (hMem);
}
//HWND WINAPI GetConsoleWindow ();
Void HideTheCursor () {
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut=GetStdHandle (STD_OUTPUT_HANDLE);
If (GetConsoleCursorInfo (hStdOut, & amp; CciCursor)) {
CciCursor. BVisible=FALSE;
SetConsoleCursorInfo (hStdOut, & amp; CciCursor);
}
}
Void ShowTheCursor () {
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut=GetStdHandle (STD_OUTPUT_HANDLE);
If (GetConsoleCursorInfo (hStdOut, & amp; CciCursor)) {
CciCursor. BVisible=TRUE;
SetConsoleCursorInfo (hStdOut, & amp; CciCursor);
}
}
Int main () {
The HWND HWND;
HDC HDC.
HFONT HFONT;
HBITMAP HBM;
HDC hdcBits;
BITMAP bm.

System (" color F0 ");
System (" CLS ");
HideTheCursor ();
HWND=GetConsoleWindow ();
HDC=GetDC (HWND);
Hfont=CreateFont (48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Chinese regular script");
SelectObject (HDC, hfont);
TextOut (HDC, 10, 10, "this is a bubble," 8);
DeleteObject (hfont);
HBM=(HBITMAP) LoadImage (0, "C: \ \ Windows \ \ Soap Bubbles. BMP", IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
If (HBM) {
HdcBits=CreateCompatibleDC (HDC);
GetObject (HBM, sizeof (BITMAP), & amp; Bm);
SelectObject (hdcBits, HBM);
BitBlt (HDC, 200, 10, bm. BmWidth, bm. BmHeight, hdcBits, 0, 0, SRCCOPY);
DeleteDC (hdcBits);
DeleteObject (HBM);
}
getch();
The FILE * f;
F=fopen (c: \ \ "new \ \ TMP JPG", "rb");
If (f) {
Int fl=filelength (fileno (f));
Char * buf=(char *) malloc (fl);
If (buf) {
Fread (buf, fl, 1, f);
}
The fclose (f);
If (buf) {
DrawPic (HDC, buf, fl);
Free (buf);
}
}
ReleaseDC (HWND, HDC);
getch();
07 system (" color ");
System (" CLS ");
ShowTheCursor ();
return 0;
}

CodePudding user response:

Give you a write from memory before loading is similar to function of BMP format


Struct WIMAGE {
Short width;
Short height.
Short ox;
Short oy.
};


Bool CImageResource: : GetImage (_In_ DWORD nImg, HTEXTURE& Texture, _Out_ WIMAGE& Img)
{
Const COLORREF keyColor=RGB (0, 0);

If (nImg & gt;=m_imgCount)
Return false;

If (m_Textures [nImg])
{
Texture=m_Textures [nImg];
Img=m_Images [nImg];
return true;
}

WIMAGE * wi=& amp; M_Images [nImg];
//is the key code below
Char * lpImageData;
DWORD dwPerLine;
DWORD dwPerPixelBits;
If (m_ColorDepth==256)
DwPerPixelBits=1;
The else
DwPerPixelBits=2;

DWORD dwPad=(1000 * dwPerPixelBits) % 4.
DwPerLine=1000 * dwPerPixelBits + 4 - ((dwPad==0)? 4: dwPad);

DWORD dwTrueOffset=m_Offsets [nImg] % m_dwAlloc;
LpImageData=https://bbs.csdn.net/topics/(char *) MapViewOfFile (m_hMapped FILE_MAP_READ, 0, m_Offsets nImg - dwTrueOffset, dwPerLine * 1000 + dwTrueOffset);
If (! LpImageData)
Return false;

* wi=* (WIMAGE *) (lpImageData + dwTrueOffset);

DwPerLine=wi - & gt; 4 - (width * dwPerPixelBits + (dwPad==0)? 4: dwPad);

//create a texture
M_Textures [nImg]=lzy - & gt; Texture_Create (wi - & gt; Width, wi - & gt; Height);
If (! M_Textures [nImg])
{
UnmapViewOfFile (lpImageData);
Return false;
}

Lzy - byte * PTR=(byte *) & gt; Texture_Lock (m_Textures [nImg]);
If (! PTR)
{
Lzy - & gt; Texture_Free (m_Textures [nImg]);
UnmapViewOfFile (lpImageData);
Return false;
}

Char * lpTrueData=https://bbs.csdn.net/topics/lpImageData + dwTrueOffset + 8;

If (m_ColorDepth==256)
{
for (int i=0; i {
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related