Click here to Skip to main content
15,891,785 members
Home / Discussions / C#
   

C#

 
GeneralStore image in DataTable Pin
lsconyer12-Feb-08 4:43
lsconyer12-Feb-08 4:43 
GeneralRe: Store image in DataTable Pin
Gareth H12-Feb-08 4:57
Gareth H12-Feb-08 4:57 
QuestionHow to run C# Code without Visual Studio? Pin
gunner_uk200012-Feb-08 4:15
gunner_uk200012-Feb-08 4:15 
AnswerRe: How to run C# Code without Visual Studio? Pin
Judah Gabriel Himango12-Feb-08 4:23
sponsorJudah Gabriel Himango12-Feb-08 4:23 
AnswerRe: How to run C# Code without Visual Studio? Pin
gunner_uk200012-Feb-08 4:25
gunner_uk200012-Feb-08 4:25 
GeneralProblem with alpha channel Pin
lupus8112-Feb-08 4:10
lupus8112-Feb-08 4:10 
GeneralRe: Problem with alpha channel Pin
KaptinKrunch12-Feb-08 6:35
KaptinKrunch12-Feb-08 6:35 
GeneralRe: Problem with alpha channel Pin
lupus8114-Feb-08 1:17
lupus8114-Feb-08 1:17 
Thanx, I had a look at the code, and at some more documentation..and tried that on a small test project, to load a bitmap on a pictureBox, and modify its alpha channel as much as a trackBar in the same form is scrolled, from 0 to 1.
The problem is that: once I have create the Graphics object, loaded with my image, and modified it, I can't reconvert it as a Bitmap object, in such a way to be able to set it as the Image property of the PictureBox of the Form.
Notice this is just a small piece of code to try the matter: actually, in my application, I have to load the bipmap as the BackgroundImage property of a Button, but I don't think this changes a lot..
Thanx for any extra help, sorry for my English..
Here down is listed the code I can't fix:

public partial class Form1 : Form
{
private string sourceFileName;
private string destFileName, proposedDestFile;
private Bitmap image, newImage;
private int modifiedImagesCounter;
ColorMatrix colorMatrix;
ImageAttributes imageAtt;
Graphics g;

public Form1()
{
InitializeComponent();
float[][] matrixItems = {
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, 1, 0},
new float[] {0, 0, 0, 0, 1}};
colorMatrix = new ColorMatrix(matrixItems);

imageAtt = new ImageAttributes();
imageAtt.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
}

private void loadImageButton_Click(object sender, EventArgs e)
{
openFileDialog.ShowDialog(Parent);
sourceFileName = openFileDialog.FileName;
image = new Bitmap(sourceFileName);
Console.WriteLine("The file to modify is: " + sourceFileName);
//IndexedToARGB_Converter conv = new IndexedToARGB_Converter(sourceFile);
//Bitmap modifiedImage = conv.getNewImage();
pictureBox.Image = image;
}

private void saveImageButton_Click(object sender, EventArgs e)
{
proposedDestFile = DestFileName();
saveFileDialog.FileName = proposedDestFile;
saveFileDialog.ShowDialog(Parent);
destFileName = saveFileDialog.FileName;
Console.WriteLine("The modified file will be saved to: " + destFileName);
newImage.Save(destFileName);
}

private string DestFileName()
{
modifiedImagesCounter++;
StringBuilder strbld = new StringBuilder();
strbld.Append(sourceFileName, 0, sourceFileName.Length - 4);
strbld.Append(modifiedImagesCounter.ToString());
strbld.Append(".GIF");
return strbld.ToString();
}

private void trackBar_Scroll(object sender, EventArgs e)
{
g = pictureBox.CreateGraphics();
//Graphics g = Graphics.FromImage(image);
TrackBar trackBar = (TrackBar)sender;
float f = (float)(trackBar.Maximum - trackBar.Value) / (float)(trackBar.Maximum - trackBar.Minimum);
colorMatrix[3, 3] = f;

int iWidth = image.Width;
int iHeight = image.Height;

Rectangle rect = new Rectangle(pictureBox.Location.X, pictureBox.Location.Y, iWidth, iHeight);

g.DrawImage(
image,
rect, // destination rectangle
0.0f, // source rectangle x
0.0f, // source rectangle y
iWidth, // source rectangle width
iHeight, // source rectangle height
GraphicsUnit.Pixel,
imageAtt);

this.Update();
}
}
Generalcalling Cobol stored procedure from .NET Pin
jchigg200012-Feb-08 4:07
jchigg200012-Feb-08 4:07 
GeneralTo execute code on clicking the link from emil Pin
Rups_12312-Feb-08 3:44
Rups_12312-Feb-08 3:44 
GeneralRe: To execute code on clicking the link from emil Pin
CKnig12-Feb-08 3:58
CKnig12-Feb-08 3:58 
GeneralMessage Closed Pin
12-Feb-08 4:10
Rups_12312-Feb-08 4:10 
GeneralRe: To execute code on clicking the link from emil Pin
Expert Coming12-Feb-08 5:17
Expert Coming12-Feb-08 5:17 
GeneralRe: To execute code on clicking the link from emil Pin
Justin Perez12-Feb-08 4:28
Justin Perez12-Feb-08 4:28 
GeneralRe: To execute code on clicking the link from emil Pin
Ravenet12-Feb-08 14:55
Ravenet12-Feb-08 14:55 
GeneralActiveDirectory LogonHours to boolean array ??? [modified] Pin
Paw Jershauge12-Feb-08 3:37
Paw Jershauge12-Feb-08 3:37 
GeneralRe: ActiveDirectory LogonHours to boolean array ??? Pin
Paw Jershauge12-Feb-08 4:54
Paw Jershauge12-Feb-08 4:54 
QuestionSearching word/Phrase in Excel/PDF/Doc file in a ASP.Net Application Pin
Member 422892512-Feb-08 2:48
Member 422892512-Feb-08 2:48 
GeneralRe: Searching word/Phrase in Excel/PDF/Doc file in a ASP.Net Application Pin
Paddy Boyd12-Feb-08 4:00
Paddy Boyd12-Feb-08 4:00 
QuestionSqlExceptions Pin
Harvey Saayman12-Feb-08 0:50
Harvey Saayman12-Feb-08 0:50 
GeneralRe: SqlExceptions Pin
Martin#12-Feb-08 1:10
Martin#12-Feb-08 1:10 
GeneralRe: SqlExceptions Pin
Harvey Saayman12-Feb-08 2:28
Harvey Saayman12-Feb-08 2:28 
GeneralRe: SqlExceptions Pin
Martin#12-Feb-08 2:31
Martin#12-Feb-08 2:31 
QuestionRe: SqlExceptions Pin
Vasudevan Deepak Kumar12-Feb-08 1:12
Vasudevan Deepak Kumar12-Feb-08 1:12 
GeneralRe: SqlExceptions Pin
Expert Coming12-Feb-08 5:20
Expert Coming12-Feb-08 5:20 

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.