Jump to content

How do i load an image?


Anaco

Recommended Posts

Hello,

I'm trying to build a plug-in that will delete (turn alpha to 0) Any Similarity/Differences between two images.

At the moment the problem I'm having is an error in the bitmap loading.

Hidden Content:
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Drawing;

using System.Text.RegularExpressions;

using System.Windows.Forms;

using PaintDotNet.Effects;

using PaintDotNet;

using System.IO;

namespace EffectsPluginTemplate1

{

public class EffectPluginConfigDialog : PaintDotNet.Effects.EffectConfigDialog

{

private Button buttonOK;

private OpenFileDialog openFileDialog1;

private ComboBox comboBox1;

private Button ButtonBrowse;

private Button buttonCancel;

public EffectPluginConfigDialog()

{

InitializeComponent();

}

protected override void InitialInitToken()

{

theEffectToken = new EffectPluginConfigToken();

}

protected override void InitTokenFromDialog()

{

// ((EffectPluginConfigToken)EffectToken).variable = dialogVariable;

}

protected override void InitDialogFromToken(EffectConfigToken effectToken)

{

// EffectPluginConfigToken token = (EffectPluginConfigToken)effectToken;

// dialogVariable = token.variable;

}

private void InitializeComponent()

{

this.buttonCancel = new System.Windows.Forms.Button();

this.buttonOK = new System.Windows.Forms.Button();

this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();

this.comboBox1 = new System.Windows.Forms.ComboBox();

this.ButtonBrowse = new System.Windows.Forms.Button();

this.SuspendLayout();

//

// buttonCancel

//

this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));

this.buttonCancel.Location = new System.Drawing.Point(324, 249);

this.buttonCancel.Name = "buttonCancel";

this.buttonCancel.Size = new System.Drawing.Size(75, 23);

this.buttonCancel.TabIndex = 1;

this.buttonCancel.Text = "Cancel";

this.buttonCancel.UseVisualStyleBackColor = true;

this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);

//

// buttonOK

//

this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));

this.buttonOK.Location = new System.Drawing.Point(243, 249);

this.buttonOK.Name = "buttonOK";

this.buttonOK.Size = new System.Drawing.Size(75, 23);

this.buttonOK.TabIndex = 2;

this.buttonOK.Text = "OK";

this.buttonOK.UseVisualStyleBackColor = true;

this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);

//

// openFileDialog1

//

this.openFileDialog1.FileName = "openFileDialog1";

this.openFileDialog1.FileOk += new System.ComponentModel.CancelEventHandler(this.openFileDialog1_FileOk);

//

// comboBox1

//

this.comboBox1.FormattingEnabled = true;

this.comboBox1.Location = new System.Drawing.Point(12, 12);

this.comboBox1.Name = "comboBox1";

this.comboBox1.Size = new System.Drawing.Size(306, 21);

this.comboBox1.TabIndex = 3;

//

// ButtonBrowse

//

this.ButtonBrowse.Location = new System.Drawing.Point(324, 12);

this.ButtonBrowse.Name = "ButtonBrowse";

this.ButtonBrowse.Size = new System.Drawing.Size(75, 21);

this.ButtonBrowse.TabIndex = 4;

this.ButtonBrowse.Text = "Browse";

this.ButtonBrowse.UseVisualStyleBackColor = true;

this.ButtonBrowse.Click += new System.EventHandler(this.button1_Click);

//

// EffectPluginConfigDialog

//

this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);

this.ClientSize = new System.Drawing.Size(411, 284);

this.Controls.Add(this.ButtonBrowse);

this.Controls.Add(this.comboBox1);

this.Controls.Add(this.buttonOK);

this.Controls.Add(this.buttonCancel);

this.Location = new System.Drawing.Point(0, 0);

this.Name = "EffectPluginConfigDialog";

this.Controls.SetChildIndex(this.buttonCancel, 0);

this.Controls.SetChildIndex(this.buttonOK, 0);

this.Controls.SetChildIndex(this.comboBox1, 0);

this.Controls.SetChildIndex(this.ButtonBrowse, 0);

this.ResumeLayout(false);

}

private void buttonOK_Click(object sender, EventArgs e)

{

FinishTokenUpdate();

DialogResult = DialogResult.OK;

this.Close();

}

private void buttonCancel_Click(object sender, EventArgs e)

{

this.Close();

}

private void button1_Click(object sender, EventArgs e)

