Posted by (JavaScript must be enabled to view this email address) on Fri 23 Jan 2009

Cropping images sounds easy, you get an image, you tell it what size you want it, issue the bitmap.Crop() command and it crops.

No it doesn’t. It crops and gives you a little freebie…random lines on your images.

So how do you resolve it? well its as simple as 3 easy steps (wrapped in some GDI+ black magic).

  1. Create your final bitmap at the correct size.
  2. Create your source bitmap from the source image.
  3. Create a temporary rectangle with dimensions 2px bigger than the final one.

Step 1 is nice and simple - create your bitmap as you would want it to appear (say 150px x 150px). Nothing difficult there.
Bitmap bmPhoto = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb);

Step 2 is also nice and easy
System.Drawing.Image imgPhoto = CreateImageFromUrl(sourcePath);

Step 3 Crop your image - heres the science bit…
grPhoto.DrawImage(imgPhoto,
new Rectangle(-2, -2, destWidth + 2, destHeight + 2),
new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
GraphicsUnit.Pixel);

Why does it work? imgPhoto is the image you are using. The first new rectangle is declared as being 1px larger than the imgPhoto in all dimensions and starts 1px to the left and 1px further up than your cropped image, and the second rectangle is the rectangle the same size as your source so that GDI knows how to scale the images.

The code doesn’t so much as remove them from your crop as leaves them in but makes them outside the bounds of your final image, by doing so, when you do save the image GDI+ ignores them and they aren’t displayed.

I’ll try and get a full working example on here for now but that should give you enough information to remove any weird lines you are seeing on your cropped images.



Posted by (JavaScript must be enabled to view this email address) on Wed 21 Jan 2009

Chances are if you have developed a web part in the past, it needed some user input. And if it needed user input then it needs validation.

When you develop webparts you are unable to do use the designer (thanks Microsoft) so you have to be a real coder and declare, instantiate and add the controls entirely programmatically. Including your validation controls. Ok, you’ve done that. Why doesn’t your validation work?

First, you MUST (and I cant stress that enough) instantiate the validators in your overridden OnInit method, not in the CreateChildControls() method. Secondly, set up a validation group so that you can control what the validators are validating (you dont want to validate the whole page) and lastly, you need to ensure that the EnableClientScript property is enabled.

        regexpval.ControlToValidate = this.txtEmail.ID;
        regexpval.ValidationExpression = @”\w+([-+.’]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*”;
        regexpval.ErrorMessage = “Please Enter a valid email address.”;
        regexpval.Display = ValidatorDisplay.Dynamic;
        regexpval.EnableClientScript = true;
        regexpval.ValidationGroup = validationGroup;

 

If you’ve been diligent then your code will compile, deploy and even let you place it on the page, but for some weird reason it still doesn’t work as you think it should. AAAAARGH!

Its a small and very simple fix, the text box you are validating might be instantiated but it doesn’t have an ID, D’oh!

All it takes is adding a line like this BEFORE you set up the validators:

 

txtEmail.ID = “txtEmail”;



Posted by (JavaScript must be enabled to view this email address) on Fri 19 Dec 2008

You’ve spent the past four days writing the best code in the world to interface with MOSS 2007 and its publishing features. You run it and Argghhhhh! Whats going on, all your publishing data is not there!

Chances are you have done something like this to get the properties:
VB


dim startDate as DateTime = Convert.ToDateTime(item.Properties(“PublishingStartDate”));

C#


DateTime startDate = Convert.ToDateTime(item.Properties[“PublishingStartDate”]);

 

Instead, try accessing the properties like this:
VB


dim startDate as DateTime = Convert.ToDateTime(item(“PublishingStartDate”));

 

C#


DateTime startDate = Convert.ToDateTime(item[“PublishingStartDate”]);

Now get back to that killer code and get it fixed!



Page 7 of 9 pages « First  <  5 6 7 8 9 >

About our Blog

Brantas Limited specialise in Dynamics CRM, SharePoint and System Integration using the Microsoft Platform. We are all experienced developers in various fields with our own specialities complementing those of our team.

We have been working with SharePoint since 2003, including Installation and Administration, Migration, Development and Support.

RSS Feed