我的应用程序崩溃,在logcat中显示:
java.lang.OutOfMemoryError: (Heap Size=39047KB, Allocated=19932KB)
at android.graphics.BitmapFactory.nativeDecodeFile(Native Method)
at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:373)
at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:443)
at com.mApp.mobileapp.mActivity.onActivityResult(mActivity.java:196)
at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:153)
at android.app.Activity.dispatchActivityResult(Activity.java:4752)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3449)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3503)
at android.app.ActivityThread.access$1100(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1320)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:5109)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:991)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:758)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
在运行此代码时:
String selectedImagePath = data.getStringExtra("imageByteCode");
try {
File imageFile = new File(selectedImagePath);
Bitmap bitmap = BitmapFactory.decodeFile(imageFile
.getAbsolutePath());//line 196
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
base64code = selectedImagePath;
mImage.setImageBitmap(bitmap);
} catch (Exception e) {
} …Run Code Online (Sandbox Code Playgroud) 我的应用程序在这行中出现内存泄漏.如果我看一下任务管理器,每次触发此过程时,RAM内存增加+ - 300 MB ..
Bitmap bmp1 = new Bitmap(2480, 3508);
panel1.DrawToBitmap(bmp1, new Rectangle(0, 0, 2480, 3508));
pictureBox2.Image = bmp1;
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决他的泄漏吗?如果我使用:
bmp1.Dispose();
Run Code Online (Sandbox Code Playgroud)
我在此行的"Program.cs"中遇到异常:Application.Run(new Form1());
在此之后,应用程序停止运行...
屏幕应用:

我最近使用锁定的位图,并且我一直"试图访问无效内存"错误.这主要是因为位图已在内存中移动.有些人GCHandle.Alloc()用来在CLR中分配内存并固定它.不Bitmap.LockBits()这样做?我不明白"锁定"内存和"固定"内存之间的区别.你能解释术语和差异吗?
我从我的资源文件夹中获取了一些图像,我有这个例外:
03-11 10:18:28.019: E/dalvikvm-heap(4052): Out of memory on a 9830416-byte allocation.
Run Code Online (Sandbox Code Playgroud)
我在这里有这个错误:
//stream to get photo
InputStream bitmap=null;
bitmap=getResources().getAssets().open("ProduitsMini/"+productList.get(rang).getImg_mini());
Bitmap bit=BitmapFactory.decodeStream(bitmap);
// get drawable image
Drawable mDrawable = new BitmapDrawable(getResources(),bit);
Run Code Online (Sandbox Code Playgroud)
这很奇怪,因为我在每台设备上都没有这个错误,只有Galaxy S3.
我有一个列表"图像",其中包含约20张照片,每张约1MB.我想通过单击下一个按钮滚动列表中的图像.但在大约8张照片后,我记忆犹新.
private void button4_Click(object sender, EventArgs e) //next
{
index++;
if (index >= images.Count) index = 0;
CurrImage = images[index];
Bitmap b = new Bitmap((Bitmap)CurrImage.Clone()); //breakpoint occurs her
pictureBox1.Image = b;
NewThread = new Thread(new ThreadStart(ChooseColors2));
}
Run Code Online (Sandbox Code Playgroud)
ChooseColors2线程将使用"CurrImage"以避免竞争条件,我通过创建一个新的位图避免了这一点,如上所示
请注意,如果我使用pictureBox1.Image = CurrImage; 没有创建一个新的位图我没有得到这个错误,但线程将有竞争条件异常.
我有一个imageView,画布和一个按钮..当我点击按钮时,在画布上绘制一个位图
我想使用我的onTouch移动该位图(将位图拖动到画布上的任何位置).
s.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View v, int position, long id) {
Bitmap workingBitmap = Bitmap.createBitmap(currentBitmap);
workingBitmap = Bitmap.createBitmap(workingBitmap);
Canvas c = new Canvas(workingBitmap);
brightBitmap = BitmapFactory.decodeResource(getResources(), sIds.mSmileyIds[position], null);
brightBitmap = Bitmap.createScaledBitmap(brightBitmap, 100, 100, false);
chosenSmiley = brightBitmap;
if (chosenSmiley != null) {
try {
c.drawBitmap(chosenSmiley, posX, posY, null);
} catch (Exception e) {
e.printStackTrace();
}
}
iv.setImageBitmap(workingBitmap);
}
public boolean onTouchEvent(MotionEvent event) {
int eventaction = event.getAction();
switch (eventaction) {
case MotionEvent.ACTION_DOWN:
// finger touches …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我使用LayerDrawable来显示覆盖图像.我这样做是成功使用layerDrawable.
之后我将layerDrawable设置为imageView.setImageDrawable(layerDrawable);
现在我想使用这个图像drawable take作为Bitmap并在下一个图像处理中使用.但是当我试图让Bitmap使用它时
((BitmapDrawable)imageLayout.getDrawable()).getBitmap();
Run Code Online (Sandbox Code Playgroud)
我得到以下错误.
04-04 12:56:02.102: E/AndroidRuntime(15127): java.lang.ClassCastException: android.graphics.drawable.LayerDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
Run Code Online (Sandbox Code Playgroud)
所以我改变了我的图像处理的跟随并尝试将LayerDrawable转换为Drawable并将此drawable设置为imageLayout backGround.那就完美了. 我的问题是如何将LayerDrawable转换为drwable?
请任何一个帮助.给我一些想法.谢谢.
我正在制作棋盘游戏,而我正在使用10x10 GridView作为棋盘.我创建了一个扩展BaseAdapter的ImageAdapter类,它包含一个Integer数组图标(9个补丁文件),这些用于显示电路板方块的图像.图标存储在res/drawable文件夹中,为629X629,平均大小约为5 KB.
我的ImageAdapter类具有以下getView()方法,它基本上循环使用相同的视图来节省内存:
编辑 :(我已经包含了在游戏的Activity中调用的changeIcon方法)
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
}
else{
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
public void changeIcon(int x, int y, Integer icon){
int position = (9-y)*10 + x;
mThumbIds[position] = icon;
getView(position, currentView, null);
}
Run Code Online (Sandbox Code Playgroud)
我有一个名为Game的独立类,其中处理游戏的逻辑.我将这些碎片存储在Piece [] []数组中,其中Piece是我用来保存游戏数据(你猜对了)的另一个类.相关的是处理片段移动的方法move(int xFrom,int yFrom,int xTo,int …
所以我使用下一个代码从blob创建一个位图:
byte[] blob = contact.getMP();
ByteArrayInputStream inputStream = new ByteArrayInputStream(blob);
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
Bitmap scalen = Bitmap.createScaledBitmap(bitmap, 320, 240, false);
Run Code Online (Sandbox Code Playgroud)
并且它返回下一个输出,这很好

然后我执行以下操作将位图制作成Mat,但随后我的颜色才会改变......
//Mat ImageMat = new Mat();
Mat ImageMat = new Mat(320, 240, CvType.CV_32F);
Utils.bitmapToMat(scalen, ImageMat);
Run Code Online (Sandbox Code Playgroud)
我不知道为什么,也不知道将位图变成Mat的另一种方法.怎么了?

我有两个位图.这是位图1:

这是位图2:

最终结果应为:

我会很感激代码,但是,我更感谢对文档或教程的引用.我想完全理解代码,我一直在developer.android.com上搜索这么久没有运气.谢谢.