This post details my first adventure into developing for the Android platform and the steps taken to get the HelloWorld application to run. Download the Linux SDK from: http://developer.android.com/sdk/index.html Extract the archive and take note of the directory Install Eclipse (`apt-get install eclipse`) Install Eclipse plugin Help->Install Software Add repository: https://dl-ssl.google.com/android/eclipse Select Developer Tools Read and accept licenses Configure Eclipse Windows->Preferences->Android Set SDK Location Select OK Setup SDK and Virtual Device From Eclipse: Window->Android SDK and AVD Manager->Available Packages Select Android Repository->Install Selected Select Virtual devices->New: Name the device and select the target API version Create Android Project in Eclipse Project name: HelloAndroid Application name: Hello Package name: com.example.helloandroid Create Activity: HelloAndroid Build Target: Same as the target as selected for Virtual Device Add the code below to src/com.example.helloandroid/HelloAndroid.java Create a new Runtime configuration Run->Run Configurations->Android->New Project: HelloAndroid Select Target tab and choose the Virtual Device configured earlier Run! After a couple of minutes the emulator should boot and display the HelloWorld application (You may need to unlock the screen first)
This is an archive of the posts published to LessThanDot from 2008 to 2018, over a decade of useful content. While we're no longer adding new content, we still receive a lot of visitors and wanted to make sure the content didn't disappear forever.
Introduction So in part one we decided to use the AForge.Net framework to do this: Finding the fiber and determining the average color based on the image. And the saga continues. The average color After talking to Andrew Kirillov the developer behind AForge.Net he told me about an easier way to do what I did. And here it is. Dim i = New Aforge.Imaging.Filters.ColorFiltering Dim b = GetBitmap() i.red = New intrange(150,255) i.Green = New intrange(150,255) i.blue = New intrange(150,255) i.FillOutsideRange = False Try PictureBox2.Image = i.Apply(b) Catch ex As Exception MessageBox.Show(ex.Message) End Try b = GetBitmap() Dim i2 = New AForge.Imaging.BlobCounter(b) Try Dim Biggestblob = i2.GetObjects(b,true).Where(Function(x) x.Area > 1000).Reverse().FirstOrDefault PictureBox2.Image = i2.GetObjects(b,true).Where(Function(x) x.Area > 1000)(0).Image Me.lblStatus.Text = "Mean: " & Biggestblob.ColorMean.ToString & " STD: " & Biggestblob.ColorStdDev.ToString Me.lblaveragecolor.BackColor = Biggestblob.ColorMean Me.HsbColorIndicator1.AverageColor = Biggestblob.ColorMean Me.lblstdcolor.BackColor = Biggestblob.ColorStdDev Catch ex As Exception MessageBox.Show(ex.Message) End Try``` This method is extremely fast. The result is the same. Here is my version. <div class="image_block"> <a href="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/Findfiber/FindFiber2.png?mtime=1294139316"><img alt="" src="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/Findfiber/FindFiber3.png?mtime=1294139316" width="753" height="544" /></a> </div> And here is the new method. <div class="image_block"> <a href="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/Findfiber/FindFiber3.png?mtime=1294139356"><img alt="" src="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/Findfiber/FindFiber4.png?mtime=1294139356" width="753" height="544" /></a> </div> ## Naming the color And now that we have the average color of our fiber I want to name it. Since it is easier to talk about something when it has a name then when you have to site the RGB values. I thought about this mast night and while chatting with George Mastros he made me think about the HSB system and especially the H in that system. The H or hue makes it easy to separate colors. And it goes from 0 to 360. So I made a usercontrol to show the H values. Like this. ```vbnet Imports System.Drawing.Drawing2D Public Class HSBColorIndicator Private _AverageColor As Color Public Sub New() InitializeComponent() Dim rect = New Rectangle(0, 0, 20, 360) Dim region = New Rectangle(0, -1, 18, 361) Dim m_colorSliderBitmap = New Bitmap(18, 360) Using g = Graphics.FromImage(m_colorSliderBitmap) Using brBrush = New LinearGradientBrush(rect, Color.Blue, Color.Red, 90.0F, False) Dim colorArray = {Color.Red, Color.Magenta, Color.Blue, Color.Cyan, Color.FromArgb(0, 255, 0), Color.Yellow, Color.Red} Dim posArray = {0.0F, 0.1667F, 0.3372F, 0.502F, 0.6686F, 0.8313F, 1.0F} Dim colorBlend = New ColorBlend() colorBlend.Colors = colorArray colorBlend.Positions = posArray brBrush.InterpolationColors = colorBlend g.FillRectangle(brBrush, region) g.DrawLine(Pens.Black, 0, 30, 18, 30) g.DrawLine(Pens.Black, 0, 90, 18, 90) g.DrawLine(Pens.Black, 0, 150, 18, 150) g.DrawLine(Pens.Black, 0, 210, 18, 210) g.DrawLine(Pens.Black, 0, 270, 18, 270) g.DrawLine(Pens.Black, 0, 330, 18, 330) End Using End Using Me.hsbcolorbar.Image = m_colorSliderBitmap End Sub Public Property AverageColor As Color Get Return _AverageColor End Get Set(ByVal value As Color) _AverageColor = value DrawArrow End Set End Property Private Sub DrawArrow() Me.Invalidate(New Rectangle(19, 0, 200, 360)) Me.Refresh() Dim x = 19 Dim y = Convert.ToInt32(360 - _AverageColor.GetHue) Using g = Me.CreateGraphics Dim points = {New Point(x, y), New Point(x + 10, y - 3), New Point(x + 10, y + 3)} g.DrawPolygon(Pens.White, points) g.DrawString(GetColorName, New Font(New FontFamily("Arial"), 7), Brushes.White, 31, y - 5) End Using End Sub Private Function GetColorName() As String Dim _Color As String = "Not defined" Dim hue = 360 - _AverageColor.GetHue If hue > 30 AndAlso hue <= 90 Then _Color = "Violet" ElseIf hue > 90 AndAlso hue <= 150 Then _Color = "Blue" ElseIf hue > 150 AndAlso hue <= 210 Then _Color = "Turquoise" ElseIf hue > 210 AndAlso hue <= 270 Then _Color = "Green" ElseIf hue > 270 AndAlso hue <= 330 Then _Color = "Yellow" Else _Color = "Red" End If Return _Color End Function End Class So I decided on some boundaries and I show an arrow where the average color is situated within the hue range, simple. Getting the hue from a color in .Net is very easy since you can just do GetHue().
Introduction Yesterday Mladen Prajdic ([twitter][1]|[blog][2]) told me about [AForge.Net][3] for image manipulation. So I immediately downloaded it and tried it out on one of my pet projects. Finding the fiber and determining the average color based on the image. The mission The mission , if you wish to accept it, is to calculate the average color of a fiber as to eliminate the need for the analyst to decide the color. The problem with letting the analyst decide the color is that it changes from time to time and from person to person. Orange might be red in the beginning of the day it might be yellow by the end of the day. Turquoise might be blue one day or green the other. We have already limited the number of colors an analyst can choose from but still it is not good enough. In the end of the day we want to compare our thousands of fibers in an easy, fast and reliable way. Make groupings based on those characteristics.
Introduction Cropping an Image is pretty simple in VB.Net. Today I had a need to make it possible for my users to crop some images by drawing a selection rectangle and I felt the need to reinvent the wheel ;-). Not zoomed image Cropping isn’t all that difficult with VB. As you can see from the following piece of code. Dim bmp As New Bitmap(newwidth,newheight) Dim g = Graphics.FromImage(bmp) g.DrawImage(PictureBox1.Image,0,0, New Rectangle(newtop, newleft, newwidth, newheight), GraphicsUnit.Pixel)```<div class="image_block"> <a href="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/croppedimage/CroppedImage1.png?mtime=1294047503"><img alt="" src="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/croppedimage/CroppedImage1.png?mtime=1294047503" width="860" height="556" /></a> </div> First thing to do was show the image, since these are scanned pages from books they are going to be a rather large format. So the picturebox will have to be able to zoom to show the image. Now this is where it gets interesting. But I did ;-). The biggest problem was to detemine the zoomfactor used in the original so that the cutout would match. Perhaps I’m doing it all wrong but it works. <div class="image_block"> <a href="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/croppedimage/CroppedImage.png?mtime=1294047492"><img alt="" src="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/croppedimage/CroppedImage.png?mtime=1294047492" width="860" height="556" /></a> </div> And here is the not yet perfect code. ```vb.net Imports System.Drawing.Drawing2D Public Partial Class MainForm Private _CropRectangle As CropRectangle Private _ZoomFactor As Double Public Sub New() Me.InitializeComponent() _CropRectangle = New CropRectangle If pictureBox1.Image.Width > pictureBox1.Image.Height Then _ZoomFactor = Me.Panel1.Width / pictureBox1.Image.Width * 100 Else _ZoomFactor = Me.Panel1.Height / pictureBox1.Image.Height * 100 End If If (pictureBox1.Image.Height / 100 * _ZoomFactor) > (Me.Panel1.Height) Then _ZoomFactor = (Me.Panel1.Height) / pictureBox1.Image.Height * 100 End If If (pictureBox1.Image.Width / 100 * _ZoomFactor) > Me.Panel1.Width Then _ZoomFactor = Me.Panel1.Width / pictureBox1.Image.Width * 100 End If If _ZoomFactor < 0.2 Then _ZoomFactor = 0.2 End If If _ZoomFactor > 100 Then _ZoomFactor = 100 End If Dim _Height As Integer _Height = Convert.ToInt32 (Me.PictureBox1.image.Height/100*_ZoomFactor) Dim _Width As Integer _Width = Convert.ToInt32 (Me.PictureBox1.image.Width/100*_ZoomFactor) Dim _Left As Integer If _Width < Me.Panel1.Width Then _Left = Convert.ToInt32 ((Me.Panel1.Width - _Width)/2) Else _Left = 0 End If Dim _Top As Integer If _Height < (Me.Panel1.Height) Then _Top = Convert.ToInt32 ((Me.Panel1.Height - _Height)/2) Else _Top = 0 End If _CropRectangle.ZoomFactor = _ZoomFactor setImage(True, _Height, _Width, _Left, _Top) End Sub private Sub SetImage(ByVal Visible As Boolean, ByVal Height As Integer, ByVal Width As Integer, ByVal Left As Integer, ByVal Top As Integer) PictureBox1.Visible = Visible PictureBox1.Height = Height PictureBox1.Width = Width PictureBox1.Left = Left PictureBox1.Top = Top End Sub Private Sub PictureBox1_MouseDown( ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown _CropRectangle.CropX = e.X _CropRectangle.CropY = e.Y _CropRectangle.CropX2 = e.X _CropRectangle.CropY2 = e.Y _CropRectangle.Initialized = True End Sub Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove If _CropRectangle.Initialized = True _CropRectangle.CropX2 = e.X _CropRectangle.CropY2 = e.Y _CropRectangle.Draw(Me.PictureBox1) end if End Sub Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp _CropRectangle.Initialized = False _CropRectangle.DrawCroppedImage(PictureBox1, PictureBox2) End Sub Private Class CropRectangle Private _CropPen As Pen Public Sub New _cropPen = New Pen(Color.green, 1) _cropPen.DashStyle = DashStyle.Dot End Sub Public Property Initialized As Boolean = False Public Property CropX As Integer Public Property CropY As Integer Public Property CropX2 As Integer Public Property CropY2 As Integer Public Property ZoomFactor As Double Public readonly Property CropPen As Pen Get Return _CropPen End Get End Property Public sub DrawCroppedImage(ByVal PictureBox1 As PictureBox, Byref PictureBox2 As PictureBox) Dim bmp As New Bitmap(Convert.ToInt32((_CropX2 - _CropX)/ZoomFactor*100), Convert.ToInt32((_CropY2 - _CropY)/ZoomFactor*100)) Dim g = Graphics.FromImage(bmp) g.DrawImage(PictureBox1.Image,0,0, New Rectangle(_cropx/ZoomFactor*100, _cropy/ZoomFactor*100, (_cropx2 -_cropx)/ZoomFactor*100, (CropY2 - _cropy)/ZoomFactor*100), GraphicsUnit.Pixel) PictureBox2.Image = bmp End Sub Public sub Draw(ByRef PictureBox1 As PictureBox) PictureBox1.Refresh() Dim g = PictureBox1.CreateGraphics g.DrawRectangle(_cropPen,_cropx, _cropy, _cropx2 -_cropx, CropY2 - _cropy) End Sub End Class End Class Here is the downloadable code in VS 2010 format.
A couple of days ago I posted about some stats in the 2010.. a year in stats..browsers, smartphones and windows flavors post. Today we are looking at most popular posts, what the most used search engines keywords were and the top 20 countries where our visits come from. Countries We got visitors from 210 countries, in the table below is the top 20. As expected the United States has the bulk of the visits.
Introduction The more popular your site becomes the more spam you will get. And a few weeks ago we had a lot of comment spam on this site. When fighting spam you must know what drives the enemy. And in this case it is backlinks. To moderate or not to moderate Since our site still gets a normal amount of comments I think we should still moderate, this will keep manual spam to a minimum. Because you should not forget that once they get through your defenses they will flood you via that hole in your defense.
** Monitoring SQL Server Monitoring SQL Server, or for that matter, any database server, is a critical aspect to a DBA or team that is hosting data services. In order to maintain a successful percentage of uptime, we as DBAs must rely on tools like this to manage alerts, performance baselines and the historic collection of statistics. All of these points can be accomplished without a boxed tool but the efforts that go into customizing them on our own outweigh the cost of the products themselves. A DBAs time is money spent with little return. This is a hardened fact that we have to accept. We do not provide a product to sell or a return in revenue. What we return in value is a constant flow of data to the business continuity. When we spend our time working more efficiently and budgeting our resources better, we as DBAs are more successful and obtain the value we look to achieve.
** RMO and working with SQL Server Replication I’ve started to add Wiki entries here on LessThanDot for Replication Management Objects (RMO). RMO is not a new assembly and has been around a long time for use with replication. In most cases RMO is extremely beneficial to merge replication when the subscriptions are editions like SQL Express. This is due to the lack of a SQL Server Agent on the Express side. With RMO you can run almost every task that involves replication including monitoring.
I know I’ve said it before, but 2010 was an amazing year. I can’t wait to see what 2011 has in store for me. A year ago, I sat down and wrote some goals for myself. I achieved almost all of them, and they opened doors for me that have led to opportunities I would never have imagined. I’ve spent the last few weeks thinking about what I can ask myself to do next year. I want to continue working on the amazing opportunities I’ve been given, try some new things, and (most importantly) inspire and help others to do cool stuff too.
The end of the year 2010 is coming up, this is an excellent time to review my 2010 goals. In this post 2010 Goals For SQLDenis I have outlined a couple of things I wanted to accomplish in 2010. Here is a list of those goals Upgrade our servers to SQL Server 2008 Read 2 books per month Be more active in the SQL community Watch more television Play more computer games