Sunday, December 19, 2010

CityVille Tips


A cool new game from Zynga, in general if you know SimCity you will get the idea quickly. What I liked with this game is the game dynamics. First the economics is based on getting supplies (From farming & etc) and selling goods that will earn you money. In the
process you will use some energy. So lets start our tips:



Tip 1: To make the game move faster (get more profit) maximize your population by doing whatever is necessary.

Tip 2: Make sure to build farm plots to cover your needs (best is Corn in my case, im in level 20).

Tip 3: When you build your business don’t forget the energy consummation. So do the following:

  • Increase your Tea, Toys & Berger shops in the beginning
  • don’t build Bakery, Flowers & Video Game shops these will drain your energy

Then when you have enough money and other shops are open to you do the following:

  • Go with the Shoe shop, it’s the best in my current level

Tip 4:
Surround your shops with Barricades as much as possible(they cost 200, increase surroundings 4% & don’t use a lot of space)






Tip 5: Get 200% more from each business

If you need a lot of money quickly as for the cinema task, a good idea is to make a hot bonus zone, a location to move your business to before you collect the profit.
My best design is as follow and its build from items that you already was forest to have, and some others that you can buy, it will cost but it will cover it cost very quickly.

This is the implementation for it. this will give you 203% bonus





The math behind the tips
For Farming:


supply
15
70
110
30
45
80
90
cost
20
46
62
28
36
49
52
So select the 110/62 and that’s the Corn , its the best and about its long time to be ready, farm several times depending on your timing so you get continues supplies and you don’t get your storage full or get out of supply  

For the shops:
Shops
bakery
flowers
tea
toys
Berger
video game
dinner
cosmetic
pool
bicycle
se clothing
coca
sea food
shoe
earning
40
95
320
180
240
50
230
120
420
330
368
441
609
572
supply
10
25
100
50
75
10
50
25
100
75
80
100
140
130
price
200
400
600
800
1000
1300
1600
1900
2200
2500
$20
$15
7500
3500
I started with the above table that made me make the worst decision, and that’s to go with video games. And after a day , my energy was out and everything stops because the shops are waiting for you to recharge with supplies. So I updated the table to see energy usage and got the following:
Shops
bakery
flowers
tea
toys
Berger
video game
dinner
cosmetic
pool
bicycle
se clothing
coca
sea food
shoe
earning
400
380
320
360
319
500
460
480
420
439
460
440
435
440.44
supply
100
100
100
100
99.8
100
100
100
100
100
100
100
100
100.1
Energy
10
4
1
2
1.4
10
2
4
1
1.4
1.25
1
0.72
0.77

So you can see from the above. To use 100 supply you will need 10 energy and yes you will get 500 money, but if you don’t have the needed energy everything will stop and you will be stock to recharge energy and before you know it you are stuck again.
So go with the tea, or Berger in the beginning and then jump to the shoes, with less than one energy you will get about 440 energy and that is great for now.




Saturday, August 14, 2010

Ask The Godfather - Mafia Wars-

If you were a fan of the Mafia Wars Facebook online game (or My Space), this will be intresting.

To sort your mafia and promote the best members to get:
  1. Make jobs require less enery and get more experience & Money
  2. Get more money from fighting & robbing
  3. Get bonus to attacks & defense.
Check the video below for detail steps, and visit the site to Select your Top Mafia
By the way if you have any comments on the site or suggestion i wil be happy to add them too :)



After completing the steps above you will get your top mafia members and the game will be easyer, this is not a cheat, its only a tool to help you out.

Monday, August 02, 2010

Facebook Resources

Facebook resource as books and articles are everywhere these days so I will try to list the most common and add some comments on them, my focus is for Facebook development books and resources.

The basic list is as follow:

  • Facebook API Developers Guide
  • Facebook Cookbook
  • Building.Facebook.Applications.For.Dummies
  • Learning Facebook Application Development
  • Developing Facebook Platform Applications
  • FBML Essentials
  • Facebook API Developers Guide
  • Facebook Applications 100 Success Secrets