{

Stream myStream = null;

OpenFileDialog openFileDialog1 = new OpenFileDialog();

openFileDialog1.InitialDirectory = "c:\\";

openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";

openFileDialog1.FilterIndex = 2;

openFileDialog1.RestoreDirectory = true;

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

try

{

if ((myStream = openFileDialog1.OpenFile()) != null)

{

using (myStream)

{

Bitmap loadedBmp = new Bitmap(Image.FromFile(myStream));

Surface imgSurface = Surface.FromBitmap(loadedBmp);

}

}

}

catch (Exception ex)

{

MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);

}

}

}

private void openFileDialog1_FileOk(object sender, CancelEventArgs e)

{

}

}

}

Here are the errors:

"Error 1 The best overloaded method match for 'System.Drawing.Image.FromFile(string)' has some invalid arguments."

"Error 2 Argument '1': cannot convert from 'System.IO.Stream' to 'string'"

"Error 3 'PaintDotNet.Surface' does not contain a definition for 'FromBitmap'"

BTW I'm a noob to Plug-in coding but I've had a fair amount of experience in coding using a language which syntax highly similar to C#'s syntax (Yes i learned GML :P ).

If anyone has a plug-in coding guide for Microsoft Visual C# 2008 express edition please don't hesitate to tell me :D.

Link to comment
Share on other sites

Let's say I Take photo of a brick wall and the put a ball in-front take another picture and I want to Cut the ball out and use it on another image without lots of time being consumed using all the other tools.

Theoretically, you could use the difference blend mode on one of the layers (the one above), although there would probably be too many variables to worry about.

BTW I'm a noob to Plug-in coding but I've had a fair amount of experience in coding using a language which syntax if very highly similar to C#.

BoltBait has written a set of tutorials on using CodeLab to write effects.

also do you know of a list that contains the variables used in paint.net?

Search the web for reflector.

KaHuc.png
Link to comment
Share on other sites

Thank you Simon Brown.

I searched reflector and I've downloaded it.

and also I didn't notice what difference did well now i do

well it looks like there's no point in me trying to make a plug-in for that

Thanks Again

edit:

actually there is point in the plug in because the difference blend darkens a cyan color the more simulator color it is.

here's the logic it would have i think

for (int y = rect.Top; y < rect.Bottom; y++)

{

for (int x = rect.Left; x < rect.Right; x++)

{

if pixel at x,y on image's RGB does not equal pixel at x,y on other image's RGB

{

add pixel at x y to selection

}

}

}

tell me if you see any flaws

Link to comment
Share on other sites

Please remember to post in the correct section of the forum.

Moved to Plugin Developer's Central

Are you trying to write an effect plugin for Paint.NET, or just writing C# code?

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

actually there is point in the plug in because the difference blend darkens a cyan color the more simulator color it is.

I missed a few steps:

1. Flatten the layers run threshold, dragging the slider until the ball is one colour and the wall is another.

2. Use alpha mask (you may need to check invert colours).

KaHuc.png
Link to comment
Share on other sites

@ Simon Brown

you do know this is a plug-in, right?

because I'm not asking how would i do this through already existing functions.

Sorry If i just sounded a bit rude just now but I wasn't trying to

Ok I've got a few questions:


  • .How do you add to a selection through code?
    .How do you load an image through code?
    .How do you accesses the loaded image through code?

Link to comment
Share on other sites

you do know this is a plug-in, right?

because I'm not asking how would i do this through already existing functions.

I know, but I assumed you were writing a plugin to accomplish this.

How do you add to a selection through code?

Unless you're talking about changing its contents, you can't.

How do you load an image through code?

How do you accesses the loaded image through code?

Note: Not tested.

Bitmap loadedBmp = new Bitmap(Image.FromFile("C:\\foo\\bar.png"));
Surface imgSurface = Surface.FromBitmap(loadedBmp);

ColorBgra onePixel = imgSurface[2, 2];

imgSurface.Dispose();
loadedBmp.Dispose();

KaHuc.png
Link to comment
Share on other sites

Simon if you could (or anyone else) show a Code Lab script Example which allows the user to pick the file location? that would help me a lot (To Google!)

Link to comment
Share on other sites

It sounds like you should really be writing a separate application for this. Paint.NET isn't meant to be an all-in-one image analysis and processing development platform.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

but this is actually a very simple plug-in because this is all it does:

loads_image

for(x=Rect.Left; x{
for(y=Rect.Top; y{
if red at x,y on image does not equal red at x,y on loaded image
{
alpha at x,y on image equals 100%
}

if blue at x,y on image does not equal blue at x,y on loaded image
{
alpha at x,y on image equals 100%
}

if green at x,y on image does not equal green at x,y on loaded image
{
alpha at x,y on image equals 100%
}
}
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...