NImages.pas ( File view )

  • By adm.maniaco 2014-09-01
  • View(s):170
  • Download(s):11
  • Point(s): 2
			unit NImages;

interface
uses Windows, Graphics, SysUtils, NUtils, NCore;

 //-------------------------------------
 // External functions
 //-------------------------------------
 procedure NImagesGetInfo(var info: TNLibraryInfo);

type
  TNImageFormat = class(TObject)
    private
      hHandle: Pointer;
      constructor Create(handle: Pointer); overload;
    public
      class function  GetFormatCount: Integer;

      class function  CreateFormat(index: Integer): TNImageFormat;
      class function  CreateBmpFormat: TNImageFormat;

      class procedure GetImageFormats(var openFileFormats: string; var saveImageFormats: string);

      function CanWrite: Boolean;
      function CanRead: Boolean;
      function FormatName: string;
      function FormatFileFilter: string;
      function DefaultExtension: string;
  end;

  TNImage = class(TObject)
  private
     hHandle: Pointer;
  public
      constructor Create(handle: Pointer); overload;
      destructor Destroy(); override;

      property Handle: Pointer read hHandle;

      class function   CreateFromFile(fileName: string; imageFormat: TNImageFormat): TNImage;
      class function   CreateFromImage(pixelFormat: TNPixelFormat; stride: LongWord; hSrcImage: TNImage): TNImage;
      class function   CreateFromImageEx(pixelFormat: TNPixelFormat; stride: LongWord; horzResolution: Single;
                vertResolution: Single; hSrcImage: TNImage): TNImage;
      class function   CreateFromHBitmap(image: HBitmap): TNImage;

      function CreateColorWrapper(min, max: TNRgb): TNImage;

      function   HorizontalResolution: Single;
      function   VerticalResolution: Single;
      function   Stride: LongWord;
      function   Height: LongWord;
      function   Width:  LongWord;

      function   Clone: TNImage;

      function   SaveToHBitmap: HBitmap;
      procedure  SaveToFile(fileName: string; hImageFormat: TNImageFormat);

      function   Crop(left, top, width, height: LongInt): TNImage;
  end;

  TNPng = class(TObject)
    private

    public
     const DefaultCompressionLevel = 6;

     class function LoadImage(fileName: string): TNImage;  overload;
     class function LoadImage(arr: TArrayOfByte): TNImage; overload;
     class procedure SaveImage(image: TNImage; fileName: string); overload;
     class procedure SaveImage(image: TNImage; compressionLevel: Integer; fileName: string); overload;
     class function SaveImage(image: TNImage): TArrayOfByte; overload;
     class function SaveImage(image: TNImage; compressionLevel: Integer): TArrayOfByte; overload;
  end;

  TArrayOfTNImage = array of TNImage;

