Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

TImage komponenta - snimanje sadrzaja kao JPG ili PNG fajle

[es] :: C/C++ programiranje :: TImage komponenta - snimanje sadrzaja kao JPG ili PNG fajle

[ Pregleda: 2058 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

adnanK
Sarajevo

Član broj: 146055
Poruke: 31
*.bbone.utic.net.ba.



Profil

icon TImage komponenta - snimanje sadrzaja kao JPG ili PNG fajle15.07.2008. u 11:00 - pre 191 meseci
Koristim TImage komponentu u BCB da prikazem neke strukture koje uglavnom crtam najjednostavnijim primitivama (LineTo, FillPolygon, ...). Kako mogu snimiti to sto nacrtam u JPG ili PNG datoteku?
 
Odgovor na temu

X Files
Vladimir Stefanovic
Pozarevac

SuperModerator
Član broj: 15100
Poruke: 4901
*.tekostolac.co.yu.

Jabber: xfiles@elitesecurity.org


+638 Profil

icon Re: TImage komponenta - snimanje sadrzaja kao JPG ili PNG fajle15.07.2008. u 11:31 - pre 191 meseci
Da bi koristio JPG slike, prethodno treba da ukljucis biblioteku:
Code:

#include <jpeg.hpp>

Ako si u TImage objekat vec ucitao JPG sliku:
Code:

Image1->Picture->LoadFromFile( "C:\\slika.jpg" );

... onda je na isti nacin i snimas:
Code:

Image1->Picture->SaveToFile( "C:\\slika.jpg" );

Ako je slika u TImage objektu nastala nekim crtanjem, mozes je konvertovati u JPG na sledeci nacin:
// NETESTIRANO
Code:

#include <jpeg.hpp> 
// ...
TJPEGImage *jpg = new TJPEGImage; 
try 

   jpg->Assign( Image1->Picture->Graphic ); 
   jpg->SaveToFile( "C:\\slika.jpg" );

__finally

   delete jpg; 
}


PNG format nije podrzan, potrebne su 3rd party klase (komponente) ...
 
Odgovor na temu

adnanK
Sarajevo

Član broj: 146055
Poruke: 31
*.bbone.utic.net.ba.



Profil

icon Re: TImage komponenta - snimanje sadrzaja kao JPG ili PNG fajle15.07.2008. u 12:35 - pre 191 meseci
Sad je testirano i radi :) Car si. Hvala ti za sve.
 
Odgovor na temu

kiklop74
Darko Miletić
Buenos Aires

Član broj: 78422
Poruke: 569
*.fibertel.com.ar.

Sajt: ar.linkedin.com/pub/darko..


+13 Profil

icon Re: TImage komponenta - snimanje sadrzaja kao JPG ili PNG fajle19.07.2008. u 20:08 - pre 191 meseci
Povodom PNG formata ima nekoliko opcija.
1. libpng - http://www.libpng.org/pub/png/libpng.html

Ovo je referentna implementacija biblioteke za manipulaciju slika u png formatu. Potpuno je portabilna i nudi sve sto je neophodno za rad sa png datotekama. Potrebno je malo vremena dok se pohvataju konci ali se sve to na kraju isplati.

2. GDI+ - microsoftova graficka biblioteka koja podrzava sve standardne image formate pa i PNG. Karakterisu je odlicne klase isporucene uz platform sdk i jednostavnost upotrebe.

Na primer:

Code:


#include <windows.h>
#include <tchar.h>
#include <ole2.h>
#include <string>
#include <GdiPlus.h>
#pragma comment(lib,"gdiplus.lib")

#ifdef __BORLANDC__
#include <cstddef> //to add size_t
#include <algorithm>
using std::min;
using std::max;
#endif //__BORLANDC__


typedef std::basic_string<TCHAR> tstring;

struct gdi_init{
  gdi_init(void) : m_gdip(0), m_status(false) { 
    Gdiplus::GdiplusStartupInput m_input;
    m_status = ( Gdiplus::GdiplusStartup(&m_gdip, &m_input, NULL) == Gdiplus::Ok );
  }
  ~gdi_init(void){ 
    if (m_status) {
      Gdiplus::GdiplusShutdown(m_gdip);
      m_status = false;
      m_gdip   = 0;
    }
  }
private:
  gdi_init(const gdi_init& rhs);
  ULONG_PTR m_gdip;
  volatile bool m_status;
};

