如何重命名目标c中捕获的图像?

发布于 2024-12-16 20:14:11 字数 184 浏览 0 评论 0原文

在我的应用程序中,我需要捕获图像并将其保存在本地库和使用 FTP 的服务器上。现在我需要在将图像保存在服务器上时遵循图像名称的格式。我能够捕获图像并将其保存在本地库中。但我找不到任何方法来更改图像的名称。假设我需要将其重命名为 Productname-UserId.png 有什么办法吗?请帮忙。

谢谢。

In my application I need to capture image as well as save it on local library and on server using FTP. Now I need to follow a format for image name while saving it on the server. I am able to capture and save the image on local library. But I am unable to find any method to change the name of the Image. Suppose I need to rename it as Productname-UserId.png Is there any way? Kindly help.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜嗑 2024-12-23 20:14:12

这里真正的问题是您希望文件名具体在哪里?在设备上或服务器上。如果设备使用 Charles 答案,否则您应该查看 http 协议(文件上传部分)。实际上,文件在本地设备上的名称并不重要,因为当您通过 http 将其发送到服务器时,您可以提供任何名称。这里棘手的部分是,您上传到的服务器在保存该文件时应考虑该参数。因此,如果您要上传到您手头没有的服务器,并且它执行一些自命名约定 - 您可能会陷入困境。如果是您的 - 看看您如何在服务器端保存文件,以及您是否考虑了“文件名”参数...

PS 并且不要忘记将该参数传递给上传要求 :)

The real question here is where do you want the file name to be specific? On the device or on the server. In case of device use Charles answer, otherwise you should look at http protocol(file upload part). Actually it doesn't matter what name the file have on you local device, as when you send it to the server over http, you can provide any name. The tricky part here is that the server you are uploading to should take that parameter into account when saving that file. So if you are uploading to a server that you don't have hand on and it does some self naming convention - you probably stuck. If it's yours - look at how you're saving files on the server side and if you are taking in account that "filename" parameter...

P.S. And don't forget to pass that argument to the upload request :)

银河中√捞星星 2024-12-23 20:14:11

UIImagePNGRepresentation(UIImage*) 可能就是您正在寻找的。您可以将 UIImage 作为 PNG 文件保存在应用程序文档文件夹中,然后将其上传到服务器。执行此操作的代码非常简单,因此如果您可以发布您尝试使用的代码,这将有助于理解并为您推荐解决方案。

这是我的代码中的一个简短剪辑,它正是执行此操作:

UIImage * image; // Some image you want to send

NSString * docDirWithSlash = [[self applicationDocumentsDirectory] stringByAppendingString:@"/"];
NSString * pngFile = [docDirWithSlash stringByAppendingString:file]; // <-- Change the string "file" to reflect the name you want.
[UIImagePNGRepresentation(image) writeToFile:pngFile atomically:YES];

// Send pngFile to the server here

其中 applicationDocumentsDirectory 如下所示:

- (NSString *) applicationDocumentsDirectory
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

    NSString *documentsDirectoryPath = [paths objectAtIndex:0];
    return documentsDirectoryPath;
}

UIImagePNGRepresentation(UIImage*) is likely what you're looking for. You can save a UIImage as a PNG file in the Application Documents folder, then upload that to a server. The code to do this is quite trivial, so if you could post the code you're trying to use, that would be helpful to understanding, and recommending a solution for you.

Here's a short clipping from my code that does exactly this:

UIImage * image; // Some image you want to send

NSString * docDirWithSlash = [[self applicationDocumentsDirectory] stringByAppendingString:@"/"];
NSString * pngFile = [docDirWithSlash stringByAppendingString:file]; // <-- Change the string "file" to reflect the name you want.
[UIImagePNGRepresentation(image) writeToFile:pngFile atomically:YES];

// Send pngFile to the server here

Where applicationDocumentsDirectory looks like this:

- (NSString *) applicationDocumentsDirectory
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

    NSString *documentsDirectoryPath = [paths objectAtIndex:0];
    return documentsDirectoryPath;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文