Presentation is loading. Please wait.

Presentation is loading. Please wait.

Računarska grafika GDI+ (Graphics Device Interface Plus)

Similar presentations


Presentation on theme: "Računarska grafika GDI+ (Graphics Device Interface Plus)"— Presentation transcript:

1 Računarska grafika GDI+ (Graphics Device Interface Plus)

2 Bitmaps A bitmap is an array of bits that specify the color of each pixel in a rectangular array of pixels. Bits per pixel Number of colors that can be assigned to a pixel 12^1 = 2 22^2 = 4 42^4 = 16 82^8 = 256 162^16 = 65,536 242^24 = 16,777,216

3 Bitmaps a file might also contain a color table (sometimes called a color palette). A color table maps numbers in the bitmap to specific colors.

4 Graphics File Formats There are many standard formats for saving bitmaps in disk files. GDI+ supports following formats: ▫BMP ▫Graphics Interchange Format (GIF) ▫Joint Photographic Experts Group (JPEG) ▫Exchangeable Image File (EXIF) ▫Portable Network Graphics (PNG) ▫Tag Image File Format (TIFF)

5 BMP BMP is a standard format used by Windows to store device-independent and application- independent images. The number of bits per pixel (1, 4, 8, 15, 24, 32, or 64) for a given BMP file is specified in a file header. BMP files with 24 bits per pixel are common. BMP files are usually not compressed and, therefore, are not well suited for transfer across the Internet.

6 GIF GIF is a common format for images that appear on Web pages. GIFs work well for line drawings, pictures with blocks of solid color, and pictures with sharp boundaries between colors. GIFs are compressed, but no information is lost in the compression process; a decompressed image is exactly the same as the original. One color in a GIF can be designated as transparent, so that the image will have the background color of any Web page that displays it. A sequence of GIF images can be stored in a single file to form an animated GIF. GIFs store at most 8 bits per pixel, so they are limited to 256 colors.

7 JPEG JPEG is a compression scheme that works well for natural scenes such as scanned photographs. Some information is lost in the compression process, but often the loss is imperceptible to the human eye. JPEGs store 24 bits per pixel, so they are capable of displaying more than 16 million colors. JPEGs do not support transparency or animation.

8 JPEG The level of compression in JPEG images is configurable, but higher compression levels (smaller files) result in more loss of information. A 20:1 compression ratio often produces an image that the human eye finds difficult to distinguish from the original.

9 BMP & JPEG & GIF JPEG compression does not work well for line drawings, blocks of solid color, and sharp boundaries. The JPEGs and the GIF were compressed from the BMP. Note that the GIF maintains the sharp boundaries along the lines, but the JPEGs tend to blur the boundaries.

10 JFIF JPEG is a compression scheme, not a file format. JPEG File Interchange Format (JFIF) is a file format commonly used for storing and transferring images that have been compressed according to the JPEG scheme. JFIF files displayed by Web browsers use the.jpg extension.

11 EXIF EXIF is a file format used for photographs captured by digital cameras. An EXIF file contains an image that is compressed according to the JPEG specification. An EXIF file also contains information about the photograph (date taken, shutter speed, exposure time, and so on) and information about the camera (manufacturer, model, and so on).

12 PNG The PNG format retains many of the advantages of the GIF format but also provides capabilities beyond those of GIF. Like GIF files, PNG files are compressed with no loss of information. PNG files can store colors with 8, 24, or 48 bits per pixel and grayscales with 1, 2, 4, 8, or 16 bits per pixel. In contrast, GIF files can use only 1, 2, 4, or 8 bits per pixel. A PNG file can also store an alpha value for each pixel, which specifies the degree to which the color of that pixel is blended with the background color. PNG improves on GIF in its ability to progressively display an image (that is, to display better and better approximations of the image as it arrives over a network connection). PNG files can contain gamma correction and color correction information so that the images can be accurately rendered on a variety of display devices.

13 TIFF TIFF is a flexible and extendable format that is supported by a wide variety of platforms and image- processing applications. TIFF files can store images with an arbitrary number of bits per pixel and can employ a variety of compression algorithms. Several images can be stored in a single, multiple-page TIFF file. Information related to the image (scanner make, host computer, type of compression, orientation, samples per pixel, and so on) can be stored in the file and arranged through the use of tags. The TIFF format can be extended as needed by the approval and addition of new tags.

14 DrawImage DrawImage(Image image, Point) DrawImage(Image image, Point[] dest) DrawImage(Image image, Rectangle) DrawImage(Image image, Point[] dest, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr) image ▫Image to draw. Image dest ▫Array of three Point structures that define a parallelogram. Point srcRect ▫structure that specifies the portion of theimage object to draw. srcUnit ▫Member of the GraphicsUnit enumeration that specifies the units of measure used by the srcRectparameter. imageAttr ▫ImageAttributes that specifies recoloring and gamma information for the image object.

