gpt4 book ai didi

c# - 如何重命名图像

转载 作者:太空宇宙 更新时间:2023-11-03 19:29:10 26 4
gpt4 key购买 nike

我有一张图片,person1.png,还有另外四张图片,person2.pngperson3.pngperson5 .pngperson4.png。我想用 C# 代码重命名这些图像。我该怎么做?

最佳答案

由于 PNG 文件在您的 XAP 中,您可以像这样将它们保存到您的 IsolatedStorage 中:

//make sure PNG_IMAGE is set as 'Content' build type
var pngStream= Application.GetResourceStream(new Uri(PNG_IMAGE, UriKind.Relative)).Stream;

int counter;
byte[] buffer = new byte[1024];
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(IMAGE_NAME, FileMode.Create, isf))
{
counter = 0;
while (0 < (counter = pngStream.Read(buffer, 0, buffer.Length)))
{
isfs.Write(buffer, 0, counter);
}

pngStream.Close();

}
}

在这里您可以通过更改IMAGE_NAME 将其保存为您想要的任何文件名。

要再次读出来,你可以这样做:

byte[] streamData;    

using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isfs = isf.OpenFile("image.png", FileMode.Open, FileAccess.Read))
{
streamData = new byte[isfs.Length];
isfs.Read(streamData, 0, streamData.Length);
}
}

MemoryStream ms = new MemoryStream(streamData);
BitmapImage bmpImage= new BitmapImage();
bmpImage.SetSource(ms);
image1.Source = bmpImage; //image1 being your Image control

关于c# - 如何重命名图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6244150/

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