Računarska grafika

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

description

Računarska grafika. GDI+ ( Graphics Device Interface Plus). Bitmaps. A bitmap is an array of bits that specify the color of each pixel in a rectangular array of pixels. Bitmaps. - PowerPoint PPT Presentation

Transcript of Računarska grafika

Page 1: Računarska grafika

Računarska grafikaGDI+(Graphics Device Interface Plus)

Page 2: Računarska grafika

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

1 2^1 = 22 2^2 = 44 2^4 = 168 2^8 = 25616 2^16 = 65,53624 2^24 = 16,777,216

Page 3: Računarska grafika

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.

Page 4: Računarska grafika

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)

Page 5: Računarska grafika

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.

Page 6: Računarska grafika

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.

Page 7: Računarska grafika

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.

Page 8: Računarska grafika

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.

Page 9: Računarska grafika

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.

Page 10: Računarska grafika

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.

Page 11: Računarska grafika

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).

Page 12: Računarska grafika

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.

Page 13: Računarska grafika

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.

Page 14: Računarska grafika

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. 

• dest▫ Array of three Point structures that define a parallelogram. 

• 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. 

Page 15: Računarska grafika

DrawImageg.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);

Page 16: Računarska grafika

ImageName DescriptionFlags Gets attribute flags for the pixel data of this Image.FrameDimensionsList Gets an array of GUIDs that represent the dimensions of frames within

thisImage.Height Gets the height, in pixels, of this Image.HorizontalResolution Gets the horizontal resolution, in pixels per inch, of thisImage.

Palette Gets or sets the color palette used for thisImage.PhysicalDimension Gets the width and height of this image.PixelFormat Gets the pixel format for this Image.PropertyIdList Gets IDs of the property items stored in this Image.PropertyItems Gets all the property items (pieces of metadata) stored in this Image.RawFormat Gets the file format of this Image.Size Gets the width and height, in pixels, of this image.Tag Gets or sets an object that provides additional data about the image.VerticalResolution Gets the vertical resolution, in pixels per inch, of thisImage.Width Gets the width, in pixels, of this Image.

Page 17: Računarska grafika

ImageName DescriptionClone Creates 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.GetBounds Gets the bounds of the image in the specified unit.GetEncoderParameterList Returns information about the parameters supported by the specified image encoder.GetFrameCount Returns the number of frames of the specified dimension.GetPixelFormatSize Returns the color depth, in number of bits per pixel, of the specified pixel format.

GetPropertyItem Gets the specified property item from this Image.GetThumbnailImage Returns a thumbnail for this Image.IsAlphaPixelFormat Returns a value that indicates whether the pixel format for this Image contains alpha information.

IsCanonicalPixelFormat Returns a value that indicates whether the pixel format is 32 bits per pixel.IsExtendedPixelFormat Returns a value that indicates whether the pixel format is 64 bits per pixel.RemovePropertyItem Removes the specified property item from thisImage.RotateFlip Rotates, 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.

SelectActiveFrame Selects the frame specified by the dimension and index.SetPropertyItem Stores a property item (piece of metadata) in thisImage.

Page 18: Računarska grafika

Imageusing (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"); }

}}

}

Page 19: Računarska grafika

ThumbnailImage & IconImage 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);

Page 20: Računarska grafika

ImageAttributes Name DescriptionClearBrushRemapTable Clears 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(ColorAdjustType)

Clears the output channel color profile setting for a specified category.

Page 21: Računarska grafika

ImageAttributesName DescriptionClearRemapTable() Clears the color-remap table for the default category.ClearRemapTable(ColorAdjustType)

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.Clone Creates an exact copy of thisImageAttributesobject.GetAdjustedPalette Adjusts the colors in a palette according to the adjustment settings of a specified category.SetBrushRemapTable Sets 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.

Page 22: Računarska grafika

ImageAttributesName DescriptionSetNoOp() 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.

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.

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.

Page 23: Računarska grafika

DrawImage & ImageAttributesImage 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);