Showing posts with label CSharp. Show all posts
Showing posts with label CSharp. Show all posts

Saturday, November 22, 2008

Tile Fill Addin

I just finished up a second Paint.NET addin. The first is available here.














This addin fills the current image with a tiled version of another image.Just copy an image to the clipboard, create a new image that is larger than the first, and run the addin.
For example, start with something like this:
And the tiled version could look like this:





It can be useful for creating textures, or patterned backgrounds.

Downloads:

Friday, November 21, 2008

Radius Fill Corners Update

I have gotten some feedback from the Paint.NET addin that I recently created. Most of the feedback has been positive, except for strange results occuring when a large radius is selected. This issue is related to how the code determines how to color each pixel for the image. Basically my calculations fall apart if the radius greater than a quarter of the height or width of the image. I knew this would be an issue, but decided not to restrict the radius size because I did not want to limit users who were working with large images.

I now realize that it is better to restrict the radius, but base it on the current image's size. This way you should always get the desired results.

Here are updated links:
source code
addin dll

Sunday, November 9, 2008

New Paint.NET Effect Addin for rounding the corners of an image

After searching through existing Paint.NET effect plugins, I did not find exactly what I was looking for (quick and easy way to round off the corners of an image, like the one below), so I decided to create one.


























With the help of Sepcot's template and tips from BoltBait’s site, the process was not too difficult, and it was an interesting learning experience. Most of the code is pretty similar to other examples, except that I decided to use some WPF libraries to help make the math calculations easier. The source code is available here, or you can just download the DLL for your personal use. Due to the WPF use, the .NET framework 3.5 is required for the effect addin to function. If you need help deploying the addin, there are tips here. Once you have got the addin working, just select the entire image and run the effect with the desired settings.

Thursday, July 3, 2008

Troubleshooting Datasets

Lately I have been working a lot with strongly typed datasets, and have found that they can be difficult to troubleshoot when faced with the dreaded error message:

"Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."

After some research, I found a blog post by Roy Osherove where he had faced the same problem. In this post, Sanjay lists the following suggestion:

"Essentially, when I see the message above, I check the HasErrors property for each DataTable in the data set and then invoke the GetErrors method on the tables reporting errors. The GetErrors returns a collection of DataRows and you can invoke the .RowError property on the each of the error-stricken rows to find out just exactly what the problem is... "

His suggestion has made troubleshooting much easier. Just disable constraints on the dataset, and then write code to catch the problem once contraints are enabled. Here is a snippet of the version that I came up with:

try


{


    this.EnforceConstraints = true;


}


catch


{


     foreach(DataTable dt in this.Tables)


    {


        if (dt.HasErrors)


        {


            DataRow[] rowErrors = dt.GetErrors();


 


            for (int i = 0; i < rowErrors.GetLength(0); i++)


            {


                System.Windows.Forms.MessageBox.Show(dt.TableName + ": " + rowErrors[i].RowError.ToString());  


            }


        }


    }


}

Tuesday, June 3, 2008

Formatting my MP3 player

My current MP3 player is a SanDisk Sansa c250. It’s not a fancy as some of the more expensive units, but overall it’s very nice unit for the price. Recently I needed to transfer 1GB of data between to pc’s and didn’t have a flash drive handy; so I just copied the data to my Sansa and used it for the transfer. This seemed like a good idea at the time, but when I tried to delete the data from the MP3 player, I was faced the the error message “Folder cannot be deleted because it is protected.”. After some experimenting, it looks like the Sansa will not let you delete a folder if it contains data. This wouldn’t be a big deal, except that the data I had transferred contained hundreds of folders. There was no way I was going to dig through all of these folders to delete the files. Being a developer, I decided to automate the process and write a .NET application that would traverse the folder structure of the unit, and delete all of the files.

I threw together a quick app, tested it on some other folders, and was off to the races (or so I thought). I attempted to select the folder on the device (using the .NET FolderBrowserDialog), and Windows Vista gave me the error message “The folder cannot be used”.

I had never tried to access a portable device programmatically, so I wasn’t sure what the cause might be. Google’ing didn’t help. Next, I did some debugging to find out what the referenced file path was so I could just hard code it. The path turned out to be in Temporary Internet Files. I’m not quite sure what this means, but obviously Windows doesn’t treat this device like a normal drive.

It was time to take a step back and think about what I was trying to accomplish. I wanted everything deleted from the device, except for my music. But, all my MP3’s are backed up on several devices. I took a quick look at the options on the Sansa, and it turns on there was a format device. This quickly wiped out everything, and then I simply copied the music back to the device.

I guess sometimes, it pays to approach a problem from a different perspective.

Monday, May 5, 2008

C# Code snippets

While making the transition from a VB.NET developer to C#, I noticed that there are far fewer out of the box code snippets for C# than VB.NET in Visual Studio 2005. A quick Google search for C# snippets revealed that Microsoft offers a separate download for C# snippets which matches all of the ones available for VB.NET. This was great news, but unfortunately the download link appears to be broken at the moment. I'm sure this will be fixed soon but in case it's not, Jeff Atwood has posted the snippets and helpful install info here.