implementation
 //-------------------------------------
 // Constants
 //-------------------------------------

 const
  dllName = 'NImages.dll';

 //-------------------------------------
 // External functions (from dll)
 //-------------------------------------
 {
$ifdef ver210
}
 function  NImagesGetInfoInternal(var info: TNLibraryInfo): Integer stdcall; external dllName name 'NImagesGetInfoW';
 {
$else
}
 function  NImagesGetInfoInternal(var info: TNLibraryInfo): Integer stdcall; external dllName name 'NImagesGetInfoA';
 {
$endif
}
 function  NImagesGetGrayscaleColorWrapperEx(hImage: Pointer; var minColor: TNRgb; var maxColor: TNRgb; var pHDstImage: Pointer): Integer stdcall; external dllName;

 {
$ifdef ver210
}
 function  NImageCreateFromFile(const szFileName: string; hImageFormat: Pointer; var pHImage: Pointer): Integer stdcall;external dllName name 'NImageCreateFromFileW';
 function  NImageSaveToFile(hImage: Pointer; szFileName: PChar; hImageFormat: Pointer): Integer stdcall; external dllName name 'NImageSaveToFileW';
 {
$else
}
 function  NImageCreateFromFile(const szFileName: string; hImageFormat: Pointer; var pHImage: Pointer): Integer stdcall;external dllName name 'NImageCreateFromFileA';
 function  NImageSaveToFile(hImage: Pointer; szFileName: PChar; hImageFormat: Pointer): Integer stdcall; external dllName name 'NImageSaveToFileA';
 {
$endif
}
 function  NImageCreateFromImageEx(pixelFormat: TNPixelformat; stride: Integer; horzResolution: Single; vertResolution: Single; hSrcImage: Pointer; var pHImage: Pointer): Integer stdcall; external dllName;
 function  NImageCreateFromImage(pixelFormat: TNPixelFormat; stride: LongWord; hSrcImage: Pointer; var pHImage: Pointer): Integer; stdcall; external dllName;
 function  NImageGetHorzResolution(hImage: Pointer; var pValue: Single): Integer stdcall;external dllName;
 function  NImageGetVertResolution(hImage: pointer; var pValue: Single): Integer stdcall; external dllName;
 function  NImageGetWidth(hImage: Pointer; var pValue: LongWord): Integer stdcall;external dllName;
 function  NImageGetHeight(hImage: Pointer; var pValue: LongWord): Integer stdcall;external dllName;
 function  NImageClone(hImage: Pointer; var pHClonedImage: Pointer): Integer stdcall; external dllName;
 function  NImageGetStride(hImage: Pointer; var pValue: LongWord): Integer stdcall; external dllName;
 function  NImageCrop(hImage: Pointer; left: Integer; top: Integer; width: Integer; height: Integer; var hHandle: Pointer) : Integer stdcall; external dllName;

 function  BmpSaveImageToHBitmap(hImage: Pointer; var pHandle: HBitmap): Integer stdcall; external dllName;
 function  BmpLoadImageFromHBitmap(handle: HBitmap; var hImage: Pointer): Integer stdcall; external dllName;

 {
$ifdef ver210
}
 function  NImageFormatGetFileFilter(hImageFormat: Pointer; value: PAnsiChar): Integer stdcall;external dllName name 'NImageFormatGetFileFilterA';
 function  NImageFormatGetName(hImageFormat: Pointer; value: PAnsiChar): Integer stdcall; external dllName name 'NImageFormatGetNameA';
 function  NImageFormatGetDefaultFileExtension(hImageFormat: Pointer; value: PAnsiChar): Integer stdcall; external dllName name 'NImageFormatGetDefaultFileExtensionA';
 {
$else
}
 function  NImageFormatGetFileFilter(hImageFormat: Pointer; value: PChar): Integer stdcall;external dllName name 'NImageFormatGetFileFilterA';
 function  NImageFormatGetName(hImageFormat: Pointer; value: PChar): Integer stdcall; external dllName name 'NImageFormatGetNameA';
 function  NImageFormatGetDefaultFileExtension(hImageFormat: Pointer; value: PChar): Integer stdcall; external dllName name 'NImageFormatGetDefaultFileExtensionA';
 {
$endif
}
 function  NImageFormatGetFormatCount(int: Pointer): Integer stdcall;external dllName;
 function  NImageFormatCanRead(hImageFormat: Pointer; value: Pointer): Integer stdcall;external dllName;
 function  NImageFormatCanWrite(hImageFormat: Pointer; value: Pointer): Integer stdcall;external dllName;
 function  NImageFormatGetFormat(index: Integer; var hImageFormat: Pointer): Integer stdcall;external dllName;
 function  NImageFormatGetBmp(var pValue: Pointer): Integer stdcall; external dllName;

 {
$ifdef ver210
}
 function  PngLoadImageFromFile(const szFileName: string; var pHImage: Pointer): Integer stdcall; external dllName name 'PngLoadImageFromFileW';
 function  PngSaveImageToFile(hImage: Pointer; compressionLevel: Integer; szFileName: string): Integer stdcall; external dllName name 'PngSaveImageToFileW';
 {
$else
}
 function  PngLoadImageFromFile(const szFileName: string; var pHImage: Pointer): Integer stdcall; external dllName name 'PngLoadImageFromFileA';
 function  PngSaveImageToFile(hImage: Pointer; compressionLevel: Integer; szFileName: string): Integer stdcall; external dllName name 'PngSaveImageToFileA';
 {
$endif
}
 function  PngLoadImageFromMemory(buffer: Pointer; size: LongWord; var pHImage: Pointer): Integer stdcall; external dllName;
 function  PngSaveImageToMemory(hImage: Pointer; compressionLevel: Integer; var buffer: Pointer; var size: LongWord): Integer stdcall; external dllName;
 //-------------------------------------
 // Realization of functions
 //-------------------------------------

 procedure NImagesGetInfo(var info: TNLibraryInfo);
  var res: Integer;
 begin
  res := NImagesGetInfoInternal(info);
  NCheck(res);
 end;

 //-------------------------------------
 // Realization of TNImage functions
 //-------------------------------------

 constructor TNImage.Create(handle: Pointer);
 begin
  inherited Create;
  hHandle := handle;
 end;

 function TNImage.CreateColorWrapper(min, max: TNRgb): TNImage;
  var imagePtr: Pointer;
      res: Integer;
 begin
  res := NImagesGetGrayscaleColorWrapperEx(hHandle, min, max, imagePtr);
  NCheck(res);
  Result := TNImage.Create(imagePtr);
 end;

 class function TNImage.CreateFromFile(fileName: string; imageFormat: TNImageFormat): TNImage;
  var res: Integer;
      handle: Pointer;
      tmpHandle: Pointer;
 begin
  tmpHandle := nil;
  if (imageFormat <> nil) then
   tmpHandle := imageFormat.hHandle;
  
  res := NImageCreateFromFile(filename, tmpHandle, handle);
  NCheck(res);
  Result := TNImage.Create(handle);
 end;

 class function TNImage.CreateFromImageEx(pixelFormat: TNPixelFormat; stride: LongWord; horzResolution: Single;
                vertResolution: Single; hSrcImage: TNImage): TNImage;
  var pHImage: Pointer;
      ret: Integer;
 begin
     pHImage := nil;
     ret := NImageCreateFromImageEx(pixelFormat, stride, horzResolution, vertResolution, hSrcImage.Handle, pHImage);
     NCheck(ret);
     Result := TNImage.Create(pHImage);
 end;
 
 class function TNImage.CreateFromImage(pixelFormat: TNPixelFormat; stride: LongWord; hSrcImage: TNImage): TNImage;
  var res: Integer;
      output: Pointer;
 begin
  res := NImageCreateFromImage(pixelFormat, stride, hSrcImage.Handle, output);
  NCheck(res);
  Result := TNImage.Create(output);
 end;

