图片未在图库中显示

时间:2019-08-25 04:20:33

标签: flutter dart

在我的应用程序中,我需要从URL下载图像,然后在图库中显示图像。我正在使用flutter_downloader plugin ,  这是我下载的功能

Future<String> _findLocalPath() async {
    final directory = widget.platform == TargetPlatform.android
        ? await getExternalStorageDirectory()
        : await getApplicationDocumentsDirectory();
    return directory.path;
  }

  Future _downloadImg(String url) async {
    _localPath = (await _findLocalPath()) + '/Download';
    final savedDir = Directory(_localPath);
    bool hasExisted = await savedDir.exists();
    if (!hasExisted) {
      savedDir.create();
    }
    FlutterDownloader.enqueue(
        url: url,
        savedDir: _localPath,
        showNotification: true,
        openFileFromNotification: true,
        fileName: '${DateTime.now().millisecondsSinceEpoch}.jpg');
  }

已下载但未在图库中显示的图像,那么如何使它在图库中可见?。

1 个答案:

答案 0 :(得分:0)

编辑您可以使用pacakage image_downloader下载带有过程的图像,并使用image_gallery_saver保存图像

软件包https://pub.dev/packages/image_downloader具有进度回调

$data = Get-MailboxDatabase -Server "Server" -Status | Where-Object {$_.name -like "DATABASE*"} | Sort-Object -Property @{Expression = "name"} | Select Name,Databasesize | ft | Out-String

function WORK
{   

Write-host $data 
Write-host "Pick the database with the lowest size"
Write-host


$database=Read-Host "Enter the database using a value of 1 to 4 to add the mailbox to"

Switch ($database)
    {
        1 {$Chosendatabase="DATABASE-1"}
        2 {$Chosendatabase="DATABASE-2"}
        3 {$Chosendatabase="DATABASE-3"}
        4 {$Chosendatabase="DATABASE-4"}    
}
    return $Chosendatabase


}   

$date=Get-Date -format d
$mailboxname=Read-Host “Enter the mailbox name”
$alias=Read-Host “Enter Email Alias”
$User=$alias + "@domain.com"
$ticket=Read-Host "Enter the Ticket number"
$notes="Mailbox created - $ticket - $date"


Read-Host "hit enter to Continue"


$script:ChosenDatabase = WORK



New-mailbox -shared -Name $mailboxname -alias $alias -UserPrincipalName $User -OrganizationalUnit "domain.com/Resources-OU" -Database $Chosendatabase

Set-user -identity $alias -notes "$Notes"

##This command is to make sure a copy of sent emails are stored on the shared mailbox as well as the senders mailbox    
Set-MailboxSentItemsConfiguration -Identity $alias -SendAsItemsCopiedTo SenderAndFrom -SendOnBehalfOfItemsCopiedTo SenderAndFrom


##bring back confirmation the script has done as tended
Get-mailbox -Identity $User | ft DisplayName,Database

Get-mailboxsentitemsconfiguration -Identity $alias


read-host "hit enter to close window"

您可以使用软件包https://github.com/hui-z/image_gallery_saver将临时目录中的图像或视频文件保存到图库。

用于保存文件的代码段


<?php

function voegGebruikerToe ($naam, $Ww, $WwConfirm, $sqlInsert, $nameImage, $naamDiv) {


    if(!empty($naam) and !empty($Ww) and !empty($WwConfirm)){
        if ($Ww == $WwConfirm) {

            $passHash = password_hash($Ww, PASSWORD_DEFAULT); // Creates a password hash

            $sql1 = "INSERT INTO users (username, password) VALUES ('$naam', '$passHash')";        
            if ($sqlInsert->query($sql1) === TRUE) {            //insert invevoerde data to database
                echo "ok";              
            } else {

            }


        } else {
            echo "your passwords doesn't match";
        }
    } else{
        echo "Please enter all the fields.";
    }

    $file = $_FILES[$naamDiv]['tmp_name']; 
    $sourceProperties = getimagesize($file);
    $fileNewName = $nameImage;
    $folderPath = "/var/www/";
    $ext = pathinfo($_FILES[$naamDiv]['name'], PATHINFO_EXTENSION);
    $imageType = $sourceProperties[2];
    $imageFileType = strtolower(pathinfo($_FILES[$naamDiv]['name'],PATHINFO_EXTENSION));


            // Allow certain file formats
    if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
    && $imageFileType != "gif" ) {

        echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed. <br>";

    } else {

        switch ($imageType) {


            case IMAGETYPE_PNG:
                $imageResourceId = imagecreatefrompng($file); 
                $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
                imagepng($targetLayer,$folderPath. $fileNewName. ".". $ext);*/

                break;


            case IMAGETYPE_JPEG:
                $imageResourceId = imagecreatefromjpeg($file); 
                $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
                imagejpeg($targetLayer,$folderPath. $fileNewName. ".". $ext);*/
                echo "works";
                break;


            default:
                echo "Invalid Image type.";
                exit;
                break;
        }


        //move_uploaded_file($file, $folderPath. $fileNewName. ".". $ext);
        echo "Image Resize Successfully.";
    }


    function imageResize($imageResourceId,$width,$height) {

        $targetWidth =200;
        $targetHeight =200;


        $targetLayer=imagecreatetruecolor($targetWidth,$targetHeight);
        imagecopyresampled($targetLayer,$imageResourceId,0,0,0,0,$targetWidth,$targetHeight, $width,$height);


        return $targetLayer;
    }   
}

voegGebruikerToe($admNaam, $admWw, $admWwConfirm, $conn, "administrator", "ImageUser1");

?>


the example code I found:

<?php

function x ($y) {


    function y ($z) {
        return ($z*2);
    }

    return($y+3);
}

$y = 4;
$y = x($y)*y($y);
echo $y;

?>

您还可以使用此插件的saveImage函数将图像保存到图库中

ImageDownloader.callback(onProgressUpdate: (String imageId, int progress) {
      setState(() {
        _progress = progress;
      });
    });