1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <meta name="keywords" content="Simple Directmedia Layer SDL2.0">
7 <link rel="top" href="index.html" title="
\83z
\81[
\83\80">
8 <link rel="parent" href="CategorySurface.html" title="1
\82Â
\8fã">
9 <title>SDL_CreateRGBSurfaceWithFormatFrom</title>
12 <a href="index.html">
\96Ú
\8e\9f</a> - <a href="ApiByCategory.html">API(
\8b@
\94\
\95Ê)</a> - <a href="CategorySurface.html">
\83T
\81[
\83t
\83F
\83C
\83X
\82Ì
\90¶
\90¬
\82Æ
\92P
\8f\83\82È
\95`
\89æ</a> - SDL_CreateRGBSurfaceWithFormatFrom
14 <h1>SDL_CreateRGBSurfaceWithFormatFrom</h1>
15 \8aù
\91¶
\82Ì
\83s
\83N
\83Z
\83\8b\83f
\81[
\83^
\82©
\82ç
\90V
\82µ
\82¢RGB
\83T
\81[
\83t
\83F
\83C
\83X
\82ð
\90¶
\90¬
\82·
\82é
17 <code>SDL_Surface* SDL_CreateRGBSurfaceWithFormatFrom(void* pixels, int width, int height, int depth, int pitch, Uint32 format)</code>
19 <table border="1" summary="SDL_CreateRGBSurfaceWithFormatFrom">
20 <tr><td>pixels</td><td>
\8aù
\91¶
\82Ì
\83s
\83N
\83Z
\83\8b\83f
\81[
\83^
\82Ö
\82Ì
\83|
\83C
\83\93\83^</td></tr>
21 <tr><td>width</td><td>
\83T
\81[
\83t
\83F
\83C
\83X
\82Ì
\95\9d</td></tr>
22 <tr><td>height</td><td>
\83T
\81[
\83t
\83F
\83C
\83X
\82Ì
\8d\82\82³</td></tr>
23 <tr><td>depth</td><td>
\83T
\81[
\83t
\83F
\83C
\83X
\82Ì
\83r
\83b
\83g
\90[
\93x</td></tr>
24 <tr><td>pitch</td><td>pixels
\82Ì
\90\85\95½
\95û
\8cü
\82Ì
\83o
\83C
\83g
\90\94</td></tr>
25 <tr><td>format</td><td>
\83T
\81[
\83t
\83F
\83C
\83X
\82Ì<a href="SDL_PixelFormatEnum.html">
\83s
\83N
\83Z
\83\8b\8c`
\8e®</a></td></tr>
28 \90¬
\8c÷
\82Ì
\82Æ
\82«
\90¶
\90¬
\82³
\82ê
\82½<a href="SDL_Surface.html">SDL_Surface</a>,
\8e¸
\94s
\82Ì
\82Æ
\82«NULL
\82ð
\96ß
\82·.
29 <a href="SDL_GetError.html">SDL_GetError()</a>
\82ð
\8cÄ
\82ñ
\82Å
\8fÚ
\8d×
\82ð
\92m
\82é
\82±
\82Æ
\82ª
\82Å
\82«
\82é.
30 <h2>
\83T
\83\93\83v
\83\8b\83R
\81[
\83h</h2>
34 // stb_image.h
\82ð
\8eg
\82Á
\82Ä
\93Ç
\82Ý
\8d\9e\82ñ
\82¾
\89æ
\91\9c\83t
\83@
\83C
\83\8b\82©
\82çSDL_Surface*
\82ð
\90¶
\90¬
\82·
\82é
\83T
\83\93\83v
\83\8b
35 // (https://github.com/nothings/stb/)
37 // stb_image
\82É
\97v
\8b\81\82·
\82é
\8fo
\97Í
\82Ì
\83J
\83\89\81[
\8c`
\8e®
38 //
\83¿
\83`
\83\83\83l
\83\8b\82ð
\8b\81\82ß
\82È
\82¢/
\95K
\97v
\82È
\82¢
\82È
\82ç
\82ÎSTBI_rgb
\82ð
\8eg
\82¤
\82±
\82Æ
39 int req_format = STBI_rgb_alpha;
40 int width, height, orig_format;
41 unsigned char* data = stbi_load("./test.png", &width, &height, &orig_format, req_format);
43 SDL_Log("
\89æ
\91\9c\82Ì
\93Ç
\82Ý
\8d\9e\82Ý
\82É
\8e¸
\94s
\82µ
\82½: %s", stbi_failure_reason());
49 if (req_format == STBI_rgb) {
51 pitch = 3*width; // 1
\83s
\83N
\83Z
\83\8b\82 \82½
\82è3byte * 1
\8ds
\82Ì
\83s
\83N
\83Z
\83\8b\90\94
52 pixel_format = SDL_PIXELFORMAT_RGB24;
53 } else { // STBI_rgb_alpha (RGBA)
56 pixel_format = SDL_PIXELFORMAT_RGBA32;
59 SDL_Surface* surf = SDL_CreateRGBSurfaceWithFormatFrom((void*)data, width, height,
60 depth, pitch, pixel_format);
63 SDL_Log("
\83T
\81[
\83t
\83F
\83C
\83X
\82Ì
\90¶
\90¬
\82É
\8e¸
\94s
\82µ
\82½: %s", SDL_GetError());
64 stbi_image_free(data);
68 // ...
\82±
\82±
\82Å
\83T
\81[
\83t
\83F
\83C
\83X
\82ð
\8eg
\82¤ ...
71 //
\83T
\81[
\83t
\83F
\83C
\83X
\82ª
\95K
\97v
\82È
\82
\82È
\82Á
\82½
\82ç
\89ð
\95ú
\82·
\82é...
72 SDL_FreeSurface(surf);
73 // .. *
\82»
\82µ
\82Ä*
\83T
\81[
\83t
\83F
\83C
\83X
\82Å
\8eg
\82Á
\82½
\83f
\81[
\83^
\82à!
74 stbi_image_free(data);
80 \83\81\83\82\83\8a\82ð
\8am
\95Û
\82Å
\82«
\82È
\82©
\82Á
\82½
\82Æ
\82«
\82ÍNULL
\82ð
\96ß
\82·.
83 \83s
\83N
\83Z
\83\8b\83f
\81[
\83^
\82Í
\83R
\83s
\81[
\82³
\82ê
\82È
\82¢.
84 \83s
\83N
\83Z
\83\8b\83f
\81[
\83^
\82Í
\8e©
\93®
\93I
\82É
\8aÇ
\97\9d\82³
\82ê
\82È
\82¢.
\82Â
\82Ü
\82è,
\83s
\83N
\83Z
\83\8b\83f
\81[
\83^
\82ð
\89ð
\95ú
\82·
\82é
\91O
\82É
\83T
\81[
\83t
\83F
\83C
\83X
\82ð
\89ð
\95ú
\82·
\82é
\95K
\97v
\82ª
\82 \82é.
86 <h2>
\83o
\81[
\83W
\83\87\83\93</h2>
88 \82±
\82Ì
\8aÖ
\90\94\82ÍSDL 2.0.5
\88È
\8d~
\82Å
\8eg
\82¦
\82é.
90 <h2>
\8aÖ
\98A
\8d\80\96Ú(
\8aÖ
\90\94)</h2>
91 <a href="SDL_CreateRGBSurfaceFrom.html">SDL_CreateRGBSurfaceFrom</a><br>
92 <a href="SDL_CreateRGBSurfaceWithFormat.html">SDL_CreateRGBSurfaceWithFormat</a><br>
93 <a href="SDL_FreeSurface.html">SDL_FreeSurface</a><br>
94 <h2>SDL Wiki
\82Ö
\82Ì
\83\8a\83\93\83N</h2>
95 <a href="https://wiki.libsdl.org/SDL_CreateRGBSurfaceWithFormatFrom">SDL_CreateRGBSurfaceWithFormatFrom - SDL Wiki</a>