小编Eut*_*hro的帖子

使用Bitmap.Config.RGB_565将内存中的位图转换为位图

我有一个加载的位图,我想转换为将配置设置为Bitmap.Config.RGB_565.Bitmap在Bitmap已经加载到内存后,是否有一种简单的方法将a 转换为此配置?例如,下面我有一个从应用程序资源解码的位图,但是,我如何将已经加载的转换BitmapRGB_565?我确定这很简单,但是,我对使用Bitmaps很新,经过几个小时的在线查看,遗憾的是我无法找到我需要的东西.

BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig=Bitmap.Config.RGB_565
bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.myphoto ,options);
Run Code Online (Sandbox Code Playgroud)

rgb android bitmap bitmapfactory

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

找到8组布尔的正确组合的最快方法

我有一套布尔值:x1, y1, z1, x2, z2, x3, y3, z3每一个都是真或假.而不是写几十个if语句来检查正确的真/假组合,找到正确和错误的正确组合的绝对最有效和最快的方法是什么?:

if(x1 == true && y1 == true && z1 == true && 
   x2 == true && z2 == true && 
   x3 == true && y3 == true && z3 == true)
  {
    //do stuff if this is correct combination
  }
else if(x1 == false && y1 == true && z1 == true && 
   x2 == true && z2 == true && 
   x3 == true && y3 == true && z3 …
Run Code Online (Sandbox Code Playgroud)

c# performance combinations boolean

3
推荐指数
1
解决办法
377
查看次数

将位掩码转换回9个布尔值

我有以下代码将一组9个布尔值转换为一个int给我,我将其用于tilemap sprite数组以快速找到tile.只是好奇,有一种简单的方法可以扭转这种局面吗?

即如果所有bool都是真的,那么下面的结果将是511.是否有一种简单的方法将其转换回来赋予布尔都是真的?或者另一个例子,a是假的,其余的都是真的,结果将是510.如何将其转换回a = true而其余为假?

int GetBitmask(bool a, bool b, bool c, bool d, bool e, bool f, bool g, bool h, bool i)
{
    int r = (a ? 1 << 0 : 0) | (b ? 1 << 1 : 0) | (c ? 1 << 2 : 0) |
            (d ? 1 << 3 : 0) | (e ? 1 << 4 : 0) | (f ? 1 << 5 : 0) |
            (g ? 1 << …
Run Code Online (Sandbox Code Playgroud)

c# boolean bitmask

2
推荐指数
1
解决办法
1243
查看次数

C#Windows Phone Mango - 无效的跨线程访问?解析XML

我有以下代码似乎抛出"无效的跨线程访问".而我似乎无法弄清楚为什么.我正在从URL加载远程xml文件,但是,在解析该XML时,我总是收到此错误.有什么建议?

using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
        {
            string xml = streamReader.ReadToEnd();

            using (XmlReader reader = XmlReader.Create(new StringReader(xml)))
            {

                    reader.ReadToFollowing("channel");
                    reader.MoveToFirstAttribute();

                    reader.ReadToFollowing("title");
                    output.AppendLine("Title: " + reader.ReadElementContentAsString());

                    reader.ReadToFollowing("description");
                    output.AppendLine("Desc: " + reader.ReadElementContentAsString());

                    textBox1.Text = output.ToString(); //Invalid cross-thread access.
            }

        }
Run Code Online (Sandbox Code Playgroud)

我试图解析的XML如下所示,我只是在尝试解析点点滴滴,因为我继续学习如何使用c#来解析不同类型的XML:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"xmlns:dc="http://purl.org   /dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0  /modules/slash/">
  <channel>
<title>Server &amp; Site News</title>
<description>A place for the Admin and Moderators to post the latest news on both the server and site.</description>
<pubDate>Fri, 18 May 2012 22:45:08 +0000</pubDate>
<lastBuildDate>Fri, 18 …
Run Code Online (Sandbox Code Playgroud)

c# xml url error-handling windows-phone-7

0
推荐指数
1
解决办法
590
查看次数