小编TaW*_*TaW的帖子

相关性数学:(a + b)+ c!= a +(b + c)

最近,我正在阅读Eric Lippert 撰写的一篇旧博客文章,其中,在写关于关联性时,他提到在C#中,(a + b) + c并不等同于a + (b + c)a,b,c的某些值.

我无法弄清楚哪些类型和范围的算术值可能是正确的以及为什么.

.net c# math numeric

53
推荐指数
3
解决办法
3430
查看次数

java.lang.OutOfMemoryError:Android 1.4上超出了GC开销限制

我得到一个java.lang.OutOfMemoryError:在Android 1.4上运行gradle时超出了GC开销限制 ...这些是我的依赖:

dependencies {
    compile project(':android-crop')
    compile project(':RTEditor-Toolbar')

        compile files('libs/apache-mime4j-0.6.jar')
        compile files('libs/httpmime-4.1.3.jar')
    /*    compile files('libs/httpcore-4.4.1.jar')*/
    compile files('libs/jetbrains-annotations.jar')
    compile files('libs/pinchzoom.jar')
    compile files('libs/gcm.jar')
    compile 'com.google.android.gms:play-services:7.8.0'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:cardview-v7:22.2.1'
    compile 'com.android.support:design:22.2.1'
    compile 'com.android.support:recyclerview-v7:22.2.1'
    compile 'com.android.support:support-v4:22.2.1'
    //three party library
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.mcxiaoke.volley:library:1.0.18'
    compile 'com.vinaysshenoy:mugen:1.0.1'
    compile 'com.github.clans:fab:1.5.5'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.github.curioustechizen.android-ago:library:1.3.0'
    compile 'com.squareup.okio:okio:1.5.0'
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.1@aar') {
        transitive = true;
    }
Run Code Online (Sandbox Code Playgroud)

怎么解决这个问题?

java android garbage-collection

25
推荐指数
4
解决办法
4万
查看次数

.NET中的热图样式渐变

我正在尝试使用与此类似的渐变创建热图: 在此输入图像描述

此图像显示三个点,渐变很好地融合在一起.

这是我目前在绘图功能中所做的事情:

public void DrawGradient(int x, int y, Graphics g) {
    using (var ellipsePath = new GraphicsPath()) {

    var bounds = new Rectangle(x, y, 100, 100);
    ellipsePath.AddEllipse(bounds);
    var brush = new PathGradientBrush(ellipsePath);
    Color[] colors = { 
           Color.FromArgb(64, 0, 0, 255), 
           Color.FromArgb(140, 0, 255, 0), 
           Color.FromArgb(216, 255, 255, 0), 
           Color.FromArgb(255, 255, 0, 0) 
       };
    float[] relativePositions = {0f,0.25f,0.5f, 1.0f};
    ColorBlend colorBlend = new ColorBlend();
    colorBlend.Colors = colors;
    colorBlend.Positions = relativePositions;
    brush.InterpolationColors = colorBlend;

    g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
    g.SmoothingMode …
Run Code Online (Sandbox Code Playgroud)

.net c# system.drawing gradient alphablending

15
推荐指数
1
解决办法
3269
查看次数

使用DateTime.ToString("tt")时,Windows 10中的时间输出(AM/PM)发生了变化

我最近升级到Windows 10 - 我现在看到使用"tt"格式说明符时日期输出中出现了一些意外的变化.

以下是一些演示此问题的代码:

using System.IO;
using System;
using System.Globalization;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
        var cultures = new string[] {null, "en-NZ", "en-US", "en-AU", "en-GB"};

            foreach (var culture in cultures) {
                if (culture != null) {
                    var c = CultureInfo.GetCultureInfo(culture);
                    System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture = c;
                }

                DateTime dt = new DateTime(2015, 1, 2, 3, 4, 5, DateTimeKind.Utc);

                Console.WriteLine("selection: {0} CurrentThread.CurrentCulture.Name: {1} CurrentThread.CurrentUICulture.Name: {2}  Value: {3}",
                    culture ?? "ambient",
                    System.Threading.Thread.CurrentThread.CurrentCulture.Name,
                    System.Threading.Thread.CurrentThread.CurrentUICulture.Name,
                    dt.ToString("hhh:mm tt"));
            }
    }
} …
Run Code Online (Sandbox Code Playgroud)

c# datetime datetime-format windows-10

14
推荐指数
1
解决办法
1042
查看次数

GetBytes函数如何工作?

我编写了自己的类,将C#标准基元转换为字节数组.

后来,我看了一下BitConverter,看看专业人士是如何做到的.

我的代码示例:

public static byte[] getBytes(short value) {
    byte[] bytes = new byte[2];

    bytes[0] = (byte)(value >> 8);
    bytes[1] = (byte)value;

    return bytes;
}
Run Code Online (Sandbox Code Playgroud)

BitConverter类代码:

public unsafe static byte[] GetBytes(short value) 
{ 
    byte[] bytes = new byte[2];
    fixed(byte* b = bytes) 
        *((short*)b) = value;
    return bytes;
}
Run Code Online (Sandbox Code Playgroud)

