Page 1 of 1

Save BitMap

PostPosted: Tue Mar 06, 2018 5:42 am
by mritter0
I am trying to save a BitMapClass BitMap, but am not having much luck.

I am using DataTypes to load and scale the image and end up with this, which displays correctly:

Code: Select all
   if (!(Img=IIntuition->NewObject(BitMapClass,NULL,
      BITMAP_BitMap,                     ScaleBM,
      BITMAP_Width,                     ScaleWidth,
      BITMAP_Height,                     ScaleHeight,
      BITMAP_HasAlpha,                  TRUE,
      BITMAP_Screen,                     DefaultPubScreen,
      BITMAP_Precision,                  PRECISION_EXACT,
      BITMAP_Masking,                     TRUE,

Now I want to save it. I am close, but all I get is a grey box. And the depth always says 4, not 32.

Code: Select all


SaveBitMap(Object *Obj,uint32 Width,uint32 Height,STRPTR Dest)
   Object *dto=NULL;
   struct BitMapHeader *bmhd;
   struct BitMap               *BM=NULL;

   if (!(dto = IDataTypes->NewDTObject(NULL,
//      DTA_GroupID,GID_PICTURE,

   if (IDataTypes->GetDTAttrs(dto,
      bmhd->bmh_Left = 0;
      bmhd->bmh_Top = 0;
      bmhd->bmh_Width = Width;
      bmhd->bmh_Height = Height;
      bmhd->bmh_Depth = 32;


      BITMAP_BitMap,                     &BM,

   IIntuition->IDoMethod(dto, PDTM_WRITEPIXELARRAY, BM, PBPAFMT_ARGB, (Width*4)*Height, 0, 0, Width, Height);

   if (IDataTypes->SaveDTObjectA(dto,NULL,NULL,Dest,
      DTWM_RAW,                        FALSE,

   if (dto)


I don't think I am handling the BITMAP_BitMap,&BM, correctly in the Intuition->IDoMethod() call.

It saves it as a PNG.

What am I doing wrong?

Re: Save BitMap

PostPosted: Tue Mar 06, 2018 5:40 pm
by TSK
You'll have to convert the bitmap to a RGB array first and use that in IDoMethod call. Also the fifth parameter in the IDoMethod call is row size and not size of the whole area.

Code: Select all
 APTR tempbuffer=NULL;
 int32 err=0;

      if (tempbuffer!=NULL)



Also I'm using DTWM_IFF,FALSE in SaveDTObject() call. It saves as IFF-ILBM. I don't know if saving works with any other picture format.

Re: Save BitMap

PostPosted: Tue Mar 06, 2018 8:10 pm
by mritter0
That's what I was missing. Thank you.