For link reference the Facebook official site is the best for starting up your app  (Facebook development)

Other books but not related to development are as follow:
  • Social Networking Spaces
  • Essential Facebook Development
  • Facebook Era
  • Facebook Marketing For Dummies
  • Sams Teach Yourself Facebook in 10 Minutes
  • Facebook the missing manual 2nd Edition
  • Building Facebook Applications For Dummies
  • Facebook For Dummies. 2Ed 
  • Facebook Marketing
  • 150 Facebook Powertools

Wednesday, July 14, 2010

My child may start programing Android sooner than I expected.

A lot of my friends are IT people because I work in an IT environment, but only us (developer) my  build application on the mobile, but these days with the new updates and mobile rush and competition between all companies, I believe this story will start changing.

Not only my colleagues that are IT oriented as network engineers or system administrators can know star developing on mobile application, but even very young children that are in school and have the interest in phones and computers (these days most of them do). Simply it don’t require any programming knowledge.
With the new development environment from Google called App Inventor, normal people without any programming skills can star. The will not do 3D game programming at the beginning (but really who star 3D programming anyway). Thy may start with some basic steps that will feed their ideas and I believe we will see from them more than expected. Now our children will have the ability to program their phones. (if they have Android mobile, that they will request sooner than expected too).
So what is App Inventor, "You can build just about any app you can imagine with App Inventor", as from the Google labs site. But really if you check the Sample Apps, I believe you will be impressed.
So it’s the easiest way to create apps for your phone. If you are interested and have an Android device. You can request an invitation and start doing what you thought about technology and knowledge that was outside your league.

Sunday, July 11, 2010

Sweet Kids Update

I updated the sharing tools for the Sweet kids site, im using AddThis, its very simple and cool, you can check the link from here (Sweet Kids )
I used some extra icon packs too, go to there site and you will find everything you need, i was intending to check other sharing tools and component but realy this one covered all my site needs.

Sweet Kids web project in beta testing phase

Hi, a long time no posts, I was working on a small web project and now it’s online. (you can access it from here)

It’s called Sweet Kids, it’s about uploading the best and most beautiful picture of your babies and voting for them with your family and friends, you can vote for other cute babies too. After voting there is always a top list of votes for the cutest babies.

  • Top of all Time: the most sweet baby picture
  • Top of the month: from the name, the top most voted picture during this month
  • Top of the week: from the name too, the top most voted picture during this week
  • Top of the day: from the name too, the top most voted picture during this day

After compiling a number of photos I will arrange more top list depending on gender, nationality, age and other characteristics.

Currently the site is in beta testing, so don’t be mad if you see something not working, please your feedback and comments will help a lot to improve the site.

I tried to use the best component and tools to arrange the gallery and the uploading take a look at them they are very cool (most of the are jQuery pluging):

For the voting gallery im using galleriffic

For cropping the uploading images im using Jcrop

For uploading control I’m using uploadify

For displaying images from the gallery I’m using PrettyPhoto

Wednesday, June 30, 2010

Mobile Surface (3D without glasses)

Microsoft is in the phase of presenting a new technology to the market that will change the balance of power and mobile distribution, I believe that all high tech mobile owners will throw there mobiles and get ones with this new Microsoft technolog.




To see more check the following links
So know if you have this new mobile technology and have any flat surface, you will have your monitor (screen), mouse keyboard & even touch screen.


If you want more fun and if you are not still convince that this will work see the simple version of what Microsoft is working on,


Sunday, June 20, 2010

WD My Book Studio (2TB External Hard Drive)


I have a large movie library and I will not start talking about the series too, currently about 400GB movies, I didn't see all of them but I believe I will have sometime in my vacation or on a Sunday/Friday night, so at that moment I will love to select something from my library and see it with the family. The problem was to store all that.

I selected a 2TB hard disk from my near computer equipment office (Speed for Computers) and the most things that I was focusing on were size and speed, with the WD My Book Studio I got both and more.

