15 Ocak 2017 Pazar

Image Sınıfı

Giriş
Şu satırı dahil ederiz.
using System.Drawing;
Soyut bir sınıftır. Bu sınıfı System.Drawing.Bitmap ve System.Drawing.Imaging.Metafile sınıfları gerçekleştirir.

FromFile metodu
Şöyle yaparız.
using (var file = Image.FromFile(tempPath)){...}
FromStream metodu
Şöyle yaparız.
using (MemoryStream ms = new MemoryStream(...))
{
     pictureBox1.Image = Image.FromStream(ms);
}
Eğer "embedded color management" yapmak istersek şöyle yaparız. Ne işe yaradığını anlamadım.
pictureBox1.Image = Image.FromStream(ms, true);
PropertyItemsAlanı
EXIF tag alanlarını doldurmak için şöyle yaparız.
var propTitle = img.PropertyItems[0];
propTitle.Id = 0x010E;
propTitle.Type = 2;
propTitle.Value = Encoding.UTF8.GetBytes($"{title}\0");
propTitle.Len = propTitle.Value.Length;
img.SetPropertyItem(propTitle);

var propTags = img.PropertyItems[0];
propTags.Id = 0x9286;
propTags.Type = 2;
propTags.Value = Encoding.UTF8.GetBytes($"{tags}\0");
propTags.Len = propTags.Value.Length;
img.SetPropertyItem(propTags);
TIFF dosyasında şöyle yaparız.
Bitmap bmp = ...;
PropertyItem[] imageProps = bmp.PropertyItems;

var modelscale = imageProps.First(a => a.Id == GEOTIFF_MODELPIXELSCALETAG);
var tiepoint = imageProps.First(a => a.Id == GEOTIFF_MODELTIEPOINTTAG);

private readonly int GEOTIFF_MODELPIXELSCALETAG = 33550;
private readonly int GEOTIFF_MODELTIEPOINTTAG = 33922;
RawFormat Alanı
ImageFormat tipindedir. Resmin formatını belirtir. Şöyle yaparız.
using(var ms = new MemoryStream())
{
  image.Save(ms, image.RawFormat);
  ...
}
Save metodu
İmzası şöyle
public void Save(Stream stream, ImageFormat format);
Şöyle yaparız.
img.Save (finalPath);


Hiç yorum yok:

Yorum Gönder