Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Iti trebuie intai cele 2 metode enumerate mai jos (iti zic doar varianta mai rapida dintre multiplele variante):
- Iti va trebui de asemenea ultimul release BitMiracle.LibTiff
- private static WriteableBitmap workingWBM;
- public WriteableBitmap LoadPage(short page, Tiff timage)
- {
- FieldValue[] value = timage.GetField(TiffTag.IMAGEWIDTH);
- int width = value[0].ToInt();
- value = timage.GetField(TiffTag.IMAGELENGTH);
- int height = value[0].ToInt();
- value = timage.GetField(TiffTag.BITSPERSAMPLE);
- int bps = value[0].ToShort();
- value = timage.GetField(TiffTag.SAMPLESPERPIXEL);
- int spp = value[0].ToShort();
- int imageSize = height * width;
- int[] raster = new int[imageSize];
- timage.SetDirectory(page);
- //citim in buffer imaginea
- if (!timage.ReadRGBAImage(width, height, raster))
- {
- System.Console.Error.WriteLine("Eroare la citire (format imagine?)");
- return null;
- }
- workingWBM = new WriteableBitmap(width, height);
- //vertical flip, poveste lunga :)
- int cnt = 0;
- for (int e = height - 1; e != -1; e--)
- {
- for (int c = 0; c < width; c++)
- {
- int red = Tiff.GetR(raster[e * width + c]);
- int green = Tiff.GetG(raster[e * width + c]);
- int blue = Tiff.GetB(raster[e * width + c]);
- //Array.Copy(
- workingWBM.Pixels[cnt] = (255 << 24) + (red << 16) + (green << 8) + (blue);
- cnt++;
- }
- }
- //teste
- //wb.Render(
- //BitmapImage bi = new BitmapImage();
- //bi.
- //wb.Render(this.image, new MatrixTransform());
- //this.image.Source = wb;
- //timage.Close();
- return workingWBM;
- }
- public class MemTiffStream : TiffStream
- {
- public MemoryStream memStream;
- public MemTiffStream(MemoryStream ms)
- : base()
- {
- memStream = ms;
- }
- public override int Read(object clientData, byte[] buffer, int offset, int count)
- {
- return memStream.Read(buffer, offset, count);
- }
- public override void Close(object clientData)
- {
- memStream.Close();
- }
- public override long Seek(object clientData, long offset, System.IO.SeekOrigin origin)
- {
- return memStream.Seek(offset, origin);
- }
- public override long Size(object clientData)
- {
- return memStream.Length;
- }
- }
- //exemplu de usage:
- //loadOp.value este un byte[] care contine tiff-ul multi page
- this.imageControl1.Images = null;
- using (var ms = new MemoryStream())
- {
- ms.Write(loadOp.Value, 0, loadOp.Value.Length);
- ms.Position = 0;
- var mts = new MemTiffStream(ms);
- var timage = Tiff.ClientOpen("a", "r", null, mts);
- var lstimg = new List<WriteableBitmap>();
- for (short i = 0; i < timage.NumberOfDirectories(); i++)
- {
- try
- {
- var wb = LoadPage(i, timage);
- lstimg.Add(wb);
- }
- catch { }
- }
- this.imageControl1.Images = lstimg;
- }
Add Comment
Please, Sign In to add comment