Hi,
1) I tryed, using AllockBitmap(), to alloc an RGB32 image (both abgr and bgra) and the image wasn't correctly saved into any formats.
I got in every case a white image.
2) I tryed to save into a gif a RGB (24 bits since 32 doesn't work...) image and SaveBitmap() asked me to convert the colorspace.
SaveBitmap() could call itself colorconvert() if it recognizes a bad colorspace for the requested output format, and btw there's now way (maybe... am I wrong?) I could know what's the maximum colour depth for every format, I mean...I know it's 8bits for gif, but I dunno if other formats have the same limitation.
If actually there isn't a way you could add such a field into the structure that returns info about fileformats.
Best regards.
SaveBitmap problems
Moderators: XnTriq, helmut, xnview
-
- Author of XnView
- Posts: 44920
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
Re: SaveBitmap problems
Could you post your code?Alessandro wrote:Hi,
1) I tryed, using AllockBitmap(), to alloc an RGB32 image (both abgr and bgra) and the image wasn't correctly saved into any formats.
I got in every case a white image.
You can use GFL_SAVE_ANYWAY2) I tryed to save into a gif a RGB (24 bits since 32 doesn't work...) image and SaveBitmap() asked me to convert the colorspace.
SaveBitmap() could call itself colorconvert() if it recognizes a bad colorspace for the requested output format, and btw there's now way (maybe... am I wrong?) I could know what's the maximum colour depth for every format, I mean...I know it's 8bits for gif, but I dunno if other formats have the same limitation.
If actually there isn't a way you could add such a field into the structure that returns info about fileformats.
Pierre.
The following code works because I modified it to save rgb24 images.
CopyFrame() was the function that I previously used and you can think of it like a memcopy() applyed on every row since Image is a rgb32 image.
What about the questions I asked about multipages formats?
The reply was actually an addiction appended by me...
CopyFrame() was the function that I previously used and you can think of it like a memcopy() applyed on every row since Image is a rgb32 image.
Code: Select all
int MySaveImage(const char *filename, char *FormatName, DWORD *Image, DWORD w, DWORD h, DWORD pitch, bool IsGray, bool flipV)
{
GFL_FILE_INFORMATION info;
GFL_SAVE_PARAMS save_params;
GFL_BITMAP *pBmp=gflAllockBitmap(IsGray ? GFL_GREY : GFL_BGR,w,h,IsGray ? 1 : 4,NULL);
if(pBmp==NULL)
return GFL_ERROR_NO_MEMORY;
// CopyFrame((DWORD *)Bmp->Data,Image,Bmp->BytesPerLine,pitch,h);
RGB32ToGB24(pBmp->Data,pBmp->Width,pBmp->Height,pBmp->BytesPerLine,Image,pitch,flipV);
gflGetDefaultSaveParams(&save_params);
save_params.Flags=GFL_SAVE_REPLACE_EXTENSION;
save_params.FormatIndex=gflGetFormatIndexByName(FormatName);
save_params.Compression=GFL_LZW;
save_params.CompressionLevel=7;
save_params.Quality=75;
save_params.ChannelType=IsGray ? GFL_CTYPE_GREYSCALE : GFL_BGR;
save_params.ChannelOrder=GFL_CORDER_INTERLEAVED; // for raw format
GFL_ERROR retVal;
if((retVal=gflSaveBitmap((char *)filename, pBmp, &save_params))!=GFL_NO_ERROR)
{
gflGetErrorString(retVal);
// MessageBox(NULL, "Error saving file!", NULL, MB_OK);
MessageBox(NULL, gflGetErrorString(retVal), NULL, MB_OK);
}
gflFreeBitmap(pBmp);
return retVal;
}
The reply was actually an addiction appended by me...
-
- Author of XnView
- Posts: 44920
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
I've tried the following code, and it works:
Code: Select all
gflGetDefaultLoadParams( &load_option );
pBmp=gflAllockBitmap(GFL_BGRA,512,512,4,NULL);
for ( y=0; y<pBmp->Height; y++ )
{
ptr = gflGetBitmapPtr( pBmp, y );
for ( x=0; x<pBmp->Width; x++ )
{
*ptr++ = 0;
*ptr++ = 0;
*ptr++ = 255; // red
*ptr++ = 0;
}
}
gflGetDefaultSaveParams(&save_params);
save_params.Flags=GFL_SAVE_REPLACE_EXTENSION;
save_params.FormatIndex=gflGetFormatIndexByName("bmp");
save_params.Compression=GFL_LZW;
save_params.CompressionLevel=7;
save_params.Quality=75;
gflSaveBitmap("d:/temp/test.bmp", pBmp, &save_params);
gflFreeBitmap(pBmp);
Pierre.
-
- Author of XnView
- Posts: 44920
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
I tryed to store into a png file an rgb32 image, but whether I set the alpha channel to 0 or to 255 the images looks transparent (format of my data is in DWORDs: AARRGGBB, format set as parameter in save function: GFL_BGRA).
I solved it converting in RGB24 but I can't figure out what's the problem.
Maybe when (and if) I'll try to store a transparent image I'll get it.
Thanks for your help.
I solved it converting in RGB24 but I can't figure out what's the problem.
Maybe when (and if) I'll try to store a transparent image I'll get it.
Thanks for your help.