为什么他们的功能被标记为不安全并使用固定运算符?

即使这些功能使用不安全,这些功能是否容易出错?我应该放弃我的并实施它们吗?哪个更有效率?

c# primitive bytearray bitconverter

13
推荐指数
1
解决办法
791
查看次数

如何在datagridview中添加绑定到数据源的New Row

我有一个绑定到数据源的datagridview.当我单击"编辑"按钮或"新建"按钮时,我必须在datagridview中添加一个新行.我尝试了一些代码,但它给了我错误,代码如下

DataGridView grdview = new DataGridView();
grdview.Rows.Add();
grdview.Rows[grdview.Rows.Count - 1].Cells[0].Selected = true;
grdview.BeginEdit(false);
Run Code Online (Sandbox Code Playgroud)

我还尝试将数据源类型转换为数据表但没有解决方案.

c# datagridview winforms

10
推荐指数
3
解决办法
4万
查看次数

在其中心旋转图形位图

我正在为学校做项目,我们需要在不使用XNA的情况下在C#中进行基本的自上而下的比赛.首先让我告诉你,到目前为止我们学到的关于编程的东西与制作甚至远程看起来像一场比赛的东西没什么关系.它没有比数组,循环等更难.所以我们没有学习图形或类似的东西.

说完所有我有以下问题.

我们创建了一个Graphics对象,然后使用DrawImage并使用car.jpg中的位图.

graphics = e.Graphics;
graphics.RotateTransform(angle);
graphics.DrawImage(car, xPos, yPos, car.Width, car.Height);
Run Code Online (Sandbox Code Playgroud)

然后我们等待按键,例如右键

case Keys.Right:
  if (angle != 360)
  {
    angle += 10;
  }
  else
  {
    angle = 0;
  }
  this.Refresh();
  break;
Run Code Online (Sandbox Code Playgroud)

我们遇到的问题是旋转的枢轴点位于左上角.因此,只要我们将汽车移动到类似的东西(20,25)并开始旋转它,它就会(0,0)用作旋转中心.我们想要实现的是将中心旋转点置于汽车的中心位置.

我们试图寻找各种方法来改变centerXcenterYRotateTransform,但得出的结论是,这是不可能的位图.我们一直在努力解决这个问题超过2天,似乎无法找到任何解决方案来实现我们想要的东西.

有没有什么我们在创建Graphics对象时做错了,还是有一种完全不同的方式来改变centerXcenterY为汽车?

c# graphics

8
推荐指数
1
解决办法
4607
查看次数

如何从WinForm pictureBox中的图像裁剪多边形区域?

如何使用多边形裁剪图像的一部分?例如,我有6个坐标,我想剪切这部分图像.

在此输入图像描述

c# image crop winforms

7
推荐指数
1
解决办法
3298
查看次数

图表自动滚动(示波器效果)

我的问题是,无论何时我向图表添加一个点,它都会压缩所有点.相反,我希望它自动滚动.

这里有两个.gif来解释我的问题

我现在有什么

在此输入图像描述

我想要实现的目标

在此输入图像描述

我现在的代码是

    DateTime dt;

    private void Form1_Load(object sender, EventArgs e)
    {
        timer1.Start();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        dt = DateTime.Now;
        if (checkBox1.Checked)
        {
            chart1.Series["Light"].Points.AddXY(dt.ToShortTimeString(), 1);
        }
        else
        {
            chart1.Series["Light"].Points.AddXY(dt.ToShortTimeString(), 0);
        }

    }
Run Code Online (Sandbox Code Playgroud)

c# scroll mschart winforms

7
推荐指数
1
解决办法
856
查看次数

根据多个系列的X值的一部分中的值,缩放图表的Y轴

我有一个这样的应用: 具有X轴缩放的图表 使用图表下方的文本框,用户可以设置图表的X轴的最小值和最大值.这是它的代码:

private void textBoxXaxisMin_TextChanged(object sender, EventArgs e)
{
    double x;
    //checks if the input is a double and smaller than the max value
    //if (Double.TryParse(this.textBoxXaxisMin.Text, out x) && x < chart1.ChartAreas[0].AxisX.Maximum)    
    if (Double.TryParse(this.textBoxXaxisMin.Text, out x))
    {
        this.textBoxXaxisMin.BackColor = Color.White;
        chart1.ChartAreas[0].AxisX.Minimum = Convert.ToDouble(this.textBoxXaxisMin.Text);
        //changeYScalaMin(chartCharacteristicCurvesThermoelemts, Convert.ToDouble(this.textBoxCharacteristicCurvesThermoelementXmin.Text), Convert.ToDouble(this.textBoxCharacteristicCurvesThermoelementXmax.Text));     

        //method to scale y axis

    }
    else
        //if the textbox is not highlighted 
        this.textBoxXaxisMin.BackColor = Color.Orange;
    //calls the Max Function to update the chart if the Max-value is now valid

    double y;
    //checks if …
Run Code Online (Sandbox Code Playgroud)

c# charts scaling axis winforms

6
推荐指数
2
解决办法
3万
查看次数