gpt4 book ai didi

ios - 如何为可以通过照片库官方 iOS (Delphi/Firemonkey) 访问的图像创建自己的 App 文件夹

转载 作者:行者123 更新时间:2023-12-04 03:38:25 28 4
gpt4 key购买 nike

我正在开发一个可以创建自己图像的应用程序。我想将这些图像保存到自己的本地文件夹(如 WhatsApp 和其他应用程序),但我需要可以从 Photos 官方 iOS 应用程序(如 WhatsApp、DJI...)访问该本地文件夹。

请问,我如何创建自己的文件夹来保存和从我的应用程序获取图像,并且可以从 iOS 的图库访问该文件夹?

这可能不是很困难,因为很多应用程序都在使用这种方法,但我已经找了 5 天,我找不到任何东西。

提前致谢!

最佳答案

您可以在类函数上将这两种解决方案与 if def Android 或 iOS 混合使用。

在 iOS 上,您需要添加权限条目 NSPhotoLibraryAddUsageDescription

然后像这样将照片保存到相册:

if TPlatformServices.Current.SupportsPlatformService(IFMXPhotoLibrary, Service) then
Service.AddImageToSavedPhotosAlbum(imageMain.Bitmap);

我知道你只对 iOS 感兴趣,但我也使用这个 Android 解决方案,我用这段代码获得了最后的 DCIM 路径(内部/外部):

function GetDCIMPath: string;
const
CST_DCIM_PATH = '/DCIM/';
var
ContentResolver: JContentResolver;
Cursor: JCursor;
Path: string;
i: integer;
begin
Result := '';

ContentResolver := TAndroidHelper.ContentResolver;
Cursor := ContentResolver.query(TJImages_Media.JavaClass.EXTERNAL_CONTENT_URI, nil, nil, nil, StringToJString('datetaken DESC'));

try
if Assigned(Cursor) then
begin
Cursor.moveToFirst;

// can be replace with a repeat until
while not Result.ToUpper.Contains(CST_DCIM_PATH) do
begin
i := Cursor.getColumnIndex(StringToJString('_data'));
if i <> -1 then
Result := JStringToString(Cursor.getString(i));

if not Cursor.moveToNext then
Break;
end;
// ex : /storage/emulated/0/DCIM/FolderName/LastPicture.png
if Result.ToUpper.Contains(CST_DCIM_PATH) then
Result := Copy(Result, 0, Result.IndexOf(CST_DCIM_PATH) + CST_DCIM_PATH.Length);
end;
finally
Cursor.close;
end;
end;

这是一个快速的代码,您可以使用良好的 const 更改字符串参数。并保存您的图像:

procedure TForm1.Button1Click(Sender: TObject);
var
Path : string;
Folder: string;
begin
Path := GetDCIMPath;
Folder := TPath.Combine(Path, 'MyAppFolder');

if not TDirectory.Exists(Folder) then
TDirectory.CreateDirectory(Folder);

// just a TImage for test
Image1.Bitmap.SaveToFile(TPath.Combine(Folder, 'picture.jpg'));
end;

也不要忘记在存储上读/写的权限。

关于ios - 如何为可以通过照片库官方 iOS (Delphi/Firemonkey) 访问的图像创建自己的 App 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66505104/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com