Wednesday, 22 January 2014

Save and Retrieve images into database using c#.net and vb.net

Public Class Form2
Dim conn As New Data.SqlClient.SqlConnection
Dim cmd As New SqlClient.SqlCommand
Browse Button
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
OpenFileDialog1.Filter = "Image File(*.jpg)|*.jpg"
OpenFileDialog1.ShowDialog()
PictureBox1.Load(OpenFileDialog1.FileName)
End Sub
Save Buttonèhow to write image into database
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fs As New System.IO.FileStream(OpenFileDialog1.FileName, System.IO.FileMode.Open)
Dim img(fs.Length) As Byte
fs.Read(img, 0, Convert.ToInt32(fs.Length))
fs.Close()
'--------- main doding
Dim str As String
str = "insert into imageList (imageID,imageData) values(@id,@data)"
Dim id As New SqlClient.SqlParameter("@id", SqlDbType.Int)
id.Value = Convert.ToInt16(TextBox1.Text)
cmd.Parameters.Add(id)
Dim data As New SqlClient.SqlParameter("@data", SqlDbType.Image)
data.Value = img
cmd.Parameters.Add(data)
'-------------
cmd.CommandText = str
conn.Open()
Dim n As Integer = 0
n = cmd.ExecuteNonQuery()
MsgBox(n.ToString + " Record Inserted")
‘C# coding
'System.IO.FileStream fs = new System.IO.FileStream(openFileDialog1.FileName, System.IO.FileMode.Open);
' Byte[] img = new Byte[fs.Length];
' fs.Read(img, 0, Convert.ToInt32(fs.Length));
' fs.Close();
' //---------
' String str;
' str = "insert into imageList (imageID,imageData) values(@id,@data)";
' SqlParameter id = new SqlParameter("@id", SqlDbType.Int);
' id.Value = Convert.ToInt16(textBox3.Text);
' cmd.Parameters.Add(id);
' SqlParameter data = new SqlParameter("@data", SqlDbType.Image);
' data.Value = img;
' cmd.Parameters.Add(data);
' //----------
' cmd.CommandText = str;
' conn.Open();
' int n = 0;
' n = cmd.ExecuteNonQuery();
' MessageBox.Show(Convert.ToString(n) + " Records Inserted");


















End Sub
Form Load
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conn.ConnectionString = "Data Source=dreampc2\sqlexpress;Initial Catalog=student;Integrated Security=True;Pooling=False"
cmd.CommandType = CommandType.Text
cmd.Connection = conn
End Sub
Search Buttonè How to read image from database
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim img() As Byte
Dim str As String
Dim dr As SqlClient.SqlDataReader
str = "select * from imageList where imageID=" + TextBox1.Text
cmd.CommandText = str
conn.Open()
dr = cmd.ExecuteReader
dr.Read()
img = dr.GetValue(1)
Dim ImageStream As New System.IO.MemoryStream(img)
PictureBox1.Image = Image.FromStream(ImageStream)
conn.Close()
‘C# Coding
'byte[] img = null; // The BLOB byte[] buffer to be filled by GetBytes.
'string str;
'SqlDataReader dr;
'str = "select * from imageList";
'cmd.CommandText = str;
'conn.Open();
'dr=cmd.ExecuteReader();
'dr.Read();
'textBox3.Text = Convert.ToString(dr.GetDecimal(0));
'img = (byte[])dr.GetValue(1);
'System.IO.MemoryStream ImageStream = new System.IO.MemoryStream(img);
'pictureBox1.Image = Image.FromStream(ImageStream);
'conn.Close();












End Sub
End Class














3. Basic parameter rollout(for standard material)

Color Controls
Color controls set the colors for different color components. You can set the color by clicking the color swatch to display the Color Selector.
Note: The Metal shader does not have a Specular component, because it generates the specular color automatically. The Multi-Layer shader can have two different Specular color components, so for this material the Specular color swatches are found in the Specular Highlights group. The Strauss shader has only a single color component, which corresponds to Diffuse.
clip_image001
1. Specular color
2. Diffuse color
3. Ambient color

Copying and Locking Color Components

For convenience in changing color components, the Material Editor lets you copy one color component to another by dragging, and to lock two color components together with the lock buttons to the left of the Ambient and Diffuse, and Diffuse and Specular color swatches.
When you drag and drop a color swatch, the Copy or Swap Colors dialog asks if you want to copy the color or swap the two colors.
In general, materials with two identical color components do not look realistic, and except for materials that are close to solid black, you should avoid using copied or locked color components in materials you use in a scene. Color copying and locking are best used as conveniences when you design a new basic material.

