Lưu bitmap thành png với dữ liệu medata wpf c # [trùng lặp]
Dec 30 2020
Tôi cần lưu một bitmap thành jpg với medata như bản quyền trong wpf c #.
var handle = BitmapImage2Bitmap(currentimage).GetHbitmap();
System.Drawing.Image img = System.Drawing.Image.FromHbitmap(handle);
System.Drawing.Imaging.PropertyItem prop = img.PropertyItems[0];
SetProperty(ref prop, 33432, "Copyright");
img.SetPropertyItem(prop);
img.Save(@"C:\images\test.jpg");
Tôi đã thử sử dụng mã ở trên nhưng nó nói rằng chỉ mục nằm ngoài mảng.
Trả lời
Charlieface Dec 30 2020 at 09:52
var prop = img.GetPropertyItem(0x503B);
prop.Value = Encoding.Ascii.GetBytes("copyright name");
prop.Len = prop.Value.Length;
img.SetPropertyItem(prop);
Giá trị 0x503B đến từ đây: Thuộc tính PropertyItem.Id