Recent

Author Topic: IS IT POSSIBLE? Convert a jpg, gif, bmp or png file to a 32bits PNG pixel format  (Read 10581 times)

phabyam

  • Newbie
  • Posts: 4
I want to convert a jpg, gif, bmp or png file to a 32bits PNG pixel format

Code: [Select]
var
   LaImagen: TBGRABitmap;
begin
   LaImagen:=TBGRABitmap.Create('jpgimage.jpg');
   LaImagen.SaveToFile('pngimage.png');
end;

this always save the image in 24bits pixel format, how I can do save in 32bits format?

IS IT POSSIBLE?

thanks, sorry my poor englsih
« Last Edit: November 25, 2012, 07:13:11 am by phabyam »

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
My assumption is that you need to give the bitmap an alpha-channel. 24-bit PNG would hint that it contains just RGB, no transparency. (3x8bit = 24)

phabyam

  • Newbie
  • Posts: 4
someone who can help me? this is possible to do? how I can save a 32bits png image with BGRABitmap?
« Last Edit: November 27, 2012, 05:34:09 am by phabyam »

circular

  • Hero Member
  • *****
  • Posts: 4471
    • Personal webpage
Well first of all, is it possible to save 32bit png with FreePascal at all ?
Conscience is the debugger of the mind

phabyam

  • Newbie
  • Posts: 4
Well first of all, is it possible to save 32bit png with FreePascal at all ?

yes if the image have any pixel transparent, it automaticly it is saved in 32bit png
format, but how I can save the image with 32bit pixel format, if this haven't any transparent pixel?

png.pixelformat := pf32bit dont works

wjackson153

  • Sr. Member
  • ****
  • Posts: 267
Image Magic can do what your wanting, you could use it to pipe through tProcess
using commandline and redirect output to your app, problem is you have
to have image magic installed. For your app to work, so if you are passing your app
to other users you would need to force the install of image magic from distro's respo.

Hope this helps

Lazarus 1.1 r39490 CT FPC 2.7.1 i386-linux KDE
Linux Mint 14 KDE 4

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
yes if the image have any pixel transparent, it automaticly it is saved in 32bit png
format, but how I can save the image with 32bit pixel format, if this haven't any transparent pixel?

png.pixelformat := pf32bit dont works
Then you should look into the PNG code to see how you can add support to create transparency, I'd say...

Patches welcome via the bugtracker.

Or use imagemagick as wjackson153 says...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
I was in assumption there is something for PNG saving made for BGRA, since this topic was about it. I have never used it, so someone else may tell more about it.

But then you said:
Quote
is it possible to save 32bit png with FreePascal at all ?
Because there are units deeper in the fpc core, that i suppose BGRA uses too.

For example TPortableNetworkGraphic class, coming from FPimage unit i think. You should go through its procedures to find something useful. Like said few times in this thread, you need to add alpha-channel to the image. Can you simply go and write pixels an alpha value, i don't know. You would have to go through the whole image and add alpha value 65535 (in fpc each pixel channel is internally 2 bytes) to every pixel. I don't know what would happen if you try to add alpha to just 1 pixel; if rest of the image gets value of 0, it would be all transparent.

Lets hope that you don't need to go through to RawImage. Just showing you quick example from my game engine, it's code that reads RawImage from PNG and JPG, and writes it into data array that OpenGL can take:
http://code.google.com/p/nxpascal/source/browse/trunk/src/nxGraph.pas#568
Sure there's alot of code you will not need in your program, but 1 interesting thing to note is, that pixel channel sequence is browsed through as bits, not bytes. Because they make support for image formats that would have for example 7 bits per pixel or other odd ones.

circular

  • Hero Member
  • *****
  • Posts: 4471
    • Personal webpage
Oh there is a misunderstaning. Of course you can save PNG images that are 32bits RBGA.

But I was wondering if it was possible to save PNG images that are 32 bits RGB. That would mean that an extra byte is not used.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018