Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#返回位图宽度为1_C#_Image_Bitmap - Fatal编程技术网

C#返回位图宽度为1

C#返回位图宽度为1,c#,image,bitmap,C#,Image,Bitmap,我正在尝试创建位图,我所拥有的只是savedUri和imagePath。我相信我正在正确地检索imagePath,因为当我去查看照片和记录路径的照片的实际属性时,它们是相同的,所以我认为创建位图的方式存在问题。以下是我使用的代码: if (_bitmap == null) { string imagePath = null; try { imagePath = GetRealPathFromURI(_saveUri); LogManage

我正在尝试创建位图,我所拥有的只是savedUri和imagePath。我相信我正在正确地检索imagePath,因为当我去查看照片和记录路径的照片的实际属性时,它们是相同的,所以我认为创建位图的方式存在问题。以下是我使用的代码:

if (_bitmap == null)

{
    string imagePath = null;
    try
    {
        imagePath = GetRealPathFromURI(_saveUri);
        LogManager.Info("********the image path is", imagePath);
    }
    catch
    {
        imagePath = _saveUri.Path;
    }

    // First decode with inJustDecodeBounds=true to check dimensions
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.InJustDecodeBounds = true;
    BitmapFactory.DecodeFile(imagePath, options);
    var width = (int)Math.Round(_outputX * 0.5);
    var heigth = (int)Math.Round(_outputY * 0.5);
    options.InSampleSize = BitmapTools.CalculateInSampleSize(options, width, width * heigth);
    options.InJustDecodeBounds = false;
    options.InDensity = 160;

    try
    {
        _bitmap = BitmapFactory.DecodeFile(imagePath, options);
    }
    catch
    {
        GC.Collect();
        _bitmap = BitmapFactory.DecodeFile(imagePath, options);
    }
}
if (_bitmap == null)
   LogManager.Info("********the bitmap width is:  ", "well bloody hell the bitmap is null");
else
   LogManager.Info("********the bitmap width is:  ", _bitmap.Width.ToString());

在最后两行,位图从不为空,但它的宽度始终为1,并且当我显示它时,没有图像。这是用于在Monodroid上创建、显示和保存图像,但这与这个问题没有太大关系。

选项的值是多少。InSampleSizeget?它给了我值:2147483647好的,我想这就是问题所在<代码>选项。InSampleSize是一个比例因子(如果大于1)。如果为4,则图像将缩放为原始高度和宽度的1/4。在你的例子中,它被缩小到基本上没有,但我猜最小值是1像素宽。哇,是这样的,只是硬编码为10,看起来很棒,我会回去看看为什么这个数字这么大。谢谢