What's New

User Manual
1. Introduction
2. Thumbnails
3. Using AspUpload
4. Image Processing
5. Drawing & Typing
6. Picture-in-Picture
7. Metadata
8. Miscellaneous
9. GIF Output

Object Reference
Live Demos

Download & Buy

Other Products
Contact Us

Search this site:

Chapter 9: GIF Output Chapter 7: Metadata Extraction Chapter 8: Miscellaneous Features

8.1 CMYK-to-RGB Conversion
8.2 Image Resolution
8.3 Access to Individual Pixels
8.4 Progressive JPEGs
8.5 Brightness, Constrast and Saturation

8.1 CMYK-to-RGB Conversion

Most digital images we deal with are RGB. That is, the color of each pixel in those images is represented by three components -- red, green and blue (RGB), which correspond to the three cathode emitters in the monitor. In images intended for print, on the other hand, the pixels are represented by four colorants -- cyan, magenta, yellow and black (CMYK), which correspond to the four primary ink colors used in printers.

JPEG and TIFF images created in the CMYK color space cannot be viewed over the Web, Internet Explorer shows them as the "red X" icon. To enable CMYK image viewing, AspJpeg 1.5+ offers a new method, ToRGB, which converts CMYK images to the RGB color space.

Converting CMYK to RGB is not a trivial task and there is no single "correct" way to do it. To achieve reasonably good color reproduction, the ToRGB method performs a series of complex non-linear color transformations based on profiles, the standard color space definitions established by the International Color Consortium (ICC). For more information on ICC profiles, visit www.color.org.

CMYK-to-RGB conversion is a very CPU-intensive procedure. It is therefore important to call the ToRGB method after the image size has been reduced:

VB Script:
' Fast
Jpeg.Width = Jpeg.OriginalWidth / 2
Jpeg.Height = Jpeg.OriginalHeight / 2

' Slow
Jpeg.Width = Jpeg.OriginalWidth / 2
Jpeg.Height = Jpeg.OriginalHeight / 2

Jpeg.ToRGB only has effect if the current image is in CMYK or grayscale color spaces. If the image is already an RGB one, the method does nothing.

To see the CMYK-to-RGB functionality in action, run Live Demo #3.

8.2 Image Resolution

Image resolution is information embedded in an image specifying the print quality of this image should it be printed. Resolution is usually expressed in dots-per-inch (DPI). 72 DPI or 96 DPI images are known as low-resolution and 300 DPI and above as high-resolution.

Most image viewers, such as your Web browser, ignore the resolution information and simply use the pixel size of the image for screen rendering. Advanced image management and print systems such as Photoshop do use image resolution to compute the correct size of the image on paper when printed. Note that resolution information is not always embedded in an image. If that is the case, it should be assumed to be 72 DPI.

AspJpeg 1.5+ enables you to retrieve the resolution information from images, and also set new resolution. The properties OriginalResolutionX and OriginalResolutionY return the current DPI resolution along the horizontal and vertical coordinates, respectively. If these properties each return 1, it means the resolution is not embedded in the image. Quite possibly, however, this information is still present, but in the form of EXIF tags (read more about EXIF in the previous chapter.)

The following code snippet attempts to retrieve the X and Y resolutions from an arbitrary image:

path = "c:\path\image.jpg"

XRes = jpeg.OriginalResolutionX
YRes = jpeg.OriginalResolutionY

If XRes = 1 and YRes = 1 Then
' Look among EXIF tags
  Set Info = jpeg.OpenInfo(path)

  If Info("XResolution") <> "" Then
    XRes = Info("XResolution")
    YRes = Info("YResolution")
    Response.Write "Resolution info not found."
  End if
End If

To set new resolution, use the properties ResolutionX and ResolutionY, as follows:

Jpeg.ResolutionX = 72
Jpeg.ResolutionY = 72
Jpeg.Save path

8.3 Access to Individual Pixels

Starting with Version 1.5, AspJpeg is capable of setting and retrieving individual pixels of an image via the default Pixels property of the main ASPJpeg object. This property accepts two arguments (X, Y) which specify the location of the pixel to be set or retrieved. The property returns, or is assigned, an array of color components for this pixel. In case of an RGB image, the array must contain exactly three elements. The number of color components in an image can be retrieved via the property Jpeg.OriginalComponents.

Since Pixels is the default property, it can be omitted. The following code snippets demonstrate this technique:

VB Script:
' Set pixel (20, 50) to green
jpeg.Pixels(20, 50) = array(0, 255, 0)

' Retrieve pixel (30, 40). The word "Pixels" is optional
arr = jpeg(30, 40)
for i = 0 to jpeg.OriginalComponents - 1
  Response.Write arr(i) & " "

'Set pixel (20, 30) to orange
Object [] arr = new Object[3];
arr[0] = (Object)255;
arr[1] = (Object)128;
arr[2] = (Object)0;

objJpeg[20, 30] = arr;

' Retrieve pixel (15, 20)
Array arr2 = (Array)objJpeg[15, 20];
for( int i = 0; i < objJpeg.OriginalComponents; i++ )
  Response.Write( arr2.GetValue(i).ToString() + " " );

8.4 Progressive JPEGs

A progressive JPEG is an equivalent of "interlaced" GIF. Such an image can be displayed in full size even if only partially downloaded, although in lower quality. As more and more data arrives, the image progressively becomes sharper and sharper until the entire image has been downloaded. This feature makes progressive images attractive in a slow-connection environment.

With AspJpeg 1.5+, you can create progressive JPEGs by setting the Progressive property to True:

Jpeg.Progressive = True
Jpeg.Save path

Note that Netscape is currently the only major browser supporting gradual rendering of progressive JPEGs, other browsers just display the entire image at once after it has been fully downloaded.

8.5 Brightness, Contrast and Saturation

Starting with version 1.7, AspJpeg is capable of adjusting the brightness, contrast and saturation of an image using the multi-purpose Adjust method. This method expects two parameters: the operation code and the operation-specific value.

To adjust brightness, 1 is passed as the first parameter and a brightness value in the range [-1, 1] is passed as the 2nd parameter. A value greater than 0 increases brightness, a value less than 0 decreases it:

jpeg.Adjust 1, 0.05

To adjust contrast, 2 is passed as the first parameter and a contrast value in the range [0.001, 5] is passed as the 2nd parameter. A value greater than 1 increases constrast, a value less than 1 decreases it:

jpeg.Adjust 2, 1.2

To adjust saturation, 3 is passed as the first parameter and a saturation value in the range [-1, 1] is passed as the 2nd parameter. A value greater than 0 increases saturation, a value less than 0 decreases it:

jpeg.Adjust 3, -0.2

The Adjust method is only applicable to RGB images.

Chapter 9: GIF Output Chapter 7: Metadata Extraction 

Copyright © 1998 - 2007 Persits Software, Inc.
All Rights Reserved.
AspJpeg is a trademark of Persits Software, Inc.