-2

UIImageView不显示/显示原始图像作为服务器上可用的图像。更多参考检查它

float scaleFactor = 0.0f;`
float scaleWidth = dstRectangle.Width; //width =748
float scaleHeight = dstRectangle.Height; // height = 759
if(!SizeF.Equals(srcRectangle ,dstRectangle))
{
float widthFactor =(float) dstRectangle.Width / srcRectangle.Width;   //srcRectHeight = 512
float heightFactor =(float) dstRectangle.Height / srcRectangle.Height;  //srcRectangle.Height = 314
if(widthFactor >heightFactor)
scaleFactor = widthFactor ;
else
scaleFactor = heightFactor;
scaleWidth = srcRectangle.Width * scaleFactor;
scaleHeight = srcRectangle.Height * scaleFactor;
if(widthFactor >heightFactor)
           {
thumbnailPoint.Y = (dstRectangle.Height - scaleHeight) * .5f;
}
else


if(widthFactor < heightFactor)
{
thumbnailPoint.X = (dstRectangle.Width - scaleWidth) *.5f;
}
}
UIGraphics.BeginImageContext(new SizeF(dstRectangle.Width , dstRectangle.Height));
RectangleF thumbnailRect = RectangleF.Empty;
thumbnailRect.Offset(thumbnailPoint);
thumbnailRect.Size.Width = scaleWidth;

thumbnailRect.Size.Height = scaleHeight;




CGImage  _bitmap = UIGraphics.GetImageFromCurrentImageContext().CGImage;
ImgVIew.Image = UIImage.FromImage(_bitmap);
UIGraphics.EndImageContext();

它给了我一个 UIImage 但不显示在 UIImageView 在 CGImage 我得到 ALphaInfo = PremultipledLast

BitsPerComponant = 8

BitsPerPixel =32

BytesPerRow = 3008

Height= 759

Width = 748

这个值我进入 CGImage 但是这个 CGImage 我将它转换为 UIImage 但它仍然无法显示

4

1 回答 1

0

你能做这样的事情吗:

        using (var url = NSUrl.FromString ("http://yoururl.com/yourpic.jpg"))
        {
            using (var data = NSData.FromUrl (url))
            {
                imageView.Image = UIImage.LoadFromData (data);
            }
        }

听起来您只需要下载图像并将其设置为 a UIImageView,对吗?

看起来您正在为一些非常简单的事情编写大量代码。

注意:对网络错误使用 try-catch。

于 2012-07-28T15:09:38.733 回答