How to display an image ?

16 posts / 0 new
Last post
YesCop
YesCop's picture
Offline
Last seen: 2 years 1 month ago
Joined: 2011-05-17 15:07
How to display an image ?
Hi, I would want to open a new screen and display an image (using datatype or not). I read the docs but it is not clear enough for me (especially displaying images). It is surely an obvious question. This will change a little from questions about guis ! Thanks, YesCop
Hans
Hans's picture
Offline
Last seen: 3 months 2 weeks ago
Joined: 2010-12-09 22:04
Do you want to add an image
Do you want to add an image to a GUI? Or do you just want to draw it anywhere on screen? For the former Reaction has an image class. If it's the latter that you're after, then load the image using datatypes, extract the image's bitmap (converting it to the screen's pixel-format), and use the graphics library to blit that onto the screen. If you use CompositeTags(), then you can even scale/warp the image. I don't have any example code, sorry. However, have a look at the picture datatype and graphics library's documentation. If you're still stuck then post back here with more specific questions. Hans
http://hdrlab.org.nz/ - Amiga OS 4 projects, programming articles and more. Home of the RadeonHD driver for Amiga OS 4.x project. http://keasigmadelta.co.nz/ - more of my software.
YesCop
YesCop's picture
Offline
Last seen: 2 years 1 month ago
Joined: 2011-05-17 15:07
Hi Hans, I thank you for our
Hi Hans, I thank you for our reply, I will take a look. My purpose is to open a new screen and load an image as background. No gui, no window. If you have some examples, I will accept these with ease. YesCop
corto
corto's picture
Offline
Last seen: 5 years 7 months ago
Joined: 2011-09-09 11:43
I wrote this article years
I wrote this article years ago, "Display an image on a private screen" : http://www.gurumed.net/index.php/Exemple_d'affichage_d'une_image_sur_un_écran_privé I don't know if it needs an update but at least you can start with this example.
YesCop
YesCop's picture
Offline
Last seen: 2 years 1 month ago
Joined: 2011-05-17 15:07
Bonjour/hello Corto, I was
Bonjour/hello Corto, I was happy when I read your post but I became sad because the link is dead... If you have a copy of your article, please free to post it here or send it to me. YesCop
trixie
trixie's picture
Offline
Last seen: 1 month 1 week ago
Joined: 2011-02-03 13:58
@YesCop Don't click on the
@YesCop Don't click on the link, copy the address from "http:" all the way to "écran_privé" and paste it in your browser's address box. It works.
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
YesCop
YesCop's picture
Offline
Last seen: 2 years 1 month ago
Joined: 2011-05-17 15:07
Hi Trixie, Thanks. I have
Hi Trixie, Thanks. I have just found it. The link is http://www.gurumed.net/index.php/Exemple_d%27affichage_d%27une_image_sur_un_%C3%A9cran_priv%C3%A9
salass00
salass00's picture
Offline
Last seen: 2 months 2 days ago
Joined: 2011-02-03 11:27
@corto and YesCop You should
@corto and YesCop You should use the url tag for long links like that as otherwise they break the forum page layout. The format for bbcode url tag is (remove the spaces before and after the square brackets to make it work): [ url=http://your/url/here ] short-label-here [ /url ]
tekmage
tekmage's picture
Offline
Last seen: 1 month 4 weeks ago
Joined: 2011-10-09 03:19
I'd like to see some examples
I'd like to see some examples pasted here. Even simple things like how to put an image in reaction, Window Background, Screen Background, etc. On a side note, is there a place to put code snippets on this site?
salass00
salass00's picture
Offline
Last seen: 2 months 2 days ago
Joined: 2011-02-03 11:27
Adding an image to a ReAction
Adding an image to a ReAction layout is very simple (just use LAYOUT_AddImage to add a bitmap.image object). This is the code I used to create the GUI in IPS-O-Matic f.e.:
  1. gui->window = WindowObject,
  2. WA_Title, VERS,
  3. WA_Flags, WFLG_CLOSEGADGET|WFLG_DRAGBAR|WFLG_DEPTHGADGET
  4. |WFLG_ACTIVATE|WFLG_NEWLOOKMENUS,
  5. WA_IDCMP, IDCMP_CLOSEWINDOW|IDCMP_GADGETUP|IDCMP_MENUPICK,
  6. WA_PubScreen, gui->screen,
  7. WINDOW_CharSet, li->li_CodeSet,
  8. WINDOW_Position, WPOS_CENTERSCREEN,
  9. WINDOW_AppPort, gui->appmp,
  10. WINDOW_AppWindow, TRUE,
  11. WINDOW_IconifyGadget, TRUE,
  12. WINDOW_AppMsgHook, &appmsghook,
  13. WINDOW_Icon, AppIcon,
  14. WINDOW_IconTitle, progname,
  15. WINDOW_IconNoDispose, TRUE,
  16. WINDOW_NewMenu, menuspecs,
  17. WINDOW_Layout, VLayoutObject,
  18. LAYOUT_AddImage, BitMapObject,
  19. BITMAP_Screen, gui->screen,
  20. BITMAP_Masking, TRUE,
  21. BITMAP_Transparent, TRUE,
  22. BITMAP_SourceFile, "PROGDIR:ipsomatic.png",
  23. End,
  24. LAYOUT_AddChild, VLayoutObject,
  25. LAYOUT_BevelStyle, BVS_GROUP,
  26. LAYOUT_Label, GetString(li, MSG_SELECTFILES_GRP),
  27. LAYOUT_AddChild, gui->gadgets[GID_ROM_FILE] = GetFileObject,
  28. GA_ID, GID_ROM_FILE,
  29. GA_RelVerify, TRUE,
  30. End,
  31. CHILD_Label, LabelObject,
  32. LABEL_Text, GetString(li, MSG_ROMFILE_GAD),
  33. End,
  34. LAYOUT_AddChild, gui->gadgets[GID_PATCH_FILE] = GetFileObject,
  35. GA_ID, GID_PATCH_FILE,
  36. GA_RelVerify, TRUE,
  37. End,
  38. CHILD_Label, LabelObject,
  39. LABEL_Text, GetString(li, MSG_PATCHFILE_GAD),
  40. End,
  41. LAYOUT_AddChild, gui->gadgets[GID_APPLY] = ButtonObject,
  42. GA_ID, GID_APPLY,
  43. GA_RelVerify, TRUE,
  44. GA_Text, GetString(li, MSG_APPLY_GAD),
  45. End,
  46. End,
  47. End,
  48. End;
YesCop
YesCop's picture
Offline
Last seen: 2 years 1 month ago
Joined: 2011-05-17 15:07
Interesting. I see you give
Interesting. I see you give the filename of the picture. So if I understand well, the bitmap will be created by windowobject. I thought I was obliged to use some calls with datatypes objects to retrieve the bitmap. By the way, Trixie will be unhappy with you, you are not using the NEW laws !! :)
salass00
salass00's picture
Offline
Last seen: 2 months 2 days ago
Joined: 2011-02-03 11:27
So if I understand well, the
So if I understand well, the bitmap will be created by windowobject. I thought I was obliged to use some calls with datatypes objects to retrieve the bitmap.
What is created is a BOOPSI image object (bitmap.image is a subclass of imageclass). The reason you don't need to concern yourself with datatypes or anything like that is because the bitmap.image class takes care of all this work for you. A BOOPSI image is essentially an image that knows how to draw itself when a certain method is called on it.
By the way, Trixie will be unhappy with you, you are not using the NEW laws !! :)
The code is several years old. There's probably a lot of other things in there that I would do differently now.
tekmage
tekmage's picture
Offline
Last seen: 1 month 4 weeks ago
Joined: 2011-10-09 03:19
Hi All, I've taken a crack
Hi All, I've taken a crack at the code from the URL listed and I've run in to some snags. The code will compile, just some warnings about calls to quit. When I run it I see the following output: Opened libraries Created datatype object got GetDTAttrs Then I the grim, "module display-photo at 0x7FC50488 (section 5 @ 0x468)" I hope it's ok to post the code here.
  1. /*
  2.  * Affichage d'une image sur un écran privé grâce aux datatypes
  3.  * Par Corto pour www.guru-meditation.net
  4.  * Date : 21/01/03
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.  
  10. #include <exec/exec.h>
  11. #include <dos/dos.h>
  12. #include <intuition/intuition.h>
  13. #include <graphics/gfx.h>
  14. #include <graphics/display.h>
  15.  
  16. #include <datatypes/datatypesclass.h>
  17. #include <datatypes/pictureclass.h>
  18.  
  19. #include <proto/exec.h>
  20. #include <proto/intuition.h>
  21. #include <proto/dos.h>
  22. #include <proto/graphics.h>
  23. #include <proto/datatypes.h>
  24.  
  25. // Variables communes au module
  26. struct Screen * screen = NULL;
  27. struct Window * window = NULL;
  28. struct Library * IntuitionBase = NULL;
  29. struct Library * GfxBase = NULL;
  30. struct Library * DataTypesBase = NULL;
  31.  
  32. struct IntuitionIFace * IIntuition = NULL;
  33. struct GraphicsIFace * IGraphics = NULL;
  34. struct DataTypesIFace * IDatatypes = NULL;
  35. //struct ExecIFace * IExec = NULL;
  36.  
  37. ULONG *palette = NULL;
  38. Object *dtype = NULL;
  39.  
  40. // Prototypes
  41. static void quit(char *msg);
  42. static ULONG *adaptCmap(int nc, ULONG *cr);
  43.  
  44.  
  45. /*
  46.  * Code du programme principal
  47.  */
  48. int main(int argc, char*argv[]){
  49. ULONG modeID = 0L;
  50. struct BitMapHeader *bmh = NULL;
  51. int width, height, depth;
  52. ULONG res;
  53. struct BitMap *bitmap = NULL;
  54. ULONG colorNumber;
  55. ULONG *colorRegisters;
  56.  
  57.  
  58. /* Vérification des arguments */
  59. if (argc != 2){
  60. printf("Usage : %s Image file\n", argv[0]);
  61. return(1);
  62. }
  63.  
  64. /* Ouverture des bibliothèques nécessaires */
  65. IntuitionBase = IExec->OpenLibrary("intuition.library", 36);
  66. GfxBase = IExec->OpenLibrary("graphics.library", 40L);
  67. DataTypesBase = IExec->OpenLibrary("datatypes.library", 39);
  68.  
  69. printf("Opened libraries\n");
  70.  
  71. if ((IntuitionBase == NULL) || (DataTypesBase == NULL || (GfxBase == NULL) ) ){
  72. quit("problem setting up intuitionBase, DataTypesBase, and GraphicsBase\n");
  73. }
  74.  
  75.  
  76. /* Création du datatype et récupération des infos générales */
  77. dtype = IDataTypes->NewDTObject( (char *) argv[1],
  78. PDTA_DestMode,
  79. PMODE_V43,
  80. TAG_END);
  81.  
  82. printf("Created datatype object\n");
  83.  
  84. if (dtype == NULL){
  85. quit("Failed to load data type\n");
  86. }
  87.  
  88. res = IDataTypes->GetDTAttrs(dtype, PDTA_BitMapHeader, (ULONG)&bmh, TAG_END);
  89. if (res != 1){
  90. quit("Unable to obtain details of picture from Datatypes\n");
  91. }
  92. width = bmh->bmh_Width;
  93. height = bmh->bmh_Height;
  94. depth = bmh->bmh_Depth;
  95.  
  96. printf("got GetDTAttrs\n");
  97.  
  98. /* Pour l'exemple, on force la profondeur de l'écran à 8 ... */
  99. depth = 8;
  100.  
  101. /* ... et on cherche quel est le meilleur écran 8 bits pour l'image */
  102. modeID = IGraphics->BestModeID(
  103. BIDTAG_NominalWidth, width,
  104. BIDTAG_NominalHeight, height,
  105. BIDTAG_DesiredWidth, width,
  106. BIDTAG_DesiredHeight, height,
  107. BIDTAG_Depth, depth,
  108. TAG_END);
  109.  
  110.  
  111. if (modeID == INVALID_ID){
  112. quit("Unable to open requested ModeID\n");
  113. }
  114.  
  115. printf("set modeID\n");
  116.  
  117. /* Ouverture de l'écran puis de la fenêtre */
  118. screen = IIntuition->OpenScreenTags(NULL,
  119. SA_Width, width,
  120. SA_Height, height,
  121. SA_Title, (ULONG)"Datatype picture display",
  122. SA_DisplayID, modeID,
  123. SA_Depth, depth,
  124. SA_Type, CUSTOMSCREEN,
  125. SA_Interleaved, TRUE,
  126. SA_FullPalette, TRUE,
  127. TAG_END);
  128. if (!screen){
  129. quit("Unable to open requested screen\n");
  130. }
  131.  
  132. window = IIntuition->OpenWindowTags(NULL,
  133. WA_Left, 0,
  134. WA_Top, 0,
  135. WA_Width, width,
  136. WA_Height, height,
  137. WA_IDCMP, IDCMP_RAWKEY | IDCMP_MOUSEBUTTONS,
  138. WA_CustomScreen, (ULONG)screen,
  139. WA_SizeGadget, FALSE,
  140. WA_DepthGadget, FALSE,
  141. WA_CloseGadget, FALSE,
  142. WA_Borderless, TRUE,
  143. WA_RMBTrap, TRUE,
  144. WA_SimpleRefresh, TRUE,
  145. WA_InnerWidth, width,
  146. WA_InnerHeight, height,
  147. TAG_DONE);
  148.  
  149. if (!window){
  150. quit("Unable to open window\n");
  151. }
  152.  
  153. printf("Starting do method\n");
  154.  
  155. if(IDataTypes->DoDTMethod(dtype, NULL, NULL,DTM_PROCLAYOUT, NULL, 1)){
  156.  
  157. printf("Done do method\n");
  158.  
  159. res = IDataTypes->GetDTAttrs(dtype,
  160. PDTA_DestBitMap, (ULONG)&bitmap,
  161. PDTA_NumColors, (ULONG)&colorNumber,
  162. PDTA_CRegs, (ULONG)&colorRegisters,
  163. TAG_DONE);
  164. if (res != 3){
  165. quit("Le chargement de l'image a échoué\n");
  166. }
  167.  
  168. if(bitmap){
  169. palette = adaptCmap(colorNumber, colorRegisters);
  170. IGraphics->LoadRGB32(&screen->ViewPort, palette);
  171. IGraphics->BltBitMapRastPort(bitmap, 0, 0, window->RPort, 0, 0, width, height, 0xc0);
  172. }
  173. }else{
  174. quit("Echec dans l'exécution de la méthode DTM_PROCLAYOUT\n");
  175. }
  176.  
  177. /* Attente et libération ressources */
  178. IExec->WaitPort(window->UserPort);
  179.  
  180. quit(NULL);
  181.  
  182. return 0;
  183. }
  184.  
  185.  
  186. /*
  187. * quit
  188. * Pour sortir proprement en tout point du programme
  189. */
  190. static void quit(char *msg){
  191. if (msg != NULL){
  192. printf("%s\n",msg);
  193. }
  194.  
  195. if (dtype != NULL){
  196. IDataTypes->DisposeDTObject(dtype);
  197. }
  198. if (window != NULL){
  199. IIntuition->CloseWindow(window);
  200. }
  201. if (screen != NULL){
  202. IIntuition->CloseScreen(screen);
  203. }
  204. if (palette != NULL){
  205. free(palette);
  206. }
  207. if (DataTypesBase != NULL){
  208. IExec->CloseLibrary((struct Library *)DataTypesBase);
  209. }
  210. if (IntuitionBase != NULL){
  211. IExec->CloseLibrary((struct Library *)IntuitionBase);
  212. }
  213. if (GfxBase != NULL){
  214. IExec->CloseLibrary((struct Library *)GfxBase);
  215. }
  216. }
  217.  
  218.  
  219. /*
  220.  * adaptCmap
  221.  * Transformation de la palette obtenue par le datatype en une palette
  222.  * système au format LoadRGB32().
  223.  */
  224. static ULONG *adaptCmap(int nc, ULONG *cr){
  225. int c;
  226. ULONG *colourtable;
  227.  
  228. colourtable = (ULONG *)malloc((1 + 3 * nc + 1) * sizeof(ULONG));
  229. if (colourtable != NULL){
  230. colourtable[0] = (nc << 16) + 0;
  231. for (c = 0; c < nc; c++) {
  232. colourtable[3 * c + 1] = cr[3 * c + 0];
  233. colourtable[3 * c + 2] = cr[3 * c + 1];
  234. colourtable[3 * c + 3] = cr[3 * c + 2];
  235. }
  236. colourtable[1 + 3 * nc] = 0;
  237. }
  238. return colourtable;
  239. }
trixie
trixie's picture
Offline
Last seen: 1 month 1 week ago
Joined: 2011-02-03 13:58
@YesCop By the way, Trixie
@YesCop
By the way, Trixie will be unhappy with you, you are not using the NEW laws !! :)
No, I hereby pardon him :-)
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
thomas
thomas's picture
Offline
Last seen: 3 weeks 3 days ago
Joined: 2011-05-16 14:23
Then I the grim You crash
Then I the grim
You crash because all your interface pointers are NULL. You can only call datatypes functions because you misspelled IDataTypes as IDatatypes (with lower-case t), so that the actual IDataTypes is correctly initialized by libauto. You should remove all library and interface declarations from the code as well as the calls to OpenLibrary and CloseLibrary. Or alternately keep the Open and CloseLibrary calls but add correct calls to GetInterface and DropInterface and don't link with libauto.
AmigaBlitter
AmigaBlitter's picture
Offline
Last seen: 4 years 7 months ago
Joined: 2012-02-18 19:55
Adding an image to a ReAction
Adding an image to a ReAction layout is very simple (just use LAYOUT_AddImage to add a bitmap.image object).
What library should be inlcuded in order to make this to work? Thank you
Log in or register to post comments