15 DrawImage g.DrawImage(Image.FromFile(@"c:\cym.jpg"), 50, 50); g.DrawImage(Image.FromFile(@"c:\cym.jpg"), new Rectangle(50,50,200,200)); g.DrawImage(Image.FromFile(@"c:\cym.jpg"), new Rectangle(50,50,200,200), new Rectangle(100,100,150,150), GraphicsUnit.Pixel); g.DrawImage(Bitmap.FromFile(@"c:\cym.jpg"), new Rectangle(50,50,200,200), new Rectangle(100,100,150,150), GraphicsUnit.Pixel);

16 Image NameDescription FlagsGets attribute flags for the pixel data of this Image. FrameDimensionsList Gets an array of GUIDs that represent the dimensions of frames within thisImage. HeightGets the height, in pixels, of this Image. HorizontalResolutionGets the horizontal resolution, in pixels per inch, of thisImage. PaletteGets or sets the color palette used for thisImage. PhysicalDimensionGets the width and height of this image. PixelFormatGets the pixel format for this Image. PropertyIdListGets IDs of the property items stored in this Image. PropertyItemsGets all the property items (pieces of metadata) stored in this Image. RawFormatGets the file format of this Image. SizeGets the width and height, in pixels, of this image. TagGets or sets an object that provides additional data about the image. VerticalResolutionGets the vertical resolution, in pixels per inch, of thisImage. WidthGets the width, in pixels, of this Image.

17 Image NameDescription CloneCreates an exact copy of this Image. FromFile(String)Creates an Imagefrom the specified file. FromFile(String, Boolean)Creates an Imagefrom the specified file using embedded color management information in that file. GetBoundsGets the bounds of the image in the specified unit. GetEncoderParameterListReturns information about the parameters supported by the specified image encoder. GetFrameCountReturns the number of frames of the specified dimension. GetPixelFormatSizeReturns the color depth, in number of bits per pixel, of the specified pixel format. GetPropertyItemGets the specified property item from this Image. GetThumbnailImageReturns a thumbnail for this Image. IsAlphaPixelFormatReturns a value that indicates whether the pixel format for this Image contains alpha information. IsCanonicalPixelFormatReturns a value that indicates whether the pixel format is 32 bits per pixel. IsExtendedPixelFormatReturns a value that indicates whether the pixel format is 64 bits per pixel. RemovePropertyItemRemoves the specified property item from thisImage. RotateFlipRotates, flips, or rotates and flips theImage. Save(String)Saves this Image to the specified file or stream. Save(String, ImageFormat)Saves this Image to the specified file in the specified format. Save(String, ImageCodecInfo, EncoderParameters) Saves this Image to the specified file, with the specified encoder and image-encoder parameters. SelectActiveFrameSelects the frame specified by the dimension and index. SetPropertyItemStores a property item (piece of metadata) in thisImage.

