Author | Topic: PNG Again | |
---|---|---|
Carlos a Beling | PNG Again on Sat, 28 Apr 2018 15:30:43 -0300 Good afternoon. I read the messages about PNG in the NGs and it seems to me that the problem, if exists or not, was not clarifyed there. I attached a example vey simple whre no images in ICO format (I did not tested others) can to be saved as PNG files. Can anyone to say what is going wrong? Or if it is possible? Fraternally Beling Png.zip | |
Jim Lee | Re: PNG Again on Sat, 28 Apr 2018 23:07:08 +0200 what do you want to do ? why do you want to convert ICO to PNG ? | |
Carlos a Beling | Re: PNG Again on Wed, 02 May 2018 12:17:41 -0300 Good morning Jim. Many thanks. I need to mark the footer of an image with some information and rewrite it to disk many times. As I can receive images in ICO, PNG, BMP (eventually JPG) format I think that the easyer way for working with the received image is to convert it to PNG format and work with all images in this format (I think that PNG has not lossy of image and I can write in it). In the testing program I noted two things: 1) when saving to disk the image generated in oIcon:getbitmap() and reading it back its transparency was not kept 2) it seems do not have any way to keep the received image transparency when writting it to a file. 3) oBitmap:savefile(... PNG) returns .f. and I do not know why. Then, if possible, even for my documentation purpose, I would liketo know if it is possible to save the image as PNG or I will need to change the way of doing my routines of working with the images. Fraternally Beling Em 28/04/2018 18:07, Jim Lee escreveu: > what do you want to do ? > why do you want to convert ICO to PNG ? > > > | |
Jim Lee | Re: PNG Again on Wed, 02 May 2018 18:33:16 +0200 as i know ICO PNG have transparency while Bitmap JPG does not have it. when using oIcon:getbitmap() transparency ist lost. but than next Question : where do you want to use new Image ? when used with Xbase++ you can try oBitmap:transparentClr := GraMakeRGBColor({192,192,192}) | |
Carlos a Beling | Re: PNG Again on Wed, 02 May 2018 17:05:02 -0300 Jim. Many thanks again. I want to use the image in windows with diferent background colors. Debugging the test I observed: 1) you can not to change the BG color of a built image, but you can show it in diferent BG colors if the image's transparent color is set as its BG color when it is created 2) you do not loose nor can to change the transparent color of XbpIcon() saved as XbpBitmap() in memory 3) if you write to disk the XbpBitmap() loaded from XbpIco() its transparency is lost independing on what format you had saved 4) XbpBitmap() does not save PNG images (no errors are informed) 5) GraBitBlt() ignores transparent color 6) GraStringAt(), GraCaptionStr(), Graline() , Grabox() -not filling the BG-, and others iGra... functions ignore the FG color and, it seems, their BG is naturally transparent. For testing this behaviour "on the fly' I create a XbpBitmap() and XbpPresSpace() and associate them during the debugging section(). May be you want to try it... Fraternally Beling Em 02/05/2018 13:33, Jim Lee escreveu: > as i know ICO PNG have transparency while Bitmap JPG does not have it. > when using oIcon:getbitmap() transparency ist lost. > > but than next Question : where do you want to use new Image ? > > when used with Xbase++ you can try > oBitmap:transparentClr := GraMakeRGBColor({192,192,192}) > > | |
Jonathan Leeming | Re: PNG Again on Wed, 02 May 2018 17:18:56 -0600 On 5/2/2018 2:05 PM, Carlos a Beling wrote: > Jim. > Many thanks again. > > I want to use the image in windows with diferent background colors. > > Debugging the test I observed: > 1) you can not to change the BG color of a built image, but you can show > it in diferent BG colors if the image's transparent color is set as its > BG color when it is created > 2) you do not loose nor can to change the transparent color of XbpIcon() > saved as XbpBitmap() in memory > 3) if you write to disk the XbpBitmap() loaded from XbpIco() its > transparency is lost independing on what format you had saved > 4) XbpBitmap() does not save PNG images (no errors are informed) > 5) GraBitBlt() ignores transparent color > 6) GraStringAt(), GraCaptionStr(), Graline() , Grabox() -not filling the > BG-, and others iGra... functions ignore the FG color and, it seems, > their BG is naturally transparent. > For testing this behaviour "on the fly' I create a XbpBitmap() and > XbpPresSpace() and associate them during the debugging section(). May be > you want to try it... > > Fraternally > Beling > > > > Em 02/05/2018 13:33, Jim Lee escreveu: >> as i know ICO PNG have transparency while Bitmap JPG does not have >> it. >> when using oIcon:getbitmap() transparency ist lost. >> >> but than next Question : where do you want to use new Image ? >> >> when used with Xbase++ you can try >> oBitmap:transparentClr := GraMakeRGBColor({192,192,192}) >> >> Hi Carlos, First off let me say I am by no means an "expert" on graphics images. However your problems brought to mind a notation in Clayton Jones Top Down documentation where he states... "Xbase++ apparently has trouble with some PNG files. I suspect it is due to variations in the way PNG files are constructed. It seems to accept some and reject others. Since it is intermittent and unreliable, I cannot continue to support PNG in Top-Down. The source code has not been changed so you can try it, it might work." I then checked Alaska's KB and found PDR ID: 6337 which has the description... "If transparency is involved some Bitmaps are not saved properly in the PNG file format." and the solution... "Save the file in a different file format such as JPEG or GIF" Regards... Jonathan jonathan.leeming@the-family-centre.com Edmonton, Alberta, Canada | |
Carlos a Beling | Re: PNG Again on Thu, 03 May 2018 09:59:53 -0300 Hello Jonathan. Good mornning. Many thanks. It was so hard to discover it. Unfortunatelly the JPG format does not support transparency and, saving images with transparency, its BG color is lost and become unchangeable. Fraternally Beling Em 02/05/2018 20:18, Jonathan Leeming escreveu: > On 5/2/2018 2:05 PM, Carlos a Beling wrote: >> Jim. >> Many thanks again. >> >> I want to use the image in windows with diferent background colors. >> >> Debugging the test I observed: >> 1) you can not to change the BG color of a built image, but you can >> show it in diferent BG colors if the image's transparent color is set >> as its BG color when it is created >> 2) you do not loose nor can to change the transparent color of >> XbpIcon() saved as XbpBitmap() in memory >> 3) if you write to disk the XbpBitmap() loaded from XbpIco() its >> transparency is lost independing on what format you had saved >> 4) XbpBitmap() does not save PNG images (no errors are informed) >> 5) GraBitBlt() ignores transparent color >> 6) GraStringAt(), GraCaptionStr(), Graline() , Grabox() -not filling >> the BG-, and others iGra... functions ignore the FG color and, it >> seems, their BG is naturally transparent. >> For testing this behaviour "on the fly' I create a XbpBitmap() and >> XbpPresSpace() and associate them during the debugging section(). May >> be you want to try it... >> >> Fraternally >> Beling >> >> >> >> Em 02/05/2018 13:33, Jim Lee escreveu: >>> as i know ICO PNG have transparency while Bitmap JPG does not >>> have it. >>> when using oIcon:getbitmap() transparency ist lost. >>> >>> but than next Question : where do you want to use new Image ? >>> >>> when used with Xbase++ you can try >>> oBitmap:transparentClr := GraMakeRGBColor({192,192,192}) >>> >>> > Hi Carlos, > > First off let me say I am by no means an "expert" on graphics images. > > However your problems brought to mind a notation in Clayton Jones Top > Down documentation where he states... > > "Xbase++ apparently has trouble with some PNG files. I suspect it is > due to variations in the way PNG files are constructed. It seems to > accept some and reject others. Since it is intermittent and unreliable, > I cannot continue to support PNG in Top-Down. The source code has not > been changed so you can try it, it might work." > > I then checked Alaska's KB and found PDR ID: 6337 which has the > description... > > "If transparency is involved some Bitmaps are not saved properly in > the PNG file format." > > and the solution... > > "Save the file in a different file format such as JPEG or GIF" > > Regards... Jonathan > > | |
Jose Antonio Diego Kereje | Re: PNG Again on Thu, 03 May 2018 11:03:45 +0200 Carlos: In addition to what Jonathan says, if you need png images you can use this code. It also allows you to standardize its size. IF oBmp:saveFile( cFileName.png, , XBPBMP_FORMAT_PNG ) = FALSE oBmp:saveFile( cFileName.bmp, , XBPBMP_FORMAT_WIN3X ) CreatePNG( cFileName.bmp, cFileName.png ) ... Regards. Diego PS: This option is also valid to facilitate the direct conversion of graphic formats. #define wiaFormatPNG '{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}' #define wiaFormatBMP '{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}' #define wiaFormatGIF '{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}' #define wiaFormatJPEG '{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}' #define wiaFormatTIFF '{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}' ************************************************* PROCEDURE CreatePNG( cFile, cFileOut, nMaxWidth ) ************************************************* LOCAL oImg := CreateObject( 'WIA.ImageFile' ) LOCAL oIP := CreateObject( 'WIA.ImageProcess' ) LOCAL oFilters:= oIP:Filters LOCAL oPT1, oFilter oImg:loadFile( cFile ) IF nMaxWidth # nil .AND. oImg:Width > nMaxWidth oPT1:= oIP:filterInfos( 'Scale' ) oFilters:add( oPT1:filterID ) oPT1:destroy() oFilter:= oIP:filters( 1 ) oPT1:= oFilter:properties( 'MaximumWidth' ) ; oPT1:Value := nMaxWidth ; oPT1:destroy() oPT1:= oFilter:properties( 'MaximumHeight' ) ; oPT1:Value := Round( nMaxWidth * oImg:Height / oImg:Width, 0 ) ; oPT1:destroy() oPT1:= oFilter:properties( 'PreserveAspectRatio' ) ; oPT1:Value := .F. ; oPT1:destroy() oFilter:destroy() oPT1:= oIP:apply( oImg ) ; oImg:destroy() oImg:= oPT1 oFilters:remove( 1 ) ENDIF oPT1:= oIP:filterInfos( 'Convert' ) oFilters:add( oPT1:filterID ) oPT1:destroy() oFilters:destroy() oFilter:= oIP:filters( 1 ) oPT1:= oFilter:properties( 'FormatID' ) ; oPT1:Value := wiaFormatPNG ; oPT1:destroy() oFilter:destroy() FErase( cFileOut ) oPT1:= oIP:Apply( oImg ) ; oPT1:SaveFile( cFileOut ) ; oPT1:destroy() oImg:destroy() oIP:destroy() RETURN | |
Carlos a Beling | Re: PNG Again on Thu, 03 May 2018 10:09:17 -0300 Hello Diego. Good morning. Many thanks. So easy and so hard to discover as you did. Would it to be possible to save XbpBitmap() objects created "on fly" in files with PNG format? Fraternally Beling Em 03/05/2018 06:03, Jose Antonio Diego Kereje escreveu: > Carlos: > > In addition to what Jonathan says, if you need png images you can use > this code. > It also allows you to standardize its size. > > IF oBmp:saveFile( cFileName.png, , XBPBMP_FORMAT_PNG ) = FALSE > > oBmp:saveFile( cFileName.bmp, , XBPBMP_FORMAT_WIN3X ) > > CreatePNG( cFileName.bmp, cFileName.png ) > ... > > > Regards. Diego > > PS: This option is also valid to facilitate the direct conversion of > graphic formats. > > > #define wiaFormatPNG '{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}' > #define wiaFormatBMP '{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}' > #define wiaFormatGIF '{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}' > #define wiaFormatJPEG '{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}' > #define wiaFormatTIFF '{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}' > > ************************************************* > PROCEDURE CreatePNG( cFile, cFileOut, nMaxWidth ) > ************************************************* > LOCAL oImg := CreateObject( 'WIA.ImageFile' ) > LOCAL oIP := CreateObject( 'WIA.ImageProcess' ) > LOCAL oFilters:= oIP:Filters > LOCAL oPT1, oFilter > > oImg:loadFile( cFile ) > > IF nMaxWidth # nil .AND. oImg:Width > nMaxWidth > oPT1:= oIP:filterInfos( 'Scale' ) > oFilters:add( oPT1:filterID ) > oPT1:destroy() > > oFilter:= oIP:filters( 1 ) > oPT1:= oFilter:properties( 'MaximumWidth' ) ; oPT1:Value := > nMaxWidth ; oPT1:destroy() > oPT1:= oFilter:properties( 'MaximumHeight' ) ; oPT1:Value := > Round( nMaxWidth * oImg:Height / oImg:Width, 0 ) ; oPT1:destroy() > oPT1:= oFilter:properties( 'PreserveAspectRatio' ) ; oPT1:Value := > .F. ; oPT1:destroy() > oFilter:destroy() > > oPT1:= oIP:apply( oImg ) ; oImg:destroy() > oImg:= oPT1 > > oFilters:remove( 1 ) > ENDIF > > oPT1:= oIP:filterInfos( 'Convert' ) > oFilters:add( oPT1:filterID ) > oPT1:destroy() > oFilters:destroy() > > oFilter:= oIP:filters( 1 ) > oPT1:= oFilter:properties( 'FormatID' ) ; oPT1:Value := wiaFormatPNG > ; oPT1:destroy() > oFilter:destroy() > > FErase( cFileOut ) > > oPT1:= oIP:Apply( oImg ) ; oPT1:SaveFile( cFileOut ) ; oPT1:destroy() > > oImg:destroy() > oIP:destroy() > RETURN > | |
Jose Antonio Diego Kereje | Re: PNG Again on Thu, 03 May 2018 23:50:56 +0200 Carlos: I modified your sample a bit to generate pngs and "simulate" the transparency. If I have some time at the weekend, I'll take a new look. Regards. Diego TesteIco.zip | |
Carlos a Beling | Re: PNG Again on Fri, 04 May 2018 11:03:05 -0300 Hello Diego. Many thanks. Very, very, very nice. I will be expecting you to have a new look. Would it to be better than this one? Fraternally Beling Em 03/05/2018 18:50, Jose Antonio Diego Kereje escreveu: > Carlos: > > I modified your sample a bit to generate pngs and "simulate" the > transparency. If I have some time at the weekend, I'll take a new look. > > Regards. Diego | |
Jim Lee | Re: PNG Again on Sat, 05 May 2018 03:32:55 +0200 hi, again i have to ask what you want to to with Images ? do you only want to convert Image or use it in you Xbase++ App ? 24bpp or 32bpp Color ? if you want to use those Image for Controls (XbParts) than you get Different Result when use Mainifest (yes) or not (no) i use Windows Imagelist to hold, all type of Image, for my native Controls. https://msdn.microsoft.com/en-us/library/windows/desktop/bb761389(v=vs.85).aspx Xbase++ does have a CLASS ImageList (for XbpToolbar) but is using MsComCtl.OCX ... what is transparency : as i know real transparancy mean Alpha Channel with 32bpp Color using ILD_TRANSPARENT (0x01) to draw a Image. other Way is to use to ILC_MASK with 2 Image where 1 is Monochrom (B/W). i guess that is what Diego does have a look about 32bit Image here https://www.codeproject.com/Articles/9142/Adding-and-using-bit-alphablended-images-and-ic#_articleTop p.s. when using Imagelist you can get a single Image and write it as file in any Image Format | |
Carlos a Beling | Re: PNG Again on Tue, 08 May 2018 12:47:45 -0300 Hello Jim. Good afternoon. Sorry for the late response. I do not want convert images. If needed I only want to save them to a file or to use its background color as transparency for to show them in diferents windows background colors. I was very confused about transparency in Xbase++ and I found out after many tries: 1) XbpBitmap():loadFile() only loads transparency information fom files GIF and PNG 2) in XbpBitmap():setBuffer() you need to inform the image format and implicitly, the XbpBitmap():transparentClr 3) only XbpBtimap():draw() or XbpIcon():draw() can to process transparency colors in Xbase++ (GraBitBlt() can not) 4) the XbpBitmap():transparentClr may to be anyone 5) if I make XbpBitmap():transparentClr := XbpBitmap():getDefaultBgColor() the image's background is "shown" transparent for any image type loaded. 6) Xbase++ does not work fine with PNG images The example posted by Mr Diego at this time is enought for me. Again I thank very much to all you that helped me. Fraternally Beling Em 04/05/2018 22:32, Jim Lee escreveu: > hi, > > again i have to ask what you want to to with Images ? > do you only want to convert Image or use it in you Xbase++ App ? 24bpp or > 32bpp Color ? > > if you want to use those Image for Controls (XbParts) than you get Different > Result when use Mainifest (yes) or not (no) > > i use Windows Imagelist to hold, all type of Image, for my native Controls. > https://msdn.microsoft.com/en-us/library/windows/desktop/bb761389(v=vs.85).aspx > Xbase++ does have a CLASS ImageList (for XbpToolbar) but is using > MsComCtl.OCX ... > > what is transparency : > as i know real transparancy mean Alpha Channel with 32bpp Color using > ILD_TRANSPARENT (0x01) to draw a Image. > other Way is to use to ILC_MASK with 2 Image where 1 is Monochrom (B/W). i > guess that is what Diego does > > have a look about 32bit Image here > https://www.codeproject.com/Articles/9142/Adding-and-using-bit-alphablended-images-and-ic#_articleTop > > p.s. when using Imagelist you can get a single Image and write it as file in > any Image Format > > | |
Carlos a Beling | Re: PNG Again on Wed, 09 May 2018 09:45:53 -0300 Hello. Good morning. Me again. I am finishing my work about PNG and I'd like to get these answers? a) can I use the function DisablePNG() for all XbpBitmap()? b) is only PNG images that needes to have its transparency corrected? c) can I save as file any XbpBitmap() created "on fly" keeping its properties using the function CreatePNG()? Fraternally Beling | |
Itai Ben-Artzi | Re: PNG Again on Sun, 22 Jul 2018 23:10:43 -0700 >Carlos, >You may achieve the effect you want by "cheating" as follow: >*************************** >cFileGIF := dtos(date())+'.gif' >cFilePNG := dtos(date())+'.png' > >oBitmap := XbpBitmap():New():create() >obitmap:loadfile(cFileName) >xTemp := oBitmap:GetDefaultBGColor() >oBitmap:TransparentClr := xTemp Set the background color transparent. >oBitmap:transparency := 255 Set the transparency level (0-255) >oBitmap:saveFile( cFileGIF, XBPBMP_FORMAT_GIF ) Create a GIF transparent (we should not save as PNG because Alaska poorly handles PNG format). > >// if you need it as PNG, use WIA to convert >CreatePNG( cFileGIF, cFilePNG ) > >// Load the PNG >oBitmap :Destroy() >oBitmap := XbpBitmap():New():create() >obitmap:loadfile(cFilePNG) >***************************** > >I call it cheating because the image is not truly transparent (hasAlphaChannel = .F., Bits <> 32, transparency = 0), but the draw() simulate a transparent image. > > -Itai |