我有一个1000x1500像素位图,我想在Android中制作一个可变副本.
当我运行以下代码时......
// int width = original.getWidth(); // 1000px
// int height = original.getHeight(); // 1500px
final Bitmap result = original.copy(original.getConfig(), true);
original.recycle();
Run Code Online (Sandbox Code Playgroud)
......我OutOfMemoryError上copy线了:
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
ERROR/GraphicsJNI(419): VM won't let us allocate 6000000 bytes
Run Code Online (Sandbox Code Playgroud)
为什么复制指令需要6MB(!)才能生成1000x1500像素的位图?
如何以更高内存效率的方式从非可变位图创建可变位图?
BitmapFactory返回不可变位图.显然,从不可变位图创建可变位图的唯一方法是将其复制到新的可变位图中.在1000x1500位图的情况下,这显然需要12MB(1000x1500x4x2),这在大多数Android设备中导致OutOfMemoryError.
这个问题在Android中无法解决吗?
背景:我有一个Wix安装程序,在现有的IIS网站中创建虚拟目录.创建虚拟目录(在安装之前它不存在)但是应该已经创建了IIS网站(用户只需选择要安装到ListBox中的网站).
问题:在卸载时,安装到的IIS网站的物理路径变为空白,该属性没有值.下面是我的主要wix文件的简化版本.我不确定为什么卸载会影响IIS网站,但任何想法都表示赞赏.
注意:我在Wix 3.5和Windows Server 2008 R2,IIS 7上.
<Product>
<Property Id='WEBSITE_DESCRIPTION'>
<RegistrySearch Id='RememberPropertyWEBSITE_DESCRIPTION' Root='HKCU'
Key='SOFTWARE\Company\Product' Name='InstalledWebsiteDescription'
Type='raw' />
</Property>
<Property Id='WEBSITE_PORT'>
<RegistrySearch Id='RememberPropertyWEBSITE_PORT' Root='HKCU'
Key='SOFTWARE\Company\Product' Name='InstalledWebsitePort'
Type='raw' />
</Property>
<Component Id='PropertiesToSave' Directory='ApplicationFolder'>
<RegistryValue Root='HKCU' Key='SOFTWARE\Company\Product'
Name='InstalledWebsiteDescription' Value='[WEBSITE_DESCRIPTION]'
Type='string' />
<RegistryValue Root='HKCU' Key='SOFTWARE\Company\Product'
Name='InstalledWebsitePort' Value='[WEBSITE_PORT]'
Type='string' />
<RemoveFolder Id='CleanupApplicationFolder' On='uninstall' />
</Component>
<Directory Id='TARGETDIR' Name='SourceDir'>
<Component Id='TestWebVirtualDirComponent' Guid='12345678-6304-410E-A808-E3585379EADB'>
<CreateFolder />
<iis:WebVirtualDir Id='TestWebVirtualDir' Alias='[WEBSITE_VIRTUALDIR]' Directory='TARGETDIR' WebSite='MyWebsite'>
<iis:WebApplication Id='TestWebApplication' Name='Test' />
</iis:WebVirtualDir>
</Component>
</Directory>
<iis:WebSite Id="MyWebsite" Description="[WEBSITE_DESCRIPTION]" SiteId="*">
<iis:WebAddress Id="AllUnassigned" Port="[WEBSITE_PORT]" />
</iis:WebSite> …Run Code Online (Sandbox Code Playgroud) 我尝试使用gcc编译一个旧程序(由cc编译).在makefile中有一行如下:
CFLAGS = -O2 -Olimit 2000 -w
Run Code Online (Sandbox Code Playgroud)
gcc中没有'-Olimit 2000'.我想知道它到底意味着什么.使用gcc时是否安全删除此选项.
stdafx.h我在Visual Studio 2010中启动项目时会自动生成一个名为的文件.我需要创建一个跨平台的C++库,所以我不能/不能使用这个头文件.
什么stdafx.h用于?我可以删除这个头文件吗?
cross-platform visual-studio-2010 stdafx.h visual-studio visual-c++
如果我有:linkedlist1= 1,2,3,4;和 linkedlist2= 5,6,7;
如果我调用,我能够以这种方式将linkedlist2附加到linkedlist1的末尾:linkedlist2.set(0,9999) 它会变为linkedlist2 = [999,6,7]并 linkedlist1变为[1,2,3,4,9999,7,8];?
那可能吗 ?或者我确实需要另一种结构?
以下代码不起作用:
List<Double> l1 = new LinkedList<Double>(Arrays.asList(1.0,2.0));
List<Double> l2 = new LinkedList<Double>(Arrays.asList(3.0,4.0));
l1.addAll(l2);
System.out.println(l1);
l2.set(0, 9.0);
System.out.println(l1);
Run Code Online (Sandbox Code Playgroud)
OUTPUT:
[1.0, 2.0, 3.0, 4.0]
[1.0, 2.0, 3.0, 4.0]
Run Code Online (Sandbox Code Playgroud) 我觉得我对使用AutoFac可以做些什么感到困惑,有人可以让我走上正轨.
我有一个基本类型
class PersonBase{
public string SaySomething(){
return "I am base";
}
}
Run Code Online (Sandbox Code Playgroud)
我推导出两个具体的课程
class FakePerson : PersonBase{
public override string SaySomething(){
return "I'm so Fake";
}
}
class RealPerson : PersonBase{
public override string SaySomething(){
return "I am For Real";
}
}
Run Code Online (Sandbox Code Playgroud)
创建一个泛型类PersonHandler,以处理不同类型的人,并希望PersonHandler在适当的时候实例化该人,所以我不想要一个Person实例注入,只需要派生类型
class PersonHandler<T>
where T : PersonBase, new() {
T _Person;
public DoWork(){
_Person = new T();
_Person.SaySomething();
}
}
Run Code Online (Sandbox Code Playgroud)
现在我尝试使用处理程序,在注册下面详细说明的类型后,会有不同的结果.
var ph = contrainer.Resolve<PersonHandler<PersonBase>>();
ph.DoWork();
Run Code Online (Sandbox Code Playgroud)
我试图按如下方式注册类型
1. vBuilder.RegisterType<PersonHandler<FakePerson>>().As<PersonHandler<PersonBase>>();
Run Code Online (Sandbox Code Playgroud)
这给了我一个错误,说明PersonHandler<FakePerson>不能分配PersonHandler<PersonBase>(或者反过来我不会重新分配哪个)
2. vBuilder.RegisterGeneric<typeof(PersonHandler<>)>
vBuilder.RegisterType<FakePerson>().As<PersonBase>(); …Run Code Online (Sandbox Code Playgroud) 我正在编写命令行应用程序,并希望用户能够输入数字作为单个数字或作为范围.所以,例如:
$ myapp -n 3,4,5,6
Run Code Online (Sandbox Code Playgroud)
要么
$ myapp -n 3-6
Run Code Online (Sandbox Code Playgroud)
我希望我的应用程序将这些放入Python列表中,例如,[3,4,5,6]我正在使用optparse,但我不确定如何从这两种输入样式创建列表.一些示例代码会很棒.
编辑
我希望能够输入多个范围:
$ myapp -n 22-27, 51-64
Run Code Online (Sandbox Code Playgroud) 我试图建立一个矢量风格类,并以使用模板还有new,delete运营商我有这样一段代码:
template <class type2> class storage
{
private:
type2 *organs;
public:
int num;
storage(); //constructor
~storage(); //destructor
void operator+(type2 newone);
void operator-(int howmany);
type2 operator[](int place);
};
storage<class type2>:: ~storage()
{
delete[] organs; //~~~~~~~Error number 1~~~~~~~~~~
}
void storage<class type2>:: operator+(type2 newone)
{ // ~~~~~~~~~~~Error number 2~~~~~~~~~~~~~~
organs = new type2[1];
num++;
oragns[num-1] = newone;
}
Run Code Online (Sandbox Code Playgroud)
编译器(Dev C++)在错误号1上写入此错误:
无效使用未定义类型`struct type2'
错误号码2上的此错误:
`newone'的类型不完整
但是,我不明白什么是错的.任何提示?
我正在寻找一个C#SQL Server包装器来调用一些存储过程.如果我正在写一个函数,我会做类似下面的事情(我认为是正确的/正确的):
void RunStoredProc1(object arg1)
{
using(SqlConnection conn = new SqlConnection(connStr)){
try{
SqlCommand cmd = new SqlCommand("storedProc1", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@input1", arg1);
conn.Open();
cmd.ExecuteNonQuery();
} catch (Exception ex){
//handle the exception appropriately.
}
}
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是它似乎有很多重复的代码......每个函数都有相同的using/try(打开/执行)/ catch代码,而且只需要一个就可以了地点.这样做有干净的方法吗?对于我想要使用数据读取器的查询怎么样?
我有一个我反序列化的XML文件,有趣的部分是使用以下代码序列化的XML文件:
enter code here
var serializer = new XmlSerializer(typeof(CommonMessage));
var writer = new StreamWriter("OutPut.txt");
serializer.Serialize(writer, commonMessage);
writer.Close();
Run Code Online (Sandbox Code Playgroud)
我试图再次反序列化以检查输出是否与输入匹配.无论如何,这是我反序列化的代码:
var serializer = new XmlSerializer(typeof(CommonMessage));
var reader = new StringReader(InputFileName);
CommonMessage commonMessage = (CommonMessage)serializer.Deserialize(reader);
Run Code Online (Sandbox Code Playgroud)