The size was 2TB, and against its price it was very cool, the speed was impressive, I have a local drive that’s 1TB and WD 2TB is faster (yes its an old 1TB drive). I have USB 2.0 connection that’s good and two FireWire 800 too (now we are talking).

It also includes in the same package a FireWire converter from 800 to 400 adapter cable for older systems with a FW 400 port.

It comes with backup software that will backup all your computer data with very simple and useful interface. So backup of your important family photos or important development software (I'm a coder) is one click a way.

The ink display on the devise is very helpful, with the free space left and a bar to show it, its very easy to know were are you in terms of space. I have a Windows 7 PC but the drive supports MAC too. It also have a very cool flashing let to tell you the state of the device (by the way it's also GreenPower Technology).


The dives design is cool too, a silver cover that looks very cool on my desktop near my monitors, it needs an external power devise to work too.

The WD SmartWare software can be updated (really the first thing I did) , it promises to increase the performance x5, I really did this first so I don’t know the old performance but two computers and two laptops had a very quick detect for the device and were all communicating smoothing.

The software is located on a separate write-protected partition on the drive that appears like a CD ROM when the drive is connected. (you can leave it and use it or you can remove/hide it).

The only sound you hear is a small quiet hesh hash when it is being used. When the drive automatically shuts down (Is not actually in use), there is no sound at all.

Its simply the most attractive device I used from a long time.

A new update to the Light Beta Sudoku


You can see the live version here Light Beta Sudoku

I made some small enhancement to the site, First completed the Auto Generation of New Sudoku Puzzles, and filled the database for the next two years, so Daily Sudoku is now active with the Complexity setting.

Yes you can select the level to play and then you can select from Random game or from the Daily Sudoku.

I updated the Action menu so it will display checkboxes with the help of symbol fonts, it helped to make the menu lighter and faster to load.



I updated the Sudoku Possibilities so that it will work with other browsers like Google Chrome & etc. made some small color adjustments too.

With a day or two the site will be fully functional, and I will try to add Google AdSense or/and Amazon recommendations too.


Working with this project was fun and I hope I can close it by the end of this week.

Saturday, June 19, 2010

Generating New Sudoku Puzzles

You can see the live version here Light Beta Sudoku
I searched a lot for algorithms and methods to create new Sudoku Puzzles for my site (Sudoku.lightbeta.com), and the most Algorithms that I as interested is was GA (Genetic Algorithms), so I started playing with it. My results were not so impressive but will do the job needed.
The idea of GA is simply  Generate a several random solution
  1. Calculate each solution fitness  (or how much percentage of the solution is correct)
  2.  Generate New solution from mixing two good solutions (Reproduction)
  3. Make very small changes randomly to this new solution (Mutation)
  4. Do it again and again until you get a 100% correct solution

I need to have multiple new puzzles so whenever I complete I save it to a DB and start over.
Currently I’m creating new Sudoku’s every 3-5min, that’s slow but it will cover my Daily Sudoku site need.
I focusing on showing the fitness function because it’s the heart of the application.

Public Function CalculateFitness() As Single
        'max error are 81 so to norimilize devide on 81
        Dim CheckItems As New Hashtable
        Dim Errors As Integer = 0
        For Row = 0 To 8
            CheckItems.Clear()
            For Col = 0 To 8
                If Not CheckItems.ContainsKey(Me.Items(Row, Col)) Then CheckItems.Add(Me.Items(Row, Col), 0)
            Next
            Errors += (9 - CheckItems.Count)
        Next
        For Col = 0 To 8
            CheckItems.Clear()
            For row = 0 To 8
                If Not CheckItems.ContainsKey(Me.Items(row, Col)) Then CheckItems.Add(Me.Items(row, Col), 0)
            Next
            Errors += (9 - CheckItems.Count)
        Next
        For GroupX = 0 To 8 Step 3
            For GroupY = 0 To 8 Step 3
                CheckItems.Clear()
                For row = 0 To 2
                    For Col = 0 To 2
                        If Not CheckItems.ContainsKey(Me.Items(row, Col)) Then CheckItems.Add(Me.Items(row, Col), 0)
                    Next
                Next
                Errors += (9 - CheckItems.Count)
            Next
        Next
        LastFitness = 1 - (Errors / 81)
        Return LastFitness
    End Function

Simply I’m doing it in three phases; Checking the number of error in row, Columns and squares.
I’m assuming that for each group the numbers must be unique so that the group will contain the numbers from 1 to 9
So I’m adding them to a hash table with the number as the key, so if the number of items in the hash table is less that 9 it mean there was some duplicates that will give errors to the Sudoku solution.
If this function can be enhanced in performance it will be a huge update, so the solution will give more results with less time.

Friday, June 11, 2010

HTC Desire

I bought an HTC Desire and its grate and awesome in all ways.


Very simple to use, beautiful colors, after making the basic setting it was like this is the only mobile I will use for life, the Google Android 2.1 is very stable, there performance is great, I had several other mobiles like the Imate PockePC and the Imate JasJar, some Nokia ones too like the N95 and some classic modules from the stone ages, in last period I was using BlackBerry Curve 8700, so people if you are out there and didn’t use the new age mobiles you are missing a real part of life,

Selecting what to go was a challenge, IPhone, Windows ,Android & Nokia & etc, my heart when to the HTC Desire, its design, large screen resolution, containing all the basic, and the most important thing is to test some new ground and that was the Android OS (Google mobiles). for more details you can check the HTC site here

Google made a super powerful mobile OS, the Google market place with all that free stuff, whatever you can imagine, you can simply find with only minutes.

May be some day I will even develop a small application for it, only for fun.

Saturday, June 05, 2010

Virtual Business Card

This isn’t new stuff, but I don’t see it a lot on the web, it’s a very cool feature for Microsoft MCP’s

You can add it to your resume links to display your experience with Microsoft technologies and its very simply to set up. So if you are a Microsoft Certified Professional pay it a visit, it’s cool. (you can access it from your Microsoft MCP side menu).

You can check mine to see how one of the setting can be like (here), it contain a lot of templates and designs.

Free Online Sudoku

I like Sudoku and love programming, so after some years of playing online games i decided to build my own, it’s still underdevelopment but its promising too. so if you like you can check it out here. http://www.sudoku.lightbeta.com/Sudoku

I used Net4.0, and a lot of generic collections, some java and JQuery too.

The solving engine took more time than expected but it can solve very hard puzzles now, I’m planning to add some more effort to have a user database and generate automatic Sudoku’s daily, have fun.

Saturday, November 28, 2009

Making your input forms more intelligent.

Online sample: Live Demo

There is a large number of applications that are related to entering data that is on paper, these applications always enter the documents from a scanner or import them from a data store and the data entry officer will start filling the forms, some of the forms even have auto OCR for certain areas of the document. Today I want to work on enabling some advance technics that is related to this subject, no OCR detail here (mostly OCR work well only with Western languages like English).


In my case I want my data entry officer to have an easy time entering his information to the form after getting a scan image from the scanner. I don’t want him to have the paper in hand; I don’t want him to switch from one window to another to copy parts of the document as Invoice Number, Owner Name & etc.


My Goal:

• I want the data entry person to see the image side by side with the fields he is entering and the application will focus automatically on the regions that he is filling, as for example, if he is entering information about the Invoice Number, I want the application to zoom on that part of the document, when the data entry person goes to the Owner Name, I need the application to focus and zoom on the Owner Name.

  • I need it to work on asp.net pages (web application)
  • I want to make it easy to be used on other applications (as a component for example)
  • It must be free, no payments here or there.
Tools:
  • VS2010/VS2008 for development with C#/VB
  • A very cool control called Seadragon


Let’s start, making this a short document is hard so I will need to reference some other blogs that will help me on this subject.


Visit my first blog about this control (Using the Seadragon control with an Image library) it will help us make the control work with an image of our desire.


Open a web site project and download the seadragon-min.js, its available on the site.



Add the following to your page header:
<script type="text/javascript" src="Scripts/seadragon-min.js"></script>
 
<script type="text/javascript">
var viewer = null;
var Loc_x = .5;
var Loc_y = .5;
var loc_zoom = 2; 
function init() {
viewer = new Seadragon.Viewer("container");
viewer.openDzi("dzc_output.xml");
}
Seadragon.Utils.addEvent(window, "load", init);
 
 
function SetFocus(x,y,z) {
Loc_x = x;
Loc_y = y;
loc_zoom = z; 
FocusOn();
}
function FocusOn(event) {
Seadragon.Utils.cancelEvent(event); // don't process link
if (!viewer.isOpen()) { return; }
viewer.viewport.panTo(new Seadragon.Point(Loc_x, Loc_y));
viewer.viewport.zoomTo(loc_zoom);
viewer.viewport.ensureVisible();
}
 
 
Seadragon.Utils.addEvent(window, "load", init);
 
</script>              
 

Simply we are adding 3 variables, Loc_x & Loc_y for the location, and loc_zoom for the zoom factor.


Let’s add four text boxes simulating our data enter form side by side with the Seadragon:

<asp:ScriptManager ID="ScriptManager1" runat="server"/>        
<table>
<tr><td class="style2" rowspan="4"><div id="container"></div></td>
<td>
Inv. Number: <asp:TextBox ID="TextBox1" runat="server" />
</td></tr>
<tr><td> 
Inv. Owner Name:<asp:TextBox ID="TextBox2" runat="server"/>
</td></tr>
<tr><td>
Inv Date:<asp:TextBox ID="TextBox3" runat="server"/>
</td></tr>
<tr><td>
rest to home <asp:TextBox ID="TextBox4" runat="server"/>
</td></tr>
</table>

And in our page load event
If (Not IsPostBack) Then
TextBox1.Attributes.Add("Onfocus", "SetFocus(.7,.2,8);")
TextBox2.Attributes.Add("Onfocus", "SetFocus(.4,.5,2);")
TextBox3.Attributes.Add("Onfocus", "SetFocus(.3,.9,2);")
TextBox4.Attributes.Add("Onfocus", "SetFocus(.5,.5,1);")
End If

Each control is hocked with the onfocus event and specifying the location and the zoom factor needed.


In general the width of the document is always 1, the height depends on other factors. If you like to read more about the coordination system go here.


I prefer using zoom factor as 1,2,4,8,16,32 & etc


We can simply warp this in a control containing the viewer and some function to hock the control from the data entry fields.


The Identification  of the active points in the document are always related to the document type (so some database can be used here to focus on needed parts depending on the document type)

Code Formatter

here is a very useful link to format your code for publishing

http://www.manoli.net/csharpformat/format.aspx

Using the Seadragon control with an Image library

Seadragon is one great control in the Ajax Control Tool kit, if you didn’t see it yet, check it out here, the idea is that it gives you a very cool image viewer to you page with DeepZoom Technology. So high resolution images is not a problem anymore.

Alone the control does everything you need, but it forces you to have your image pre-rendered (with Deep Zoom Composer or any other tool) . So what if we need to make this control work with our image library without creating all Seadragon images (without thinking about maintaining them after updates and moving them to your production nor even the extra size). It’s a small challenge.

  1. So after looking at the problem my approach is as follow:
    Create an Http Handler to handle the requests from the Seadragon Control

    1. For IIS6 register the jpg extension to be handled by our handler
    2. Add the needed configurations to our Web.config
    3. Create our handler
  2. Create the needed Seadragon images on the fly. Providing the needed part only to the control.
    1. Finding the needed level and which part the control need
    2. Getting the high resolution image, making some zooming and slicing
    3. Returning the result to the control by the handler.



Simple, that’s it. We don’t need anything else.

Before going in the details, I only wanted to say that this is only the first phase. For future I will try to make it work with PDF documents with some special zooming tricks. But this is not our problem so let’s go back.
For the first task (1.1) registering the jpg extension in IIS, that’s a simple task
Launch the Internet Services Manager tool, right click on Default Web Site, select Properties, go to Home Directory tab and press Configuration button. This will popup Application Configuration dialog. Click Add button and fill the Executable field with the path to the aspnet_isapi.dll file and fill .jpg in the Extension field. Leave the other fields as is, close the Application Configuration and Default Web Site Properties dialog boxes by pressing the OK button. (if you have IIS7 this step is not needed).


For the task (1.2) Add the needed configurations to our Web.config, add the following:
Add the following in the section of the web config
<httpHandlers>
<add verb="*" path="dzc_output_files/*.jpg" type="ImageHandler.HttpImageHandler,ImageHandler"/>
</httpHandlers>
So now requests coming for the control are captured by our handler, so let’s create it.
For the first task (1.c), Create our handler
using System;

using System;
using System.Web;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text.RegularExpressions;
using Injazat.DeepZoom;
namespace ImageHandler
{
public class HttpImageHandler : IHttpHandler
{
 
public void ProcessRequest(System.Web.HttpContext context)
{
DynamicDeepZoomImageGenerator DDZIG = new DynamicDeepZoomImageGenerator();
if (context.Request.PhysicalPath.IndexOf(DDZIG.Identifier) < 0)
{
//this is not for the deep zoom images 
context.Response.Clear();
context.Response.ContentType = getContentType(context.Request.PhysicalPath);
context.Response.WriteFile(context.Request.PhysicalPath);
context.Response.End();
}
else
{
context.Response.Clear();
context.Response.ContentType = getContentType(context.Request.PhysicalPath);
byte[] buffer = DDZIG.GeneratorImage(context.Request.PhysicalPath);
context.Response.OutputStream.Write(buffer, 0, buffer.Length);
context.Response.End();
}
}
public bool IsReusable
{
get
{
return false;
}
}
string getContentType(String path)
{
switch (Path.GetExtension(path))
{
case ".bmp": return "Image/bmp";
case ".gif": return "Image/gif";
case ".jpg": return "Image/jpeg";
case ".png": return "Image/png";
default: break;
}
return "";
}
}}
 

So we need now to create the needed Seadragon images on the fly
I created one class to handle that.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text.RegularExpressions;
 
namespace Injazat.DeepZoom
{
public class DynamicDeepZoomImageGenerator
{
int Size = 250;
public string Identifier = "dzc_output_files";
public DynamicDeepZoomImageGenerator()
{
 
}
public byte[] GeneratorImage(String PhysicalPath)
{
// 1. find the orignal size of the doc
String path = @"C:\inetpub\wwwroot\testthumb\SampleDoc.jpg";
Bitmap imgIn = new Bitmap(path);
Point OriginalSize = new Point(imgIn.Width, imgIn.Height);
 
// 1.5 find number of zoom level avaliable
int ZoomMax = 0;
int X = OriginalSize.Y;
do { X /= 2; ZoomMax++; } while (X > 0);
 
ZoomMax = (int)Math.Ceiling(Math.Log(Math.Max(imgIn.Width, imgIn.Height), 2));
 
// 2. get the zoom level and array location
int ZoomLevel = 0;
Point ArrayLocation = new Point(0, 0);
 
String Pattren = Identifier + @"\\(?<ZoomLevel>[0-9]{1,2})\\(?<XXX>[0-9]{1,2})_(?<YYY>[0-9]{1,2}).jpg";
// use 'x' modifier to ignore comments
Regex r = new Regex(Pattren);
// get the list of group numbers
int[] gnums = r.GetGroupNumbers();
// get first match
Match m = r.Match(PhysicalPath);
if (m.Success)
{
ZoomLevel = int.Parse(m.Groups["ZoomLevel"].Value);
ArrayLocation.X = int.Parse(m.Groups["XXX"].Value);
ArrayLocation.Y = int.Parse(m.Groups["YYY"].Value);
}
// 3. return the needed part depending on the req.
//find the scalling 
int Scale;
if (ZoomMax > ZoomLevel)
{ Scale = (int)Math.Pow(2, (ZoomMax - ZoomLevel)); }
else { Scale = 1; }
 
// resize the image to the scale
Bitmap imgOut = ResizedImage(imgIn, Scale);
 
 
// get only the needed portion of the image
imgOut = GetRegionImage(imgOut, ArrayLocation, Size);
 
return Image2BateArray(imgOut);
}
byte[] Image2BateArray(Bitmap imgIn)
{
System.IO.MemoryStream outStream = new System.IO.MemoryStream();
imgIn.Save(outStream, ImageFormat.Jpeg);
return outStream.ToArray();
}
public Bitmap ResizedImage(Bitmap imgIn, int Scale)
{
if (Scale == 0) Scale = 1;
 
int NewWidth = (int)(1.0F * imgIn.Width / Scale);
int NewHeight = (int)(1.0F * imgIn.Height / Scale);
if (NewWidth == 0) NewWidth = 1;
if (NewHeight == 0) NewHeight = 1;
 
Size NewSize = new System.Drawing.Size(NewWidth, NewHeight);
Bitmap imgOut = new Bitmap(imgIn, NewSize);
return imgOut;
}
Bitmap GetRegionImage(Bitmap imgIn, Point ArrayLocation, int RegionSize)
{
 
Point TopLeft = new Point(ArrayLocation.X * RegionSize, ArrayLocation.Y * RegionSize);
 
Size NewSize = new Size(RegionSize, RegionSize);
if ((TopLeft.X + RegionSize) > imgIn.Width) NewSize.Width = imgIn.Width - TopLeft.X;
if ((TopLeft.Y + RegionSize) > imgIn.Height) NewSize.Height = imgIn.Height - TopLeft.Y;
Rectangle SourceRegion = new Rectangle(TopLeft, NewSize);
 
Bitmap imgOut = new Bitmap(RegionSize, RegionSize);
Graphics g = Graphics.FromImage(imgOut);
g.Clear(Color.White);
 
 
g.DrawImage(imgIn, new Rectangle(0, 0, NewSize.Width, NewSize.Height), SourceRegion, GraphicsUnit.Pixel);
g.Dispose();
return imgOut;
}
void DrawOnImage(ref Bitmap imgIn, String Text)
{
Graphics g = Graphics.FromImage(imgIn);
Font Fo = new Font("Arial", 12);
Rectangle Clip = new Rectangle(0, 0, imgIn.Width, imgIn.Height);
g.DrawString(Text, Fo, Brushes.Blue, Clip);
g.DrawEllipse(Pens.Red, Clip);
Fo.Dispose();
 
g.Dispose();
}
ImageFormat getImageFormat(String path)
{
switch (Path.GetExtension(path))
{
case ".bmp": return ImageFormat.Bmp;
case ".gif": return ImageFormat.Gif;
case ".jpg": return ImageFormat.Jpeg;
case ".png": return ImageFormat.Png;
default: break;
}
return ImageFormat.Jpeg;
}
string getContentType(String path)
{
switch (Path.GetExtension(path))
{
case ".bmp": return "Image/bmp";
case ".gif": return "Image/gif";
case ".jpg": return "Image/jpeg";
case ".png": return "Image/png";
default: break;
}
return "";
}
}
}
So finalizing our work
Create an xml file named “dzc_output.xml”, that will contain:
<?xml version="1.0" encoding="utf-8"?>
<Image TileSize="256" Overlap="0" Format="jpg" ServerFormat="Default" xmlns="http://schemas.microsoft.com/deepzoom/2009">
<Size Width="754" Height="948" /></Image>


Add an web site with a default.aspx page and include the following:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<cc1:Seadragon ID="Seadragon1" runat="server" SourceUrl="~/dzc_output.xml" 
BorderColor="#660033" BorderStyle="Double" BorderWidth="4px" 
Height="240px" AutoHideControls="False" MaxZoomPixelRatio="10" Width="200px">
</cc1:Seadragon>
In my project I added the handler and the DynamicDeepZoomImageGenerator class to a separate project and referenced it.
That’s it.
You can see from the code that the image loaded is one image , in my next post I will add the needed code not only to change the image, but to extract on from a PDF and display it, and focus on some important locations too.  (It depends on the time :) )


Related Links: