1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

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 AdminDF, Apr 25, 2014.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan 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;
    
     
    Mahdi and arty like this.

Share This Page