Wednesday, March 17, 2021

C# - How to draw image with Gamma or Threshold effect

var rectDest = new Rectangle( 0, 0, this.m_bitmap_source.Width, this.m_bitmap_source.Height );
using ( var graphics = Graphics.FromImage( this.m_bitmap_dest ) ) using ( var attr = new ImageAttributes() ) { attr.SetGamma( 0.2f ); graphics.DrawImage( this.m_bitmap_source, rectDest, 0, 0, this.m_bitmap_source.Width, this.m_bitmap_source.Height, GraphicsUnit.Pixel, attr ); }
You can use Threshold effect too (replace row with Gamma):
attr.SetThreshold( 0.4f );

Friday, March 5, 2021

C# - How to initialize List items in new statement

One possibility:
image.Normalize( new List() { new Rectangle( 100, 100, 300, 100 ) }  );
Another possibility with setting accessible properties by name:
image.Normalize( new List()
{ 
  new Rectangle() { X=100, Y=100, Width=300, Height=100 }, 
  new Rectangle() { X=200, Y=250, Width=200, Height=50 }
}  
);

Monday, March 1, 2021

C# - How to check installed .NET SDK

With this command tool dotnet.exe you can list for example installed .NET SDK.
Tip: If you want make .NET 5 app, create .NET CORE x project and then you can change it into .NET 5 (Feb 2021).

Friday, January 29, 2021

office (vba) - How to load data from text file into excel

If you have this text file with two columns, first with key, second with value:
osc;value
476;56
113;102
272;32.5
This VBA macro code enables to load data, check key comparing with first A column, if key is equal (exactly, if starts with key), then fill value into column R.
Sub Import()
  
  Dim file As String
  Dim counter As Integer
  Dim arr() As String
  Dim key As String
  Dim rngFound As Range
  Dim sheet As Worksheet
  Dim cell As Object
  
  file = Application.GetOpenFilename("Data files (*.txt),*.txt", Title:="Select file")
  
  If file = "False" Then Exit Sub
  
  ' Open file for reading
  
  Set sheet = ActiveSheet
  counter = 1
  
  Open file For Input As #1
  Do Until EOF(1)
    Line Input #1, textline
    
    ' Header - omit it
    If counter <> 1 Then
    
        arr = Split(textline, ";")
                
        ' Find row key value
        For Each cell In sheet.UsedRange.Rows
          
          key = sheet.Cells(cell.Row, "A").Value
                    
          If key <> "" Then
            If key Like arr(0) + "*" Then                
                
                sheet.Cells(cell.Row, "R") = arr(1)
                
            End If
          End If
                    
        Next cell
       
        ' MsgBox (arr(0) + "=" + arr(1))
    End If
        
    counter = counter + 1
  Loop
  Close #1
  
  MsgBox ("Hotovo")
  
End Sub
Output:

Tuesday, January 26, 2021

AX - How to set conditionally grid font type to bold

..on DataSource override displayOption() method:
public void displayOption(Common _record, FormRowDisplayOption _options)
{
    DM_ProductivityDuplicate dm_productivityDuplicate1;
    real iPercent;

    dm_productivityDuplicate1 = _record;

    if ( dm_productivityDuplicate1.cieb_duplicate == NoYes::Yes ) _options.fontBold( true );

    super( _record, _options );
}