|
Thank you for your answer, i would transform pdf to word and word to pdf using myprogram in C#, thank you verry mutch.
|
|
|
|
|
I am having difficulty in keeping the alpha channels in my images when I open them into a c# pictureBox.
Having spent a couple of days searching forums and things I gather that a pictureBox doesn't actually keep the alpha channel and that I need to store the info in memory and work on the data there, pre-multiplying the alpha channels and doing any other calculations I need to with the raw data and then display the result when all is done.
Unfortunately as a total noob I have no idea of how to do this.
My code so far:
Bitmap bitmap = new Bitmap(ImagePath + PBox1);
Bitmap layer = new Bitmap(ImagePath + PBox2);
for (int x = 0; x < layer.Width; x++)
{
for (int y = 0; y < layer.Height; y++)
{
Color BitmapPixel = bitmap.GetPixel(x, y);
Color LayerPixel = layer.GetPixel(x, y);
int r = (LayerPixel.A * (BitmapPixel.R - LayerPixel.R)) / 256 + LayerPixel.R;
int g = (LayerPixel.A * (BitmapPixel.G - LayerPixel.G)) / 256 + LayerPixel.G;
int b = (LayerPixel.A * (BitmapPixel.B - LayerPixel.B)) / 256 + LayerPixel.B;
Color newColor = Color.FromArgb(r, g, b);
bitmap.SetPixel(x, y, newColor);
}
progressBar1.PerformStep();
Update();
}
pictureBox3.Image = bitmap;
Basically what I want to do is take two images, both with an alpha layer in them. Overlay the second one onto the first one, using its alpha layer for transparency, and finally save out a new 32bpp image from the result.
Any help would be much appreciated.
Thankyou.
|
|
|
|
|
Doof369 wrote: I am having difficulty in keeping the alpha channels in my images when I open them into a c# pictureBox.
What did you expect the PictureBox to do?? It's only a "noobie" control used to quick'n'dirty show a single image. It doens't do any magical transformations on the image it's showing.
Doof369 wrote: I gather that a pictureBox doesn't actually keep the alpha channel
Yes it does, becuase it doesn't manipulate the Image object you passed to it in any way. Just because it doesn't show the results of the alpha channel, doesn't mean that it complete tossed it.
Doof369 wrote: I need to store the info in memory and work on the data there, pre-multiplying the alpha channels and doing any other calculations I need to with the raw data and then display the result when all is done.
That's exactly what you have to do. Check out the excellent series of articles Christian Grauss put together on image filters, here[^].
|
|
|
|
|
Doof369 wrote: Basically what I want to do is take two images, both with an alpha layer in them. Overlay the second one onto the first one, using its alpha layer for transparency, and finally save out a new 32bpp image from the result.
Just draw one image onto the other. Use Graphics.FromImage to create a Graphics object for one of the images, then use the DrawImage method to draw the other image on it.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks for the replies.
ok. So this is what I have now, which actually works ))
public static void ArgbOverlay(Bitmap bm2, Bitmap bm1, out Bitmap bm3)
{
int[,] a1 = new int[bm1.Width, bm1.Height];
int[,] a2 = new int[bm2.Width, bm2.Height];
int[,] a3 = new int[bm2.Width, bm2.Height];
int[,] r1 = new int[bm1.Width, bm1.Height];
int[,] r2 = new int[bm2.Width, bm2.Height];
int[,] r3 = new int[bm2.Width, bm2.Height];
int[,] g1 = new int[bm1.Width, bm1.Height];
int[,] g2 = new int[bm2.Width, bm2.Height];
int[,] g3 = new int[bm2.Width, bm2.Height];
int[,] b1 = new int[bm1.Width, bm1.Height];
int[,] b2 = new int[bm2.Width, bm2.Height];
int[,] b3 = new int[bm2.Width, bm2.Height];
Rectangle rect1 = new Rectangle(0, 0, bm1.Width, bm1.Height);
BitmapData bd1 = bm1.LockBits(rect1, ImageLockMode.ReadWrite, bm1.PixelFormat);
int bytes1 = bd1.Stride * bd1.Height;
byte[] argbValues1 = new byte[bytes1];
IntPtr ptr1 = bd1.Scan0;
Marshal.Copy(ptr1, argbValues1, 0, bytes1);
Rectangle rect2 = new Rectangle(0, 0, bm2.Width, bm2.Height);
BitmapData bd2 = bm2.LockBits(rect2, ImageLockMode.ReadWrite, bm2.PixelFormat);
int bytes2 = bd2.Stride * bd2.Height;
byte[] argbValues2 = new byte[bytes2];
IntPtr ptr2 = bd2.Scan0;
Marshal.Copy(ptr2, argbValues2, 0, bytes2);
bm3 = new Bitmap(bm1.Width, bm1.Height, PixelFormat.Format32bppArgb);
Rectangle rect3 = new Rectangle(0, 0, bm3.Width, bm3.Height);
BitmapData bd3 = bm3.LockBits(rect3, ImageLockMode.ReadWrite, bm3.PixelFormat);
int bytes3 = bd3.Stride * bd3.Height;
byte[] argbValues3 = new byte[bytes3];
for (int x = 0; x < bm1.Width; x++)
{
for (int y = 0; y < bm1.Height; y++)
{
int BitPos1 = (x * 4) + (y * bd1.Stride);
b1[x, y] = (int)argbValues1[BitPos1];
g1[x, y] = (int)argbValues1[BitPos1 + 1];
r1[x, y] = (int)argbValues1[BitPos1 + 2];
a1[x, y] = (int)argbValues1[BitPos1 + 3];
b2[x, y] = (int)argbValues2[BitPos1];
g2[x, y] = (int)argbValues2[BitPos1 + 1];
r2[x, y] = (int)argbValues2[BitPos1 + 2];
a2[x, y] = (int)argbValues2[BitPos1 + 3];
r3[x, y] = (r2[x, y] * a2[x, y]) / 256 + ((r1[x, y] * (256 - a2[x, y])) / 256);
g3[x, y] = (g2[x, y] * a2[x, y]) / 256 + ((g1[x, y] * (256 - a2[x, y])) / 256);
b3[x, y] = (b2[x, y] * a2[x, y]) / 256 + ((b1[x, y] * (256 - a2[x, y])) / 256);
if (a1[x, y] < a2[x, y])
{
a3[x, y] = a2[x, y];
}
else
{
a3[x, y] = a1[x, y];
}
argbValues3[BitPos1] = (byte)b3[x, y];
argbValues3[BitPos1 + 1] = (byte)g3[x, y];
argbValues3[BitPos1 + 2] = (byte)r3[x, y];
argbValues3[BitPos1 + 3] = (byte)a3[x, y];
}
}
IntPtr ptr3 = bd3.Scan0;
Marshal.Copy(argbValues3, 0, ptr3, bytes3);
bm3.UnlockBits(bd3);
return;
}
Was wondering if anyone can see any glaring ways to optimise this further to make it a less cumbersome piece of code and also to make it run faster if poss.
It is fine as it is, but less is more.
|
|
|
|
|
Who I Send data from textbox to datagridview in a diferent form?
Plesea give me the code.
Thanks.
|
|
|
|
|
Can you explain little bit more what exactly you mean in "different form". Do you mean different format or different "FORM"? If you give more details somebody will be able to help you out.
|
|
|
|
|
you need a public propety or method in the from with the datagridview thagt will take textbox value
then you need a reference to the instance of the form, possibly a static instance somewhere
then you just do
StaticInstance.ProcessFunction(textbox1.Text);
If only MySelf.Visible was more than just a getter...
A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
|
|
|
|
|
When you want to send the data, raise a custom event.
In the other form subscribe to that event and react accordingly.
Don't be tempted (as previously suggested) to send forms or textboxes as parameters (to constructors or methods) or static properties to other forms. It's bad design. You will end up coupling forms too closely together which is non OOP and will lead to maintanence nightmares as your application grows.
Basic outline below:
using System;
using System.Windows.Forms;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Shown += new EventHandler(Form1_Shown);
}
void Form1_Shown(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.TextUpdated += new EventHandler<TextUpdatedEventArgs>(form2_TextUpdated);
form2.Show();
}
void form2_TextUpdated(object sender, TextUpdatedEventArgs e)
{
Console.WriteLine(e.Text);
}
}
using System;
using System.Windows.Forms;
public partial class Form2 : Form
{
public event EventHandler<TextUpdatedEventArgs> TextUpdated;
public Form2()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
OnTextUpdated(new TextUpdatedEventArgs(textBox1.Text));
}
protected virtual void OnTextUpdated(TextUpdatedEventArgs e)
{
EventHandler<TextUpdatedEventArgs> eh = TextUpdated;
if (eh != null)
eh(this, e);
}
}
using System;
public class TextUpdatedEventArgs : EventArgs
{
private string m_Text;
public TextUpdatedEventArgs(string text)
{
m_Text = text;
}
public string Text
{
get { return m_Text; }
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
You should try using delegates and events.
It will work great, and you can even catch the event on another form too.
|
|
|
|
|
Hi out there,
Has anybody an idea how i can do the following with c# and visual studio 2008:
I want to recognize when the user is right clicking a desktop icon.
If the right clicked desktop icon has a special feature (name or tag or something else)
i want to open my own custom context menu.
Is it possible to override the desktop context menu ?
Or is there something like an global "object clicked event"
thanx in advance
Peter
modified on Wednesday, February 11, 2009 10:07 AM
|
|
|
|
|
Yeah, totally. I remember using the Registry (regedit) to add a custom menu a while back but for the life of me I cannot remember how I did it. I'm going through my files looking for the snippet, if I find it I'll post it.
j.t.
|
|
|
|
|
Hi,
thanx for your rapid answer.
But i want to do this programmatically.
The context menu should be created dynamically depending on
the type of clicked icon.
ciao
Peter
|
|
|
|
|
There are several articles at codeproject that show how to make your own context menu items you need a simple search.
|
|
|
|
|
Hi,
Perhaps you did not understand what i want:
Yes i found ways to add items to the default desktop context menu !
I dont want to add items, i want to replace or override the desktop context menu in
special context.
For example:
If the right clicked desktop icon represents a directory i want to rise a custom
context menu with all the entries in this directory. The selected
context menu item should then be started.
Peter
|
|
|
|
|
Hi All,
I was wondering if it would at all be possible to create my own very small and simple programming language using C# Express Edition? And how one might go about doing so? I'd appreciate any help I can get on this. Thanks in advance
j.t.
j.t.
|
|
|
|
|
Basically you will need to learn assembly language i.e. how an executable is created
Then you would need to parse you language and produce your assembly code based on the parsed values
Quite a simple theory really :P
If only MySelf.Visible was more than just a getter...
A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
|
|
|
|
|
You could always take a look at developing a DLR language (Dynamic Language Runtime). Take a look here[^] for a marketing type overview, and here[^] for more detail.
|
|
|
|
|
What you will need to do is create a program that will take in source code and emit object code.
The source code will be written in your language; the object code be targeted at some machine. So it will either be machine code, aimed at a particular CPU, or byte code that runs on some virtual machine (e.g. the CLR in .Net or Java in a JVM).
Effectively this means you have to write a compiler (or interpreter) in C#. This is not a trivial task.
You might try looking at this book:
Compilers: Principles, Techniques, and Tools
Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman
Addison-Wesley Pub Co
ISBN: 0201100886
Regards
David R
|
|
|
|
|
Or it could be an interpreted language and maybe not general-purpose.
|
|
|
|
|
Possible, yes. I've written a very simple interpreted scripting language for a very specific purpose; automating a telnet session.
Do you have a particular need? Or just a curiosity?
See also this[^] article.
|
|
|
|
|
Well, it's just out of plain curiosity and wanting to learn that's all.
foreach( inch on Jason )
{
Girlfriend.IsHappier();
}
|
|
|
|
|
I took a few minutes and made a programming language. Create a console application (named GuffaProgrammingLanguage of course), and put this in the Main method:
static void Main(string[] args) {
foreach (string line in File.ReadAllLines(args[0]+".gpl")) {
switch (line.Substring(0,Math.Min(line.Length,4))) {
case "out ": Console.WriteLine(line.Substring(4)); break;
case "time": Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); break;
case "end.": return;
default: Console.WriteLine("Syntax error."); return;
}
}
}
Create a text file in the bin folder named test.gpl with this content:
out Hello
out World!
time
end.
Open a console window and go to the bin folder, start the program with GuffaProgrammingLanguage test and you get an amazing result like this:
Hello
World!
2009-02-11 18:48:49
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I have created 2 forms namely form1.cs and form2.cs....
I want to move from one form to another at the run time with a click of a button...The following code gives me an error...
Error 1 The type or namespace name 'Form2' could not be found (are you missing a using directive or an assembly reference?)
Is there any other method of doing it..
public class Form1:System.Windows.Forms.Form
{
public Form2 i;
}
private void button1_click(object sender,System.EventArgs e)
{
i=new Form2();
i.ShowDialog();
}
|
|
|
|
|
|