Procedures

To change a color component:
  1. Click the color swatch next to the color component you want to change.
The Material Editor displays a Color Selector.
  1. Use the Color Selector to change the values of the color component.
As you change color values, the color component also changes in the sample slot.

To copy one color component to another:

  1. Drag the color swatch of the color you want to copy to the color swatch of the other color component.
A Copy or Swap Colors dialog is displayed.
  1. Click Copy to replace the second color swatch with the color you dragged. Click Swap to swap the two color components.

To lock two color components:

  1. Click the clip_image002“wire” button between Ambient and Diffuse or between Diffuse and Specular.
The Material Editor displays an alert that asks whether you want to lock the two color components.
  1. Click Yes.
The color above replaces the color below. In other words, Ambient replaces Diffuse and Diffuse replaces Specular.
If two colors are locked, and you lock the other two, all three component colors are replaced by the active color.
While two colors are locked, adjustments to one color component affect the other as well.

To unlock two color components:

  • Click the clip_image002[1]“wire” button to turn it off.
The two colors remain the same until you change either or both.

Interface

clip_image003
Ambient
Controls the ambient color. The ambient color is the color in shadow (indirect light).
clip_image004The lock button to the right of the Ambient and Diffuse settings, when on (the default), forces them to use the same map.
Usually it makes sense to use the same map for the ambient and diffuse components. To use different maps, turn off the lock button. A map shortcut button for Ambient appears.
Turn off the clip_image004[1]lock button and click the map button to assign an Ambient Color map. This button is a shortcut: You can also assign an Ambient Color map on the Maps rollout.
Diffuse
Controls the diffuse color. The diffuse color is the color in direct light.
Click the map button to assign a Diffuse Color map. This button is a shortcut: You can also assign a Diffuse Color map on the Maps rollout.
Specular
Controls the specular color. The specular color is the color of the highlight on a shiny object. You can control the size and shape of highlights in the Specular Highlights group, described below.
Click the map button to assign a Specular Color map. This button is a shortcut: You can also assign a Specular Color map on the Maps rollout.

Self-Illumination Setting

These controls make the material self illuminated. Self-illumination creates the illusion of incandescence by replacing shadows on the surface with the diffuse color. As you increase self-illumination, the self-illumination color takes over from the ambient color. At a setting of 100, the material shows no shaded areas, although it can show specular highlights.
The self-illumination color appears in viewports.
Note: The Strauss shader does not have self-illumination.
There are two ways to specify self-illumination. You can turn on the checkbox and use a self-illumination color, or turn off the checkbox and use a monochrome spinner, which is comparable to using a gray scale self-illumination color.
Self-illuminated materials do not show shadows cast onto them, and they are unaffected by the lights in the scene. The brightness (Value in the HSV color description) remains the same regardless of the scene's lighting.
To make a visible light source in a scene, you can combine a geometric object with a light object, and give the geometric object a self-illuminating surface. For example, you could create a lofted light bulb shape, assign it a self-illuminating white or yellowish material, and place an omni light in the same location.
To make a material both self-illuminating and transparent, use the Additive transparency type in combination with self-illumination.
clip_image005
A self-illuminated object using a percentage value and a color

Procedures

To make a material self-illuminating:
  1. Click the color swatch in the Self-Illumination group.
  2. In the Color Selector, choose a color for self-illumination.
  3. Use the color's Value parameter (in the HSV model) to increase or decrease the amount of self-illumination.
You can also set self-illumination with a monochrome spinner. To do so, turn off the self-illumination checkbox and adjust the spinner.
The self-illumination color is mixed with the material's diffuse color. The closer to black the self-illumination color, the more diffuse color is used.
As self-illumination increases, the sample object appears flatter and more luminous.

Interface

