Кажется, мне не удается прикрепить тег, который я добавляю к изображению, после сохранения изображения в поток памяти. Есть идеи, как мне сделать так, чтобы этот тег оказался в массиве байтов imageCache после того, как я попытаюсь скопировать его в другой поток памяти?
byte[] imageCache = File.ReadAllBytes(@"c:\test\test.tif");
using (MemoryStream msOut = new MemoryStream())
{
using (MemoryStream ms = new MemoryStream(imageCache))
{
using (Image image = Image.FromStream(ms))
{
/*
Total tags on page 1 of 3: 20 tags
Image does not show the tag I want to add. This is expected.
*/
// Select the correct page (1 of 3)
image.SelectActiveFrame(FrameDimension.Page, 0);
// Add a tag to the image's page 1
PropertyItem property = CreateBasePropertyItem();
property.Id = 38888;
property.Type = 2;
property.Value = Encoding.ASCII.GetBytes("This is a test tag.");
property.Len = property.Value.Length;
// Save the tag on the image's page 1
image.SetPropertyItem(property);
/*
Total tags on page 1 of 3: 21 tags
Image does show the tag I just added. This is expected.
*/
// Save the image to a new memory stream
image.Save(msOut, image.RawFormat);
}
}
// Convert the new image to a byte array to replace the cached byte array
imageCache = msOut.ToArray();
}
using (MemoryStream ms = new MemoryStream(imageCache))
{
using (Image image = Image.FromStream(ms))
{
/*
Total tags on page 1 of 3: 13 tags
Image does not show the new tag I added above. This is not expected.
*/
}
}
Просто чтобы никому не приходилось спрашивать, в том числе и об этом, хотя это не имеет отношения к цели моего вопроса.
private PropertyItem CreateBasePropertyItem()
{
BindingFlags flags = (BindingFlags)(-20);
PropertyItem pi = (PropertyItem)typeof(PropertyItem)
.Assembly
.CreateInstance("System.Drawing.Imaging.PropertyItem", false, flags, null, null, null, null);
return pi;
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... -in-memory
Сохранение тега в файл изображения и повторная загрузка его в память. ⇐ C#
Место общения программистов C#
1731442348
Anonymous
Кажется, мне не удается прикрепить тег, который я добавляю к изображению, после сохранения изображения в поток памяти. Есть идеи, как мне сделать так, чтобы этот тег оказался в массиве байтов imageCache после того, как я попытаюсь скопировать его в другой поток памяти?
byte[] imageCache = File.ReadAllBytes(@"c:\test\test.tif");
using (MemoryStream msOut = new MemoryStream())
{
using (MemoryStream ms = new MemoryStream(imageCache))
{
using (Image image = Image.FromStream(ms))
{
/*
Total tags on page 1 of 3: 20 tags
Image does not show the tag I want to add. This is expected.
*/
// Select the correct page (1 of 3)
image.SelectActiveFrame(FrameDimension.Page, 0);
// Add a tag to the image's page 1
PropertyItem property = CreateBasePropertyItem();
property.Id = 38888;
property.Type = 2;
property.Value = Encoding.ASCII.GetBytes("This is a test tag.");
property.Len = property.Value.Length;
// Save the tag on the image's page 1
image.SetPropertyItem(property);
/*
Total tags on page 1 of 3: 21 tags
Image does show the tag I just added. This is expected.
*/
// Save the image to a new memory stream
image.Save(msOut, image.RawFormat);
}
}
// Convert the new image to a byte array to replace the cached byte array
imageCache = msOut.ToArray();
}
using (MemoryStream ms = new MemoryStream(imageCache))
{
using (Image image = Image.FromStream(ms))
{
/*
Total tags on page 1 of 3: 13 tags
Image does not show the new tag I added above. This is not expected.
*/
}
}
Просто чтобы никому не приходилось спрашивать, в том числе и об этом, хотя это не имеет отношения к цели моего вопроса.
private PropertyItem CreateBasePropertyItem()
{
BindingFlags flags = (BindingFlags)(-20);
PropertyItem pi = (PropertyItem)typeof(PropertyItem)
.Assembly
.CreateInstance("System.Drawing.Imaging.PropertyItem", false, flags, null, null, null, null);
return pi;
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79182593/saving-a-tag-to-an-image-file-and-loading-it-again-all-in-memory[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия