public static Image FromStream (Stream stream, bool useEmbeddedColorManagement) { DotGNU.Images.Image image = new DotGNU.Images.Image(); image.Load(stream); return(new Bitmap(image)); }
public static Image FromFile (String filename, bool useEmbeddedColorManagement) { DotGNU.Images.Image image = new DotGNU.Images.Image(); image.Load(filename); return(new Bitmap(image)); }
// Draw the source parallelogram of an image into the parallelogram // defined by dest. Point[] has 3 Points, Top-Left, Top-Right and Bottom-Left. // The remaining point is inferred. public virtual void DrawImage(IToolkitImage image, Point[] src, Point[] dest) { int originX = dest[0].X; int originY = dest[0].Y; for (int i = 1; i < 3; i++) { if (originX > dest[i].X) { originX = dest[i].X; } if (originY > dest[i].Y) { originY = dest[i].Y; } } DotGNU.Images.Image gnuImage = (image as ToolkitImageBase).image; // Currently we only draw the first frame. Frame frame = gnuImage.GetFrame(0); frame = frame.AdjustImage(src[0].X, src[0].Y, src[1].X, src[1].Y, src[2].X, src[2].Y, dest[0].X - originX, dest[0].Y - originY, dest[1].X - originX, dest[1].Y - originY, dest[2].X - originX, dest[2].Y - originY); // Setup the new image and draw it. using (DotGNU.Images.Image newGnuImage = new DotGNU.Images.Image(gnuImage.Width, gnuImage.Height, gnuImage.PixelFormat)) { newGnuImage.AddFrame(frame); IToolkitImage newImage = Toolkit.CreateImage(newGnuImage, 0); DrawImage(newImage, originX, originY); } }
/// <summary> /// <para>Constructs a new <see cref="T:Xsharp.Image"/> instance /// that represents an off-screen image that was loaded /// from a file.</para> /// </summary> /// /// <param name="screen"> /// <para>The screen upon which to create the new pixmap.</para> /// </param> /// /// <param name="filename"> /// <para>The file to load the image from.</para> /// </param> /// /// <exception cref="T:System.ArgumentNullException"> /// <para>The <paramref name="filename"/> parameter is /// <see langword="null"/>.</para> /// </exception> /// /// <exception cref="T:System.FormatException"> /// <para>The image format is not recognized.</para> /// </exception> /// /// <exception cref="T:Xsharp.XInvalidOperationException"> /// <para>Raised if <paramref name="filename"/> could not be /// loaded for some reason.</para> /// </exception> public Image(Screen screen, String filename) { Display dpy; if (filename == null) { throw new ArgumentNullException("filename"); } if (screen != null) { dpy = screen.DisplayOfScreen; } else { dpy = Application.Primary.Display; screen = dpy.DefaultScreenOfDisplay; } this.screen = screen; DotGNU.Images.Image img = new DotGNU.Images.Image(); img.Load(filename); Frame frame = img.GetFrame(0); try { dpy.Lock(); pixmapXImage = ConvertImage.FrameToXImage(screen, frame); maskXImage = ConvertImage.MaskToXImage(screen, frame); } finally { dpy.Unlock(); } }
// Load the icon contents from a stream, and then set the // current frame to the first one in the icon image. private void Load(Stream stream) { image = new DotGNU.Images.Image(); image.Load(stream); frame = image.GetFrame(0); frameNum = 0; }
// Constructor. public DrawingImage(Screen screen, DotGNU.Images.Image image, int frame) : base(image, frame) { this.screen = screen; base.frame = frame; base.image = image; ImageChanged(); }
protected virtual void Dispose(bool disposing) { if (dgImage != null) { dgImage.Dispose(); dgImage = null; } }
// This is an internal member and should not be used. // Returns a bitmap which is the resized (to newWidth and newHeight) of the first frame. public Image Resize(int newWidth, int newHeight) { Frame frame = dgImage.GetFrame(0); Frame newFrame = frame.AdjustImage(0, 0, width, 0, 0, height, 0, 0, newWidth, 0, 0, newHeight); DotGNU.Images.Image newImage = new DotGNU.Images.Image(newWidth, newHeight, newFrame.PixelFormat); newImage.AddFrame(newFrame); return(new Bitmap(newImage)); }
internal Image(SerializationInfo info, StreamingContext context) { // Do we need to Handle PixelFormats ?. byte[] data = null; data = (byte[])info.GetValue("Data", typeof(byte[])); MemoryStream stream = new MemoryStream(data,false); DotGNU.Images.Image dgImage = new DotGNU.Images.Image(); dgImage.Load(stream); SetDGImage(dgImage); }
private Icon(Icon cloneFrom) { if (cloneFrom == null) { throw new ArgumentNullException("cloneFrom"); } image = (DotGNU.Images.Image)(cloneFrom.image.Clone()); frameNum = cloneFrom.frameNum; frame = image.GetFrame(frameNum); }
internal Image(SerializationInfo info, StreamingContext context) { // Do we need to Handle PixelFormats ?. byte[] data = null; data = (byte[])info.GetValue("Data", typeof(byte[])); MemoryStream stream = new MemoryStream(data, false); DotGNU.Images.Image dgImage = new DotGNU.Images.Image(); dgImage.Load(stream); SetDGImage(dgImage); }
// Copy image into this.image at x, y public override void DrawImage(IToolkitImage image, int x, int y) { DotGNU.Images.Image sourceImage = (image as ToolkitImageBase).image; Frame sourceFrame = sourceImage.GetFrame(0); DotGNU.Images.Image destImage = this.image.image; Frame destFrame =destImage.GetFrame(0); if (sourceFrame.PixelFormat != destFrame.PixelFormat) sourceFrame = sourceFrame.Reformat(destImage.PixelFormat); destFrame.Copy(sourceFrame, x, y); this.image.ImageChanged(); }
// Set the dgImage field within this object. internal void SetDGImage(DotGNU.Images.Image dgImage) { flags = 0; #if !ECMA_COMPAT switch (dgImage.LoadFormat) { case DotGNU.Images.Image.Png: rawFormat = ImageFormat.Png; break; case DotGNU.Images.Image.Jpeg: rawFormat = ImageFormat.Jpeg; break; case DotGNU.Images.Image.Gif: rawFormat = ImageFormat.Gif; break; case DotGNU.Images.Image.Tiff: rawFormat = ImageFormat.Tiff; break; case DotGNU.Images.Image.Bmp: rawFormat = ImageFormat.Bmp; break; case DotGNU.Images.Image.Icon: rawFormat = ImageFormat.Icon; break; case DotGNU.Images.Image.Exif: rawFormat = ImageFormat.Exif; break; } frameDimensionsList = new Guid [0]; this.dgImage = dgImage; // If we are loading an icon, set the size of the image // to the size of the first icon if (rawFormat == ImageFormat.Icon || rawFormat == ImageFormat.Gif) { width = dgImage.GetFrame(0).Width; height = dgImage.GetFrame(0).Height; } else { width = dgImage.Width; height = dgImage.Height; } #else this.dgImage = dgImage; width = dgImage.GetFrame(0).Width; height = dgImage.GetFrame(0).Height; #endif horizontalResolution = Graphics.DefaultScreenDpi; verticalResolution = Graphics.DefaultScreenDpi; pixelFormat = (System.Drawing.Imaging.PixelFormat) (dgImage.PixelFormat); }
// Implement the IDisposable interface. public void Dispose() { if (toolkitImage != null) { toolkitImage.Dispose(); toolkitImage = null; } if (image != null) { image.Dispose(); image = null; frame = null; frameNum = 0; } }
public Bitmap(Type type, String resource) { Stream stream = GetManifestResourceStream(type, resource); if (stream == null) { throw new ArgumentException(S._("Arg_UnknownResource")); } try { DotGNU.Images.Image dgImage = new DotGNU.Images.Image(); dgImage.Load(stream); SetDGImage(dgImage); } finally { stream.Close(); } }
// Create a gradient for the background of a title bar. private DotGNU.Images.Image CreateGradient (int width, int height, Color startColor, Color endColor) { if(startColor.Index != StandardColor.RGB) { startColor = screen.ToColor(startColor.Index); } if(endColor.Index != StandardColor.RGB) { endColor = screen.ToColor(endColor.Index); } int startR = startColor.Red; int startG = startColor.Green; int startB = startColor.Blue; int lenR = endColor.Red - startR; int lenG = endColor.Green - startG; int lenB = endColor.Blue - startB; DotGNU.Images.Image image = new DotGNU.Images.Image (width, height, PixelFormat.Format24bppRgb); Frame frame = image.AddFrame(); int x, y, red, green, blue; for(y = 0; y < height; ++y) { for(x = 0; x < width; ++x) { red = startR + lenR * x / width; green = startG + lenG * x / width; blue = startB + lenB * x / width; frame.SetPixel(x, y, (red << 16) + (green << 8) + blue); } } return image; }
public Bitmap(Stream stream, bool useIcm) { DotGNU.Images.Image dgImage = new DotGNU.Images.Image(); dgImage.Load(stream); SetDGImage(dgImage); }
// Create a device independant bitmap from a frame. Optionally set all bits that are masked to black. // This is required for icons. private IntPtr HandleFromBitmap(Frame frame, bool andMask) { // By default we use the data straight from the frame. byte[] data = frame.Data; if (andMask) { //TODO: this could be slow. // Create a new image that we will copy the pixels to, leaving the masked pixels black. DotGNU.Images.Image newImage = new DotGNU.Images.Image(frame.Width, frame.Height, frame.PixelFormat); Frame newFrame = newImage.AddFrame(); data = new byte[data.Length]; for (int y = 0; y < frame.Height; y++) { for (int x = 0; x < frame.Width; x++) { if (frame.GetMask(x, y) != 0) { newFrame.SetPixel(x, y, frame.GetPixel(x, y)); } } } data = newFrame.Data; } // Create BITMAPINFO structure. int bitmapInfoSize = 40; int bitCount = frame.BitsPerPixel; // Do we have a palette? if (bitCount <= 8) { bitmapInfoSize += 1 << bitCount * 4; } byte[] bitmapInfo = new byte[bitmapInfoSize]; // Build and write the BITMAPINFOHEADER structure. WriteInt32(bitmapInfo, 0, 40); // biSize WriteInt32(bitmapInfo, 4, frame.Width); WriteInt32(bitmapInfo, 8, -frame.Height); // upside down so make the height negative. WriteUInt16(bitmapInfo, 12, 1); // biPlanes WriteUInt16(bitmapInfo, 14, bitCount); WriteInt32(bitmapInfo, 16, 0); // biCompression WriteInt32(bitmapInfo, 20, 0); // size of image WriteInt32(bitmapInfo, 24, 3780); // biXPelsPerMeter WriteInt32(bitmapInfo, 28, 3780); // biYPelsPerMeter WriteInt32(bitmapInfo, 32, 0); // biClrUsed WriteInt32(bitmapInfo, 36, 0); // biClrImportant // Write the palette. if (bitCount <= 8) { int count = (1 << bitCount); for (int index = 0; index < count; ++index) { if (frame.Palette != null && index < frame.Palette.Length) { WriteBGR(bitmapInfo, index * 4 + 40, frame.Palette[index]); } else { // Short palette: pad with black pixels. WriteBGR(bitmapInfo, index * 4 + 40, 0); } } } return(Win32.Api.CreateDIBitmap(Win32.Api.GetDC(hwnd), bitmapInfo, 4 /*CBM_INIT*/, data, bitmapInfo, 0 /*DIB_RGB_COLORS*/)); }
// This is an internal member and should not be used. // Returns a bitmap which is the resized (to newWidth and newHeight) of the first frame. public Image Resize(int newWidth, int newHeight) { Frame frame = dgImage.GetFrame(0); Frame newFrame = frame.AdjustImage(0, 0, width, 0, 0, height, 0, 0, newWidth, 0, 0, newHeight); DotGNU.Images.Image newImage = new DotGNU.Images.Image(newWidth, newHeight, newFrame.PixelFormat); newImage.AddFrame(newFrame); return new Bitmap(newImage); }
public static Image FromStream (Stream stream, bool useEmbeddedColorManagement) { DotGNU.Images.Image image = new DotGNU.Images.Image(); image.Load(stream); return new Bitmap(image); }
public IToolkitImage CreateImage(DotGNU.Images.Image image, int frame) { return(new DrawingImage (app.Display.DefaultScreenOfDisplay, image, frame)); }
public IToolkitImage CreateImage(DotGNU.Images.Image image, int frame) { return(new DrawingImage(image, frame)); }
public virtual IToolkitImage CreateImage( Image image, int frame ) { return null; }
public ToolkitImageBase(Image image, int frame) { this.image = image; this.frame = frame; }
public Bitmap(String filename, bool useIcm) { DotGNU.Images.Image dgImage = new DotGNU.Images.Image(); dgImage.Load(filename); SetDGImage(dgImage); }
protected virtual void Dispose(bool disposing) { if(dgImage != null) { dgImage.Dispose(); dgImage = null; } }
public static Image FromFile (String filename, bool useEmbeddedColorManagement) { DotGNU.Images.Image image = new DotGNU.Images.Image(); image.Load(filename); return new Bitmap(image); }
public DrawingImage(DotGNU.Images.Image image, int frame) : base(image, frame) { ImageChanged(); }
// Set the dgImage field within this object. internal void SetDGImage(DotGNU.Images.Image dgImage) { flags = 0; #if !ECMA_COMPAT switch(dgImage.LoadFormat) { case DotGNU.Images.Image.Png: rawFormat = ImageFormat.Png; break; case DotGNU.Images.Image.Jpeg: rawFormat = ImageFormat.Jpeg; break; case DotGNU.Images.Image.Gif: rawFormat = ImageFormat.Gif; break; case DotGNU.Images.Image.Tiff: rawFormat = ImageFormat.Tiff; break; case DotGNU.Images.Image.Bmp: rawFormat = ImageFormat.Bmp; break; case DotGNU.Images.Image.Icon: rawFormat = ImageFormat.Icon; break; case DotGNU.Images.Image.Exif: rawFormat = ImageFormat.Exif; break; } frameDimensionsList = new Guid [0]; this.dgImage = dgImage; // If we are loading an icon, set the size of the image // to the size of the first icon if (rawFormat == ImageFormat.Icon) { width = dgImage.GetFrame(0).Width; height = dgImage.GetFrame(0).Height; } else { width = dgImage.Width; height = dgImage.Height; } #else this.dgImage = dgImage; width = dgImage.GetFrame(0).Width; height = dgImage.GetFrame(0).Height; #endif horizontalResolution = Graphics.DefaultScreenDpi; verticalResolution = Graphics.DefaultScreenDpi; pixelFormat = (System.Drawing.Imaging.PixelFormat) (dgImage.PixelFormat); }
/// <summary> /// <para>Constructs a new <see cref="T:Xsharp.Image"/> instance /// that represents an off-screen image that was loaded /// from a file.</para> /// </summary> /// /// <param name="screen"> /// <para>The screen upon which to create the new pixmap.</para> /// </param> /// /// <param name="filename"> /// <para>The file to load the image from.</para> /// </param> /// /// <exception cref="T:System.ArgumentNullException"> /// <para>The <paramref name="filename"/> parameter is /// <see langword="null"/>.</para> /// </exception> /// /// <exception cref="T:System.FormatException"> /// <para>The image format is not recognized.</para> /// </exception> /// /// <exception cref="T:Xsharp.XInvalidOperationException"> /// <para>Raised if <paramref name="filename"/> could not be /// loaded for some reason.</para> /// </exception> public Image(Screen screen, String filename) { Display dpy; if(filename == null) { throw new ArgumentNullException("filename"); } if(screen != null) { dpy = screen.DisplayOfScreen; } else { dpy = Application.Primary.Display; screen = dpy.DefaultScreenOfDisplay; } this.screen = screen; DotGNU.Images.Image img = new DotGNU.Images.Image(); img.Load(filename); Frame frame = img.GetFrame(0); try { dpy.Lock(); pixmapXImage = ConvertImage.FrameToXImage(screen, frame); maskXImage = ConvertImage.MaskToXImage(screen, frame); } finally { dpy.Unlock(); } }
// Implement the IDisposable interface. public void Dispose() { if(toolkitImage != null) { toolkitImage.Dispose(); toolkitImage = null; } if(image != null) { image.Dispose(); image = null; frame = null; frameNum = 0; } }
public virtual IToolkitImage CreateImage(DotGNU.Images.Image image, int frame) { return(null); }
private Icon(Icon cloneFrom) { if(cloneFrom == null) { throw new ArgumentNullException("cloneFrom"); } image = (DotGNU.Images.Image)(cloneFrom.image.Clone()); frameNum = cloneFrom.frameNum; frame = image.GetFrame(frameNum); }
internal Image(DotGNU.Images.Image dgImage) { SetDGImage(dgImage); }
public Bitmap(Type type, String resource) { Stream stream = GetManifestResourceStream(type, resource); if(stream == null) { throw new ArgumentException(S._("Arg_UnknownResource")); } try { DotGNU.Images.Image dgImage = new DotGNU.Images.Image(); dgImage.Load(stream); SetDGImage(dgImage); } finally { stream.Close(); } }
internal Bitmap(DotGNU.Images.Image image) : base(image) { }
// Create a device independant bitmap from a frame. Optionally set all bits that are masked to black. // This is required for icons. private IntPtr HandleFromBitmap(Frame frame, bool andMask) { // By default we use the data straight from the frame. byte[] data = frame.Data; if (andMask) { //TODO: this could be slow. // Create a new image that we will copy the pixels to, leaving the masked pixels black. DotGNU.Images.Image newImage = new DotGNU.Images.Image(frame.Width, frame.Height, frame.PixelFormat); Frame newFrame = newImage.AddFrame(); data = new byte[data.Length]; for (int y = 0; y < frame.Height; y++) { for (int x = 0; x < frame.Width; x++) { if (frame.GetMask(x, y) != 0) newFrame.SetPixel(x, y, frame.GetPixel(x, y)); } } data = newFrame.Data; } // Create BITMAPINFO structure. int bitmapInfoSize = 40; int bitCount = frame.BitsPerPixel; // Do we have a palette? if(bitCount <= 8) bitmapInfoSize += 1 << bitCount * 4; byte[] bitmapInfo = new byte[bitmapInfoSize]; // Build and write the BITMAPINFOHEADER structure. WriteInt32(bitmapInfo, 0, 40);// biSize WriteInt32(bitmapInfo, 4, frame.Width); WriteInt32(bitmapInfo, 8, -frame.Height);// upside down so make the height negative. WriteUInt16(bitmapInfo, 12, 1);// biPlanes WriteUInt16(bitmapInfo, 14, bitCount); WriteInt32(bitmapInfo, 16, 0);// biCompression WriteInt32(bitmapInfo, 20, 0);// size of image WriteInt32(bitmapInfo, 24, 3780);// biXPelsPerMeter WriteInt32(bitmapInfo, 28, 3780);// biYPelsPerMeter WriteInt32(bitmapInfo, 32, 0); // biClrUsed WriteInt32(bitmapInfo, 36, 0); // biClrImportant // Write the palette. if(bitCount <= 8) { int count = (1 << bitCount); for(int index = 0; index < count; ++index) { if(frame.Palette != null && index < frame.Palette.Length) WriteBGR(bitmapInfo, index * 4 + 40, frame.Palette[index]); else { // Short palette: pad with black pixels. WriteBGR(bitmapInfo, index * 4 + 40, 0); } } } return Win32.Api.CreateDIBitmap( Win32.Api.GetDC(hwnd), bitmapInfo, 4 /*CBM_INIT*/, data, bitmapInfo, 0 /*DIB_RGB_COLORS*/); }
// Constructor. public PostscriptImage(DotGNU.Images.Image image, int frame) : base(image, frame) { ImageChanged(); }
// Draw the source parallelogram of an image into the parallelogram // defined by dest. Point[] has 3 Points, Top-Left, Top-Right and Bottom-Left. // The remaining point is inferred. public virtual void DrawImage(IToolkitImage image, Point[] src, Point[] dest) { int originX = dest[0].X; int originY = dest[0].Y; for (int i = 1; i < 3; i++) { if (originX > dest[i].X) originX = dest[i].X; if (originY > dest[i].Y) originY = dest[i].Y; } DotGNU.Images.Image gnuImage = (image as ToolkitImageBase).image; // Currently we only draw the first frame. Frame frame = gnuImage.GetFrame(0); frame = frame.AdjustImage(src[0].X, src[0].Y, src[1].X, src[1].Y, src[2].X, src[2].Y, dest[0].X - originX, dest[0].Y - originY, dest[1].X - originX, dest[1].Y - originY, dest[2].X - originX, dest[2].Y - originY); // Setup the new image and draw it. using (DotGNU.Images.Image newGnuImage = new DotGNU.Images.Image(gnuImage.Width, gnuImage.Height, gnuImage.PixelFormat)) { newGnuImage.AddFrame(frame); IToolkitImage newImage = Toolkit.CreateImage(newGnuImage, 0); DrawImage( newImage, originX, originY); } }
public ToolkitImageBase(DotGNU.Images.Image image, int frame) { this.image = image; this.frame = frame; }