clip_image006
Color checkbox
When on, the material uses a special self-illumination color. When off, the material uses the diffuse color for self-illumination, and displays a spinner to control the self-illumination amount. Default=off.
Click the map button to assign a Self-Illumination map. This button is a shortcut: You can also assign a Self-Illumination map on the Maps rollout.
Color swatch
When Color is on, the color swatch shows the self-illumination color. To change the color, click the swatch and then use the Color Selector. Adjusting the Value (in the color's HSV description) adjusts the amount of self-illumination. The greater the Value, the more the self-illumination color dominates both the ambient and diffuse color components.
Mono spinner
When Color is off, the diffuse component is used as the self-illumination color, and this spinner lets you adjust the amount of self-illumination. At 0, there is no self-illumination. At 100, the diffuse color takes over from the ambient color.

Opacity

Opacity controls whether a material is opaque, transparent, or translucent. (A more physically accurate way to generate translucency is to use the Translucent shader.)
clip_image007
Controlling opacity using the Opacity setting (left) or an opacity map (right).

Procedures

To reduce a material's opacity:
  • Change Opacity to a value less than 100%.
The material becomes more transparent. A fully transparent object (0% Opacity) is nearly invisible except for the light it reflects (the specular highlights).
To preview transparency in the sample slots, view the sample object against a background. Click the checkered Background button to the right of the sample slots.
Transparent materials render more realistically when you turn on 2-Sided in the material's Shader Basic Parameters.

Interface

clip_image008
Opacity
Sets the opacity/transparency of the material as a percentage. The effect is best previewed against a pattern background in the sample slot. You can control opacity falloff in the Extended Parameters.
Click the map button to assign an Opacity map. This button is a shortcut: You can also assign an Opacity map on the Maps rollout.

Diffuse Level

Diffuse Level controls the brightness of the material's diffuse component.
clip_image009
Adjusting diffuse level
Note: The Blinn, Metal, Phong, and Strauss shaders do not have Diffuse Level control.

Procedures

To adjust the diffuse level:
  • Change the value of Diffuse Level.
The material grows lighter or darker. Lowering the Diffuse Level dims the material's diffuse color without affecting the specular highlight. Diffuse Level is intended primarily so you can create a Diffuse Level map that makes portions of the material very dark.

Interface

clip_image010
Diffuse Level
Increasing this value increases diffuse brightness, and decreasing it reduces diffuse brightness without affecting the specular highlight. You can increase the diffuse level over and above the diffuse color's Value (in its HSV description). This parameter can range from 0 to 400. Default=100.
Click the map button to assign a Diffuse Level map. This button is a shortcut: You can also assign a Diffuse Level map on the Maps rollout.

Roughness

Roughness controls the rate at which the diffuse component blends into the ambient component.
Note: The Roughness parameter is available only with the Oren-Nayar-Blinn and Multi-Level shaders, and with the Arch & Design material (mental ray).
clip_image011
Increasing the blending area between ambient and diffuse with Roughness

Procedures

To adjust the roughness:
  • Change the value of Roughness.
Increasing roughness makes the material have a flatter, more matte appearance.

Interface

clip_image012
Roughness
As you increase this value, the matte appearance of the material increases. It also grows darker and appears more flat. At 0, the roughness is the same as it is with Blinn shading. Range (Oren-Nayar-Blinn and Multi-Layer)=0 to 100. Range (Arch & Design material)=0.0 to 1.0. Default=0.
Click the button to assign a Diffuse Roughness map. This button is a shortcut: You can also assign a Diffuse Roughness map on the Maps rollout.

Translucency Setting

The translucency controls are available for the Translucent shader.
Warning: Do not use shadow maps with the translucent shader. Shadow maps result in artifacts at the edge of translucent objects.

Procedures

To make a material translucent:
  • Increase the HSV Value (V) of the Translucent Color.
As the Value increases, the material becomes more translucent. The Hue of the Translucent Color tints the light that is scattered within the material.
Translucent materials render more realistically when you turn on 2-Sided in the material's Shader Basic Parameters. The translucent effect does not appear in shaded viewports.
clip_image017 clip_image015
The projection screen uses translucency

Interface

clip_image018
Translucent Clr (Color)
Specifies a translucency color. This is the color of light that is scattered within the material. It does not need to be the same as the filter color, which is light transmitted by the material. The two color values are multiplied. Click the color swatch to change the Translucent Color.
Click the button to assign a map to the Translucent Color component. This button is a shortcut: You can also assign a Translucent Color map on the Maps rollout.
Filter Color
Specifies a filter color that is multiplied by the translucent color. The filter, or transmissive color, is the color transmitted through transparent or semi-transparent materials such as glass. Click the color swatch to change the filter color.
Click the map button to assign a Filter Color map. This button is a shortcut: You can also assign a Filter Color map on the Maps rollout.
You can use the filter color with volumetric lighting to create effects such as colored light through a stained-glass window. Ray-traced shadows cast by transparent objects are tinted with the filter color.
Opacity
Sets the opacity/transparency of the material as a percentage. The effect is best previewed against a pattern background in the sample slot.
Click the map button to assign an Opacity map. This button is a shortcut: You can also assign an Opacity map on the Maps rollout.

Next >> 4.Specular Highlight Controls

2. Standard Material & Material Guidelines in 3DS MAX

Standard Material

The Standard material type provides a fairly straightforward way to model surfaces. In the real world, the appearance of a surface depends on how it reflects light. In 3ds Max, a standard material simulates a surface's reflective properties. If you don't use maps, a standard material gives an object a single, uniform color.

Standard Color Components

A surface of a "single" color usually reflects many colors. Standard materials typically use a four-color model to simulate this. (This can vary, depending on which shader you use.) The four colors are known as the material’s color components.
  • Ambient color appears where the surface is lit by ambient light alone, where the surface is in shadow.
  • Diffuse color appears where light falls directly on the surface, where the surface is in “good” lighting.
This component is called "diffuse" because light striking it is reflected in various directions. Highlights, on the other hand, are reflections of light sources.
  • Specular color appears in highlights. Shiny surfaces usually have specular highlights, where the viewing angle is equal to the angle of incidence.
A surface can also have glancing highlights, where the angle of incidence is high, relative to the observer or camera (that is, the light ray is nearly parallel to the surface). Glancing highlights are characteristic of metallic surfaces.
Note: Some shaders generate the specular color procedurally, rather than letting you choose it.
Some surfaces are completely reflective, or nearly so. These reflect their environment as well as the light sources that illuminate them. To model such surfaces, you need to assign a Reflection map or use ray tracing.
  • Filter color is the color transmitted by light shining through the object.
The Filter color component isn't visible unless the material's Opacity is less than 100 percent.

Note: The Raytrace material uses a different, six-color model to simulate surfaces. Several components are similar to those in the Standard Material, but they behave differently in Raytrace.

The three color components blend at the edges of their regions. Between ambient and diffuse, the blending is calculated by the shader. Between diffuse and specular, you set the amount of blending by using the Standard material's highlight controls.

When we describe an object's color in conversation, usually we mean its diffuse color. The choice of an ambient color depends on the kind of lighting. For moderate indoor lighting, it can be a darker shade of the diffuse color, but for bright indoor lighting and for daylight, it should be the complement of the primary (key) light source. The specular color should be either the same color as the key light source, or a high-value, low-saturation version of the diffuse color.

Warning: When you change the shading type of a material, you lose the settings (including map assignments) for any parameters that the new shader does not support. If you want to experiment with different shaders for a material with the same general parameters, make a copy of the material before you change its shading type. That way, you can still use the original material if the new shader doesn't give you the effect you want.

Other Standard Material Components

A standard material's specular color appears in highlights. You can control the size and shape of the highlight. A polished surface has a small and strong highlight. A matte surface has a large, weak highlight, or no highlight at all.

Standard materials also have controls for making the object appear transparent, and for making it self-illuminating so that it appears to glow.

Along with the material's color components, components also refers to the parameters that control highlights, transparency, self-illumination, and so on.

Shader Basic Parameters Rollout

The Shader Basic Parameters rollout lets you choose the type of shader to use with a Standard material. Some additional controls affect how the material appears.

Procedures:
To set a material's shading type:
  1. On the Shader Basic Parameters rollout, open the shader drop-down list.
  2. Click the name of the shader type to use for the active material.
To use Wire mode:
  • On the Shader Basic Parameters rollout, turn on Wire.
The material is now shaded as a wireframe mesh. The wire portions of the geometry do not change; color components, shininess, and so on, remain the same.

For a wireframe material, turn on the 2-Sided option as well.You have two choices for how wireframe materials are rendered. The controls for tuning wireframe shading are on the Extended Parameters rollout.

If you choose Pixels, the thickness of the wires maintains the same apparent thickness regardless of the scale of the geometry or how near or far the object is positioned. In other words, pixel wires have a constant display size as if the wires were traced over an image.If you choose Units, the wires behave as if they were modeled in the geometry. They appear thinner at a distance and thicker at close range. Scaling a wireframe object does scale wire width.

Interface
[shader drop-down list]
Chooses a shader. The material's Basic Parameters rollout changes to show the controls for the shader you choose.

These are the basic material shaders:
·         Anisotropic: For surfaces with elliptical, "anisotropic" highlights
·         Blinn (The default): For rounder, softer highlights than Phong shading
·         Metal: For metallic surfaces
·         Multi-Layer: For surfaces with more complex highlights than Anisotropic
·         Oren-Nayar-Blinn: For matte surfaces such as fabric or terra cotta
·         Phong: For surfaces with strong, circular highlights
·         Strauss: For metallic and nonmetallic surfaces
·         Translucent: Lets you specify translucency, where light is scattered as it passes through the material
Wire
Renders the material in wireframe mode. You can set the size of the wire in Extended Parameters.
2-Sided
Makes the material 2-sided. Applies the material to both sides of selected faces.
Face Map
Applies the material to the faces of the geometry. If the material is a mapped material, it requires no mapping coordinates. The map is automatically applied to each facet of the object.
Faceted

Renders each face of a surface as if it were flat.

Choosing Colors for Realism

Indoor and Outdoor Lighting

Whether a scene is indoors or outdoors affects your choice of material colors, just as it affects the way you set up lights. Full sunlight is bright and unidirectional. Most indoor lighting is less intense and more even (that is, multidirectional) than daylight. However, some special indoor lighting (and nighttime outdoor lighting), as for the stage, also features intense, directional light.

Direct sunlight has a yellow tint. Materials for objects to appear in daylight should have a specular color of a pale, unsaturated yellow (for example, RGB values of 240, 240, 188). The ambient color should be the complement of the specular: a deep, dark purple with a hint of the diffuse color.

Materials for objects to appear under normal interior lighting should have a specular color that is close to white. (Our perception compensates for the yellow or green tint that is often present in artificial light.) The ambient color can often have the same hue as the diffuse color, but with a darker value.

Materials for objects to appear under spotlights should follow the general guidelines for daylight materials. The specular color should match the spotlight's color, and the ambient color should be a very dark value of the spotlight color's complementary hue, mixed with a bit of the material's diffuse color.

Representing Natural Materials

Outdoor scene with natural materials

Most natural materials have a matte surface with little or no specular color. For natural materials such as these, use the following guidelines:
  • Ambient color: The ambient color depends on whether the scene is indoors or outdoors, as previously described.
  • Diffuse color: Choose a color found in nature. It is best to use the observed color of the object itself, or a similar object.
  • Specular color: Make the specular color the same hue as the diffuse, but with a higher value and a lower saturation.
  • Glossiness: Set the Glossiness to a low value.
Some foliage, bird feathers, fish scales, and so on, are shiny. For materials such as these, set the Glossiness to higher values. You might also want to change the specular color so it's closer to the lighting color than the surface's diffuse color.

Water is reflective, and is best modeled by a color component in combination with a reflection map or a water map.While metal is a natural material, its special visual characteristics are most apparent when it has been polished.

 

Representing Manufactured Materials

Manufactured materials often have a synthetic color rather than an "earth tone." Also, many manufactured materials, such as plastics and porcelain glazes, are very shiny. For manufactured materials, use the following guidelines:
  • Ambient color: The ambient color depends on whether the scene is indoors or outdoors, as previously described.
  • Diffuse color: Although the diffuse color doesn't have to be an "earth tone," as with natural materials you should used the observed color of the object or a similar object.
  • Specular color: Make the specular color close to white, or to the color of the light source. White is especially characteristic of plastic materials.
  • Glossiness: Set the glossiness to a high value.

Representing Metallic Objects

image

Metallic cup and ice cream scoop


Polished metal has a characteristic "glancing" highlight that appears where the light is at a high angle of incidence. To generate this effect, Metal shading uses the Cook/Torrance illumination model.

For metallic materials, you can use the Metal shading type. This disables the specular color and highlight controls. The Metal shader calculates its own specular color, which can vary between the diffuse color and the color of the light.

In the diffuse region of a metal material, the ambient component is greater than it is for other kinds of materials.

The Anisotropic, Multi-Layer, and Strauss shaders give you further options for modeling polished metal.
If the metallic object is the focus of the scene, you can improve realism by using a Blend material to combine metallic shading with a reflection map.

Tip: When you preview metallic surfaces, it is useful to turn on a backlight. This displays the metal's glancing highlight. The Backlight button is to the right of the sample slots.