int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
   UINT  num = 0;          // number of image encoders
   UINT  size = 0;         // size of the image encoder array in bytes

   Gdiplus::ImageCodecInfo* pImageCodecInfo = NULL;

   Gdiplus::GetImageEncodersSize(&num, &size);
   if(size == 0)
      return -1;  // Failure

   pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(size));
   if(pImageCodecInfo == NULL)
      return -1;  // Failure

   Gdiplus::GetImageEncoders(num, size, pImageCodecInfo);

   for(UINT j = 0; j < num; ++j)
   {
      if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
      {
         *pClsid = pImageCodecInfo[j].Clsid;
         free(pImageCodecInfo);
         return j;  // Success
      }    
   }

   free(pImageCodecInfo);
   return -1;  // Failure
}


bool ConvertImageToPNG(const tstring& imgfile, const tstring& pngfile) {
  gdi_init in;
  CLSID   encoderClsid = {0};
  
  Gdiplus::Image ig(imageile.c_str());
  GetEncoderClsid(L"image/png", &encoderClsid);
  Gdiplus::Bitmap bmp( (width > 0) ? width : ig.GetWidth(), 
                       (height > 0) ? height : ig.GetHeight(), 
                       PixelFormat32bppRGB);
  Gdiplus::Graphics gr(&bmp);
  Gdiplus::Color backColor(0,0,0);
  gr.Clear(backColor);
  gr.DrawImage(&ig,0,0);
  
  Gdiplus::EncoderParameters* encoderParameters = (Gdiplus::EncoderParameters*)
   malloc(sizeof(Gdiplus::EncoderParameters) + sizeof(Gdiplus::EncoderParameter));
  
  encoderParameters->Count = 1;
  encoderParameters->Parameter[0].Guid = Gdiplus::EncoderQuality;
  encoderParameters->Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong;
  encoderParameters->Parameter[0].NumberOfValues = 1;
  int quality = 95;
  encoderParameters->Parameter[0].Value = &quality;
   
  Gdiplus::Status stat = bmp.Save(pngfile.c_str(), &encoderClsid, encoderParameters);
  free(encoderParameters);
  return (stat == Gdiplus::Ok);
}

int main(void) {

  ConvertImageToPNG(_T("nekifajl.bmp", _T("nekifajl.png") ));

  return 0;
}


Tko leti vrijedi
 
Odgovor na temu

deerbeer
Beograd

Član broj: 174418
Poruke: 1189
*.adsl-4.sezampro.yu.



+395 Profil

icon Re: TImage komponenta - snimanje sadrzaja kao JPG ili PNG fajle20.07.2008. u 10:20 - pre 191 meseci
Jel neko radio sa EXIF podacima u JPEG-u sa GDI+?
Ja sam koristio graficku biblioteku http://www.smalleranimals.com/isource.htm
al je tamo EXIF traljavo odradjen mada je i sam EXIF ne-standardan i zavisi od prozivodjaca digitalnih kamera ...


Viva lollapalooza
 
Odgovor na temu

kiklop74
Darko Miletić
Buenos Aires

Član broj: 78422
Poruke: 569
*.fibertel.com.ar.

Sajt: ar.linkedin.com/pub/darko..


+13 Profil

icon Re: TImage komponenta - snimanje sadrzaja kao JPG ili PNG fajle20.07.2008. u 12:58 - pre 191 meseci
Koliko sam uspeo da vidim gdi¡ klasa Image ima podršku za exif.

Pogledaj sve metode vezane za Properties kao ovo:

http://msdn.microsoft.com/en-us/library/ms535372(VS.85).aspx

Ovaj sajt ima zanimljive komentare vezane za exif

http://www.pixvillage.com/blog...og/archive/2005/03/17/159.aspx
Tko leti vrijedi
 
Odgovor na temu

[es] :: C/C++ programiranje :: TImage komponenta - snimanje sadrzaja kao JPG ili PNG fajle

[ Pregleda: 2058 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.