Click here to Skip to main content
15,914,452 members
Home / Discussions / C#
   

C#

 
GeneralBinding Data to a Datagridview Pin
Dstor9-Sep-04 9:18
Dstor9-Sep-04 9:18 
GeneralInterprocess function calls Pin
Arun Bhalla9-Sep-04 8:20
Arun Bhalla9-Sep-04 8:20 
Generalcheckedlistbox control in a winform Pin
abhishk2001@yahoo.com9-Sep-04 7:28
abhishk2001@yahoo.com9-Sep-04 7:28 
QuestionSave string... HowTo? Pin
QzRz9-Sep-04 7:02
QzRz9-Sep-04 7:02 
AnswerRe: Save string... HowTo? Pin
Nick Parker9-Sep-04 7:46
protectorNick Parker9-Sep-04 7:46 
GeneralRe: Save string... HowTo? Pin
QzRz9-Sep-04 8:09
QzRz9-Sep-04 8:09 
AnswerRe: Save string... HowTo? Pin
Stefan Troschuetz9-Sep-04 7:50
Stefan Troschuetz9-Sep-04 7:50 
Generalmerging halftoned images Pin
Member 7466529-Sep-04 6:40
Member 7466529-Sep-04 6:40 
Hello,

I would like to simulate CMYK printing by drawing four halftoned images on the screen, one after the other, as a printing press would do, i.e. print cyan, then magenta, then yellow and finally black. Now, If I use:

g.DrawImage(cyanImage, 0,0);
g.DrawImage(magentaImage, 0,0);
g.DrawImage(yellowImage, 0,0);
g.DrawImage(blackImage, 0,0);

the white pixels of an image will paint over the previous colors. If I use alpha blending, colors will be merged, but they unfortunately become fainter by the aplha factor.

What I would like to see happening is to draw one image on the graphics or canvas such that only these pixels of that image will be painted which are above a certain threshold, i.e. not blank, or the areas where in a real printing role the paint would be.

Alternatively, I could combine these images, like professional tools can do. Then it would be sufficient to draw the combined image.

How could I achieve that in C# using the Graphics/Imaging classes?

What I started doing is the following code. Thanks for any hints.

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.Data;
using System.Windows.Forms;

namespace MergedImages
{
public class MergedImage : System.Windows.Forms.UserControl
{
private System.ComponentModel.Container components = null;
private System.Drawing.Image cyanImage;
private System.Drawing.Image magentaImage;
private System.Drawing.Image yellowImage;
private System.Drawing.Image blackImage;


public MergedImage()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Component Designer generated code
private void InitializeComponent()
{
cyanImage = Image.FromFile(@"c:\tmp\cyan.bmp" );
magentaImage = Image.FromFile(@"c:\tmp\magenta.bmp");
yellowImage = Image.FromFile(@"c:\tmp\yellow.bmp" );
blackImage = Image.FromFile(@"c:\tmp\black.bmp" );
//
// MergedImage
//
this.BackColor = System.Drawing.Color.White;
this.Name = "MergedImage";
this.Size = new System.Drawing.Size(620, 620);

}
#endregion

protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.Clear(this.BackColor);

float[][] ptsArray ={
new float[] {1, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, 0.25f, 0},
new float[] {0, 0, 0, 0, 1}};
ColorMatrix clrMatrix = new ColorMatrix(ptsArray);
ImageAttributes imgAttributes = new ImageAttributes();
imgAttributes.SetColorMatrix(clrMatrix,
ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);

g.DrawImage(cyanImage, 10,10);
g.DrawImage(magentaImage, 110,10);
g.DrawImage(yellowImage, 210,10);
g.DrawImage(blackImage, 310,10);

g.DrawImage(cyanImage, 0,0);
g.DrawImage(magentaImage, 0,0);
g.DrawImage(yellowImage, 0,0);
g.DrawImage(blackImage, 0,0);

g.DrawImage(cyanImage,
new Rectangle(300,300, cyanImage.Width, cyanImage.Height),
0, 0, cyanImage.Width, cyanImage.Height,
GraphicsUnit.Pixel, imgAttributes);
g.DrawImage(magentaImage,
new Rectangle(300,300, magentaImage.Width, magentaImage.Height),
0, 0, magentaImage.Width, magentaImage.Height,
GraphicsUnit.Pixel, imgAttributes);
g.DrawImage(yellowImage,
new Rectangle(300,300, yellowImage.Width, yellowImage.Height),
0, 0, yellowImage.Width, yellowImage.Height,
GraphicsUnit.Pixel, imgAttributes);
g.DrawImage(blackImage,
new Rectangle(300,300, blackImage.Width, blackImage.Height),
0, 0, blackImage.Width, blackImage.Height,
GraphicsUnit.Pixel, imgAttributes);
}
}
}

GeneralMerge halftone images Pin
Anonymous9-Sep-04 6:21
Anonymous9-Sep-04 6:21 
QuestionIntegrating A Custom Editor Within VS IDE 2003... Possible? Pin
Nailbite9-Sep-04 5:25
Nailbite9-Sep-04 5:25 
GeneralMaster-Child DataGrid Filter Issue: Winform DataGrid Pin
Looney Tunezez9-Sep-04 4:50
Looney Tunezez9-Sep-04 4:50 
GeneralClearing the clipboard Pin
Garrick Hensberg9-Sep-04 4:36
Garrick Hensberg9-Sep-04 4:36 
GeneralRe: Clearing the clipboard Pin
Dave Kreskowiak9-Sep-04 5:44
mveDave Kreskowiak9-Sep-04 5:44 
GeneralTo minimize all opened windows Pin
Chauhan9-Sep-04 2:59
Chauhan9-Sep-04 2:59 
GeneralRe: To minimize all opened windows Pin
Nick Parker9-Sep-04 3:46
protectorNick Parker9-Sep-04 3:46 
Generalnumeric updown column in datagrid Pin
9-Sep-04 1:32
suss9-Sep-04 1:32 
GeneralAPI Calls Pin
Member 368639-Sep-04 1:25
Member 368639-Sep-04 1:25 
GeneralRe: API Calls Pin
Nick Parker9-Sep-04 3:58
protectorNick Parker9-Sep-04 3:58 
QuestionHow to use COM DLL in ASP.NET using C# Pin
zahid_ash9-Sep-04 0:39
zahid_ash9-Sep-04 0:39 
AnswerRe: How to use COM DLL in ASP.NET using C# Pin
Dave Kreskowiak9-Sep-04 5:32
mveDave Kreskowiak9-Sep-04 5:32 
GeneralA simple FileSystemWatcher Question ( How to see if file has copied) Pin
Capriono9-Sep-04 0:29
Capriono9-Sep-04 0:29 
GeneralRe: A simple FileSystemWatcher Question ( How to see if file has copied) Pin
Pradeep Shamarao9-Sep-04 3:11
Pradeep Shamarao9-Sep-04 3:11 
GeneralRe: A simple FileSystemWatcher Question ( How to see if file has copied) Pin
mav.northwind9-Sep-04 5:30
mav.northwind9-Sep-04 5:30 
GeneralDelay Pin
erina5488-Sep-04 22:53
erina5488-Sep-04 22:53 
GeneralRe: Delay Pin
sreejith ss nair8-Sep-04 22:56
sreejith ss nair8-Sep-04 22:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.