Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

1 MONTH VIP - 5$; 3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

SavePhoto To Album Delphi XE6

Discussion in 'Delphi Android And IOS' started by N0body, Apr 25, 2014.

  1. N0body
    Online

    N0bodyN0body is a Verified Member DelphiFan Administrator Staff Member DF Staff

    For this case you can use this procedure :


    Code:
    procedure TDPFImagePickerControllerDelegate.imagePickerController( picker: UIImagePickerController; didFinishPickingMediaWithInfo: NSDictionary );
    const
      EType: array [TDPFEditingType] of string = ( 'UIImagePickerControllerMediaType', 'UIImagePickerControllerOriginalImage', 'UIImagePickerControllerEditedImage' );
    var
      img                : UIImage;
      Bitmap             : TBitmap;
      Angle              : SIngle;
      mtype              : NSString;
      videoURL           : NSURL;
      videoData          : NSData;
      FileSavedPath      : string;
      isMovie            : Boolean;
      P                  : Pointer;
      newWidth, newHeight: Single;
      scaleFactor        : Single;
    begin
      HidePicker;
     
      mtype   := TNSString.Wrap( didFinishPickingMediaWithInfo.objectForKey( ( CocoaNSStringConst( libKit, 'UIImagePickerControllerMediaType' ) as ILocalObject ).GetObjectID ) );
      isMovie := ( mtype.isEqualToString( kUTTypeVideo ) or mtype.isEqualToString( kUTTypeMovie ) );
     
      // movie != video
      if Assigned( FDPFUIImagePickerController.FOndidFinishPickingMovie ) and isMovie then
      begin
        videoURL  := TNSURL.Wrap( didFinishPickingMediaWithInfo.objectForKey( ( CocoaNSStringConst( libKit, 'UIImagePickerControllerMediaURL' ) as ILocalObject ).GetObjectID ) );
        videoData := TNSData.Wrap( TNSData.OCClass.dataWithContentsOfURL( videoUrl ) );
     
        FileSavedPath := UTF8ToString( videoURL.absoluteString.UTF8String );
     
        if FDPFUIImagePickerController.FSaveToAlbum then
          if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum( PNSStr( FileSavedPath ) ) then
            UISaveVideoAtPathToSavedPhotosAlbum( PNSStr( FileSavedPath ), nil, nil, nil );
     
        FDPFUIImagePickerController.FOndidFinishPickingMovie( FDPFUIImagePickerController, videoData.length, FileSavedPath );
        if FileSavedPath <> UTF8ToString( videoURL.absoluteString.UTF8String ) then
          videoData.writeToFile( NSStr( FileSavedPath ), true );
      end
      else if Assigned( FDPFUIImagePickerController.FOndidFinishPickingImage ) and not isMovie then
      begin
        img    := TUIImage.Wrap( didFinishPickingMediaWithInfo.objectForKey( ( CocoaNSStringConst( libKit, EType[FDPFUIImagePickerController.FEditingType] ) as ILocalObject ).GetObjectID ) );
        Angle  := GetImageOrientation( img );
        Bitmap := UIImageToBitmap( img, Angle );
        try
          FDPFUIImagePickerController.FOndidFinishPickingImage( FDPFUIImagePickerController, BitMap );
        finally
          Bitmap.DisposeOf;
        end;
      end
      else if Assigned( FDPFUIImagePickerController.FOndidFinishPickingUIImage ) and not isMovie then
      begin
        img := TUIImage.Wrap( didFinishPickingMediaWithInfo.objectForKey( ( CocoaNSStringConst( libKit, EType[FDPFUIImagePickerController.FEditingType] ) as ILocalObject ).GetObjectID ) );
        FDPFUIImagePickerController.FOndidFinishPickingUIImage( FDPFUIImagePickerController, img );
      end
      else if Assigned( FDPFUIImagePickerController.FOndidFinishPickingSavedImage ) and not isMovie then
      begin
        P := didFinishPickingMediaWithInfo.objectForKey( ( CocoaNSStringConst( libKit, EType[FDPFUIImagePickerController.FEditingType] ) as ILocalObject ).GetObjectID );
     
        if Assigned( FDPFUIImagePickerController.FOnResizeImage ) then
        begin
          img       := TUIImage.Wrap( P );
          newWidth  := img.size.width;
          newHeight := img.size.height;
          FDPFUIImagePickerController.FOnResizeImage( FDPFUIImagePickerController, newWidth, newHeight );
     
          if img.size.width > img.size.height then
          begin
            scaleFactor := img.size.width / img.size.height;
            newHeight   := newHeight / scaleFactor;
          end
          else
          begin
            scaleFactor := img.size.height / img.size.width;
            newWidth    := newWidth / scaleFactor;
          end;
     
          UIGraphicsBeginImageContext( CGSizeMake( newWidth, newHeight ) { , false, 0.0 } );
          img.drawInRect( CGRectMake( 0, 0, newWidth, newHeight ) );
          P := UIGraphicsGetImageFromCurrentImageContext( );
          UIGraphicsEndImageContext( );
        end;
     
        if FDPFUIImagePickerController.FSaveImageType = itPNG then
        begin
          P             := UIImagePNGRepresentation( P );
          FileSavedPath := '.png';
        end
        else
        begin
          P             := UIImageJPEGRepresentation( P, 1.0 );
          FileSavedPath := '.jpg';
        end;
     
        FileSavedPath := GetTempDirectory + GetUUID + FileSavedPath;
        if Assigned( P ) then
          if not TNSData.Wrap( P ).writeToFile( NSStr( FileSavedPath ), true ) then
            FileSavedPath := '';
        FDPFUIImagePickerController.FOndidFinishPickingSavedImage( FDPFUIImagePickerController, FileSavedPath );
      end;
     
      if not isMovie and ( FDPFUIImagePickerController.FDPFImagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera ) and FDPFUIImagePickerController.FSaveToAlbum then
      begin
        p := didFinishPickingMediaWithInfo.objectForKey( ( CocoaNSStringConst( libKit, EType[FDPFUIImagePickerController.FEditingType] ) as ILocalObject ).GetObjectID );
        if FDPFUIImagePickerController.FSaveToAlbum then
          UIImageWriteToSavedPhotosAlbum( P, nil, nil, nil );
      end;
     
    end;
    
     
    arty likes this.

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block