>I'm having problems saving a bitmap to an iff file on disk using the
>datatypes.library. Are there any examples of how to do this available?
>I need to save the bitmap from a rastport connected to a window, as
>well as seperate bitmaps in ram.
Here's a butchered code fragment that illustrates the solution.
BOOL savePicture (struct Screen *scr, struct BitMap *bm, LONG width, LONG height, LONG depth, LONG mode) { struct ColorRegister *cmap, *acmap; struct BitMapHeader *bmhd; ULONG modeid = LORES_KEY; BOOL result = FALSE; LONG *cregs; Object *o; WORD i; /* Should be DTA_GroupID, GID_PICTURE */ if (o = newdtobject ((APTR) "IconEdit", DTA_SourceType, DTST_RAM, DTA_GroupID, GID_PICTURE, PDTA_NumColors, ncolors, PDTA_BitMap, bm, PDTA_ModeID, modeid, TAG_DONE)) { /* Get a pointer to the data that we must prepare */ if ((getdtattrs (o, PDTA_BitMapHeader, &bmhd, PDTA_ColorRegisters, &acmap, PDTA_CRegs, &cregs, TAG_DONE)) == 3) { /* Prepare the bitmap header */ bmhd->bmh_Width = width; bmhd->bmh_Height = height; bmhd->bmh_Depth = depth; bmhd->bmh_PageWidth = 320; bmhd->bmh_PageHeight = 200; /* Remember the points */ cmap = acmap; /* Make them the same as our screen */ GetRGB32 (scr->ViewPort.ColorMap, 0, ncolors, cregs); /* Set the colors */ for (i = 0; i < ncolors; i++) { /* Set the master color table */ cmap->red = (UBYTE) (cregs[i * 3 + 0] >> 24); cmap->green = (UBYTE) (cregs[i * 3 + 1] >> 24); cmap->blue = (UBYTE) (cregs[i * 3 + 2] >> 24); cmap++; } if (mode == 0) { struct dtGeneral dtg; /* Copy it to the clipboard */ dtg.MethodID = DTM_COPY; DoDTMethodA (o, NULL, NULL, &dtg); /* Show that we were successful */ result = TRUE; } else { struct DiskObject *dob; struct dtWrite dtw; BPTR fh; if (fh = Open (filename, MODE_NEWFILE)) { dtw.MethodID = DTM_WRITE; dtw.dtw_GInfo = NULL; dtw.dtw_FileHandle = fh; dtw.dtw_Mode = DTWM_IFF; dtw.dtw_AttrList = NULL; if (DoMethodA (o, &dtw)) { /* Get the an Icon for the file */ if (dob = GetDiskObject (filename)) { FreeDiskObject (dob); } else if (dob = GetDiskObject ("ENV:Sys/def_ilbm")) { PutDiskObject (filename, dob); FreeDiskObject (dob); } else { PutDiskObject (filename, &BrushIcon); } /* Show that we were successful */ result = TRUE; } Close (fh); } } } DisposeDTObject (o); } return (result); } David N. Junod net: davidj@cbmvax.cbm.commodore.com bix: djunod
Design by comdes