class function TNImage.CreateFromHBitmap(image: HBitmap): TNImage;
  var res: Integer;
      handle: Pointer;
 begin
  Handle := nil;
  res := BmpLoadImageFromHBitmap(image, handle);
  NCheck(res);
  Result := TNImage.Create(handle);
 end;

 function TNImage.SaveToHBitmap: HBitmap;
  var res: Integer;
      handle: HBitmap;
 begin
  res := BmpSaveImageToHBitmap(self.hHandle, handle);
  NCheck(res);
  Result := handle;
 end;

 destructor TNImage.Destroy();
 begin
  if (hHandle <> nil) then

...
...
(Not finished, please download and read the complete file)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 2

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
Aboutform.dcu7.81 kB29-05-10 03:22
AboutForm.dfm59.86 kB02-04-10 14:37
AboutForm.pas2.79 kB02-04-10 14:37
DataBase.dcu10.72 kB29-05-10 02:56
DataBase.pas7.02 kB02-04-10 14:37
NCore.dcu12.55 kB29-05-10 02:56
NCore.pas11.17 kB02-04-10 14:37
NDeviceManager.dcu24.08 kB29-05-10 02:56
NDeviceManager.pas20.58 kB26-05-10 01:21
NExtractors.dcu26.38 kB29-05-10 02:56
NExtractors.pas22.97 kB02-04-10 14:37
NImages.dcu18.89 kB29-05-10 02:56
NImages.pas16.86 kB02-04-10 14:37
NLicensing.dcu1.73 kB29-05-10 02:56
NLicensing.pas2.27 kB02-04-10 14:37
NMatchers.dcu10.16 kB29-05-10 02:56
NMatchers.pas8.69 kB02-04-10 14:37
NTemplates.dcu13.67 kB29-05-10 02:56
NTemplates.pas10.28 kB02-04-10 14:37
NUtils.dcu17.47 kB29-05-10 02:56
NUtils.pas14.14 kB02-04-10 14:37
SQLite3.dcu10.79 kB29-05-10 02:56
sqlite3.dll493.92 kB02-04-10 14:37
SQLite3.pas13.07 kB02-04-10 14:37
SQLiteTable3.dcu49.60 kB29-05-10 02:56
SQLiteTable3.pas44.43 kB02-04-10 14:37
<SQLite>0.00 B29-05-10 03:00
DataBase.pas.~1~7.02 kB02-04-10 14:37
DataBase.pas.~2~7.02 kB26-05-10 01:49
DataBase.pas.~3~7.03 kB26-05-10 01:51
NDeviceManager.pas.~1~20.57 kB02-04-10 14:37
<__history>0.00 B29-05-10 03:00
<Bibliotecas>0.00 B29-05-10 03:00
CameraForm.dcu7.54 kB29-05-10 03:22
CameraForm.dfm172.63 kB02-04-10 14:37
CameraForm.pas2.57 kB02-04-10 14:37
DataBase.dcu10.98 kB29-05-10 03:22
DataBase.pas7.02 kB02-04-10 14:37
EnrollmentForm.dcu4.85 kB29-05-10 03:22
EnrollmentForm.dfm171.08 kB02-04-10 14:37
EnrollmentForm.pas577.00 B02-04-10 14:37
FacesSamplePas.cfg473.00 B02-04-10 14:37
FacesSamplePas.dof2.57 kB02-04-10 14:37
FacesSamplePas.dpr1.00 kB02-04-10 14:37
FacesSamplePas.dproj5.96 kB29-05-10 03:20
FacesSamplePas.dproj.20074.74 kB02-04-10 14:37
FacesSamplePas.dproj.local62.00 B29-05-10 03:21
FacesSamplePas.identcache1.19 kB29-05-10 03:22
FacesSamplePas.res78.90 kB29-05-10 03:20
fPrincipal.dcu53.36 kB29-05-10 03:13
fPrincipal.dfm176.14 kB29-05-10 03:05
fPrincipal.pas47.37 kB29-05-10 03:05
MainForm.dcu53.56 kB29-05-10 03:22
MainForm.dfm176.34 kB29-05-10 02:38
MainForm.pas47.42 kB29-05-10 02:54
NCore.dcu12.56 kB29-05-10 03:15
NDeviceManager.dcu24.09 kB29-05-10 03:15
Neurotechnology.bmp19.17 kB02-04-10 14:37
Neurotechnology.ico77.80 kB02-04-10 14:37
NExtractors.dcu26.39 kB29-05-10 03:15
NImages.dcu18.90 kB29-05-10 03:15
NLicensing.dcu1.74 kB29-05-10 03:15
NMatchers.dcu10.17 kB29-05-10 03:15
NTemplates.dcu13.68 kB29-05-10 03:15
NUtils.dcu17.48 kB29-05-10 03:15
SettingsForm.dcu15.43 kB29-05-10 03:22
SettingsForm.dfm177.53 kB02-04-10 14:37
SettingsForm.pas7.09 kB02-04-10 14:37
SQLite3.dcu10.80 kB29-05-10 03:15
SQLiteTable3.dcu49.61 kB29-05-10 03:15
FacesSamplePas.dpr.~1~1.00 kB02-04-10 14:37
FacesSamplePas.dpr.~2~1.01 kB29-05-10 03:02
FacesSamplePas.dpr.~3~411.00 B29-05-10 03:02
fPrincipal.dfm.~1~176.34 kB29-05-10 02:38
fPrincipal.dfm.~2~176.35 kB29-05-10 03:02
fPrincipal.dfm.~3~176.32 kB29-05-10 03:04
fPrincipal.pas.~1~47.42 kB29-05-10 03:01
fPrincipal.pas.~2~47.59 kB29-05-10 03:02
fPrincipal.pas.~3~47.58 kB29-05-10 03:04
fPrincipal.pas.~4~47.43 kB29-05-10 03:05
MainForm.dfm.~1~176.32 kB02-04-10 14:37
MainForm.dfm.~2~176.34 kB26-05-10 01:10
MainForm.dfm.~3~176.34 kB26-05-10 01:45
MainForm.dfm.~4~176.35 kB26-05-10 23:51
MainForm.dfm.~5~176.35 kB27-05-10 01:38
MainForm.dfm.~6~176.35 kB29-05-10 01:37
MainForm.pas.~1~45.50 kB02-04-10 14:37
MainForm.pas.~2~45.50 kB26-05-10 01:26
MainForm.pas.~3~45.64 kB26-05-10 01:45
MainForm.pas.~4~47.41 kB27-05-10 00:51
MainForm.pas.~5~47.42 kB27-05-10 01:18
MainForm.pas.~6~47.42 kB29-05-10 01:40
<__history>0.00 B29-05-10 03:16
<Biometria>0.00 B0 0%
...
Sponsored links

NImages.pas (1.58 MB)

Need 2 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D