18 Image using (Bitmap background = (Bitmap)Bitmap.FromFile("c:\\pozadina.png")) { using (Bitmap foreground = (Bitmap)Bitmap.FromFile(@"c:\tekst.png")) { if (background.Height == foreground.Height & background.Width == foreground.Width) { using (Bitmap mergedImage = new Bitmap(background.Width, background.Height)) { for (int x = 0; x < mergedImage.Width; x++) { for (int y = 0; y < mergedImage.Height; y++) { Color backgroundPixel = background.GetPixel(x, y); Color foregroundPixel = foreground.GetPixel(x, y); Color mergedPixel = Color.FromArgb(backgroundPixel.ToArgb() & foregroundPixel.ToArgb()); mergedImage.SetPixel(x, y, mergedPixel); } mergedImage.Save("c:\\slika.jpg", ImageFormat.Jpeg); MessageBox.Show(“Zavrseno"); }

19 ThumbnailImage & Icon Image image = new Bitmap(@"c:\cym.jpg"); Image pThumbnail = image.GetThumbnailImage(100, 100, null, new IntPtr()); g.DrawImage(pThumbnail, 10, 10, pThumbnail.Width, pThumbnail.Height); Icon icon = new Icon(@"c:\frd.ico", 64, 64); g.DrawImage(icon.ToBitmap(), 50, 50);

20 ImageAttributes NameDescription ClearBrushRemapTableClears the brush color-remap table of this ImageAttributes object. ClearColorKey()Clears the color key (transparency range) for the default category. ClearColorKey(ColorAdjustType)Clears the color key (transparency range) for a specified category. ClearColorMatrix()Clears the color-adjustment matrix for the default category. ClearColorMatrix(ColorAdjustType)Clears the color-adjustment matrix for a specified category. ClearGamma()Disables gamma correction for the default category. ClearGamma(ColorAdjustType)Disables gamma correction for a specified category. ClearNoOp()Clears theNoOp setting for the default category. ClearNoOp(ColorAdjustType)Clears theNoOp setting for a specified category. ClearOutputChannel() Clears the CMYK (cyan-magenta-yellow-black) output channel setting for the default category. ClearOutputChannel(ColorAdjustType)Clears the (cyan-magenta-yellow-black) output channel setting for a specified category. ClearOutputChannelColorProfile()Clears the output channel color profile setting for the default category. ClearOutputChannelColorProfile(ColorAdj ustType) Clears the output channel color profile setting for a specified category.

21 ImageAttributes NameDescription ClearRemapTable()Clears the color-remap table for the default category. ClearRemapTable(ColorAdjustTy pe) Clears the color-remap table for a specified category. ClearThreshold()Clears the threshold value for the default category. ClearThreshold(ColorAdjustType ) Clears the threshold value for a specified category. CloneCreates an exact copy of thisImageAttributesobject. GetAdjustedPaletteAdjusts the colors in a palette according to the adjustment settings of a specified category. SetBrushRemapTableSets the color-remap table for the brush category. SetColorKey(Color, Color)Sets the color key for the default category. SetColorKey(Color, Color, ColorAdjustType) Sets the color key (transparency range) for a specified category. SetColorMatrices(ColorMatrix, ColorMatrix) Sets the color-adjustment matrix and the grayscale-adjustment matrix for the default category. SetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag) Sets the color-adjustment matrix and the grayscale-adjustment matrix for the default category. SetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag, ColorAdjustType) Sets the color-adjustment matrix and the grayscale-adjustment matrix for a specified category. SetColorMatrix(ColorMatrix)Sets the color-adjustment matrix for the default category. SetColorMatrix(ColorMatrix, ColorMatrixFlag) Sets the color-adjustment matrix for the default category. SetColorMatrix(ColorMatrix, ColorMatrixFlag, ColorAdjustType) Sets the color-adjustment matrix for a specified category. SetGamma(Single)Sets the gamma value for the default category. SetGamma(Single, ColorAdjustType) Sets the gamma value for a specified category.

22 ImageAttributes NameDescription SetNoOp() Turns off color adjustment for the default category. You can call theClearNoOpmethod to reinstate the color-adjustment settings that were in place before the call to the SetNoOpmethod.ClearNoOpSetNoOp SetNoOp(ColorAdjustType) Turns off color adjustment for a specified category. You can call theClearNoOpmethod to reinstate the color-adjustment settings that were in place before the call to the SetNoOpmethod.ClearNoOpSetNoOp SetOutputChannel(ColorChannelFlag ) Sets the CMYK (cyan-magenta-yellow-black) output channel for the default category. SetOutputChannel(ColorChannelFlag, ColorAdjustType) Sets the CMYK (cyan-magenta-yellow-black) output channel for a specified category. SetOutputChannelColorProfile(String ) Sets the output channel color-profile file for the default category. SetOutputChannelColorProfile(String, ColorAdjustType) Sets the output channel color-profile file for a specified category. SetRemapTable(ColorMap[])Sets the color-remap table for the default category. SetRemapTable(ColorMap[], ColorAdjustType) Sets the color-remap table for a specified category. SetThreshold(Single)Sets the threshold (transparency range) for the default category. SetThreshold(Single, ColorAdjustType) Sets the threshold (transparency range) for a specified category. SetWrapMode(WrapMode) Sets the wrap mode that is used to decide how to tile a texture across a shape, or at shape boundaries. A texture is tiled across a shape to fill it in when the texture is smaller than the shape it is filling. SetWrapMode(WrapMode, Color) Sets the wrap mode and color used to decide how to tile a texture across a shape, or at shape boundaries. A texture is tiled across a shape to fill it in when the texture is smaller than the shape it is filling. SetWrapMode(WrapMode, Color, Boolean) Sets the wrap mode and color used to decide how to tile a texture across a shape, or at shape boundaries. A texture is tiled across a shape to fill it in when the texture is smaller than the shape it is filling.

23 DrawImage & ImageAttributes Image image = new Bitmap("InputColor.bmp"); ImageAttributes imageAttributes = new ImageAttributes(); int width = image.Width; int height = image.Height; float[][] colorMatrixElements = { new float[] {2, 0, 0, 0, 0}, // red scaling factor of 2 new float[] {0, 1, 0, 0, 0}, // green scaling factor of 1 new float[] {0, 0, 1, 0, 0}, // blue scaling factor of 1 new float[] {0, 0, 0, 1, 0}, // alpha scaling factor of 1 new float[] {.2f,.2f,.2f, 0, 1}}; // three translations of 0.2 ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements); imageAttributes.SetColorMatrix( colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); g.DrawImage(image, 10, 10); g.DrawImage( image, new Rectangle(120, 10, width, height), 0, 0, width, height, GraphicsUnit.Pixel, imageAttributes);


Download ppt "Računarska grafika GDI+ (Graphics Device Interface Plus)"

Similar presentations


Ads by Google