我正在使用Bitmap C#并想知道如何将颜色png图像转换为仅一种颜色.我希望图像中的所有可见颜色都变白.透明的部分应保持透明.我将以灰色背景显示这些.
11-24 23:19:18.434: ERROR/AndroidRuntime(12660): Uncaught handler: thread main exiting due to uncaught exception
11-24 23:19:18.684: ERROR/AndroidRuntime(12660): java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@4384c218
11-24 23:19:18.684: ERROR/AndroidRuntime(12660): at android.graphics.Canvas.throwIfRecycled(Canvas.java:955)
11-24 23:19:18.684: ERROR/AndroidRuntime(12660): at android.graphics.Canvas.drawBitmap(Canvas.java:1044)
11-24 23:19:18.684: ERROR/AndroidRuntime(12660): at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:291)
11-24 23:19:18.684: ERROR/AndroidRuntime(12660): at android.widget.ImageView.onDraw(ImageView.java:908)
11-24 23:19:18.684: ERROR/AndroidRuntime(12660): at android.view.View.draw(View.java:6283)
11-24 23:19:18.684: ERROR/AndroidRuntime(12660): at android.view.ViewGroup.drawChild(ViewGroup.java:1581)
11-24 23:19:18.684: ERROR/AndroidRuntime(12660): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1311)
11-24 23:19:18.684: ERROR/AndroidRuntime(12660): at android.view.ViewGroup.drawChild(ViewGroup.java:1579)
11-24 23:19:18.684: ERROR/AndroidRuntime(12660): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1311)
11-24 23:19:18.684: ERROR/AndroidRuntime(12660): at android.view.View.draw(View.java:6286)
11-24 23:19:18.684: ERROR/AndroidRuntime(12660): at android.view.ViewGroup.drawChild(ViewGroup.java:1581)
11-24 …Run Code Online (Sandbox Code Playgroud) 试图调整存储在我的SD卡上的图像的大小,我注意到原始颜色在哪里被改变了.它接缝BitmapFactory.decodeFile对此负责.这是一个演示代码:
private void testImage() throws Exception{
BitmapFactory.Options o = new BitmapFactory.Options();
o.inDither = false;
o.inPreferredConfig = Bitmap.Config.ARGB_8888;
o.inScaled = false;
Bitmap b = BitmapFactory.decodeFile("/sdcard/test/original.jpg", o);
b.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream("/sdcard/test/result.jpg"));
b.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream("/sdcard/test/result.png"));
}
Run Code Online (Sandbox Code Playgroud)
结果图像(original.jpg,result.jpg,result.png):



你有没有看到,男孩的皮肤在2张图片上有点绿.解决这个问题的任何提示?
我似乎无法通过搜索得到明确的答案.Win32 blitting操作硬件是否加速(GDI,而不是GDI +).我不知道这些功能如何与图形驱动程序连接.是否有任何函数调用来验证此功能,例如?GetCaps?对于特定的图形设备(win32图形设备),看看这些功能是否正在接收硬件加速?
我正在尝试旋转此图像上的一个透明PNG.数字部分是我想要旋转的部分.我能够做到这一点,但这不是我想要实现的目标
http://i48.tinypic.com/25exzle.png
我想像真正的密码锁一样旋转数字.因此,用户将触摸并将他们的手指移动一圈.我在触摸/移动事件中看到了不太精确的图像旋转,但它们还不够.
这是我目前的代码
public boolean onTouch(View v, MotionEvent event) {
double r=Math.atan2(event.getX()-lockNumbers.getWidth(), lockNumbers.getHeight()-event.getY());
int rotation=(int)Math.toDegrees(r);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
x=event.getX();
y=event.getY();
updateRotation(rotation);
break;
case MotionEvent.ACTION_UP:
break;
}//switch
return true;
}//onTouch
private void updateRotation(double rot){
float newRot=new Float(rot);
Bitmap bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.numbers);
Matrix matrix=new Matrix();
matrix.postRotate(newRot,bitmap.getWidth(),bitmap.getHeight());
if(y>250){
Bitmap reDrawnBitmap=Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
lockNumbers.setImageBitmap(reDrawnBitmap);
}
else{
Bitmap reDrawnBitmap=Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
lockNumbers.setImageBitmap(reDrawnBitmap);
}
}
Run Code Online (Sandbox Code Playgroud)
由于矩阵参数,它也会在触摸时调整位图的大小.这不是理想的效果.
用户几乎需要用手指进入一个圆圈.
我试图沿矩形绘制位图,但我不知道如何去做.有没有办法使用paint属性或其他东西沿Rect对象平铺位图?我看了,但是我找不到任何能让它做我需要的东西,大多数的平铺选项都不会为特定的实例平铺它们,它们会在整个屏幕上平铺它,所以使用该位图的一切都结束了在没有滚动或任何东西的情况下,同时沿着所有这些位图平铺一个大位图.
有任何想法吗?如果您需要更多信息让我知道,这是一个奇怪的问题所以我知道我可能没有提到重要的事情.
威廉
我目前有一个5 x 5平方的迷宫游戏(占用屏幕宽度并均匀分割).然后,对于使用x和y坐标的每个框,我使用drawRect来绘制彩色背景.
我遇到的问题是我现在需要在同一位置绘制图像,因此替换当前的普通背景颜色填充.
这是我目前用于drawRect的代码(一些例子):
// these are all the variation of drawRect that I use
canvas.drawRect(x, y, (x + totalCellWidth), (y + totalCellHeight), green);
canvas.drawRect(x + 1, y, (x + totalCellWidth), (y + totalCellHeight), green);
canvas.drawRect(x, y + 1, (x + totalCellWidth), (y + totalCellHeight), green);
Run Code Online (Sandbox Code Playgroud)
然后我还需要为画布中的所有其他方块实现背景图像.此背景将在其顶部绘制简单的1px黑色线条,当前代码以灰色背景绘制.
background = new Paint();
background.setColor(bgColor);
canvas.drawRect(0, 0, width, height, background);
Run Code Online (Sandbox Code Playgroud)
如果可能的话,请你指点一下.如果是这样,那么我可以做的最好的方法是什么,同时尽量减少内存使用量并使1个图像扩展和缩小以填充相关的方形空间(这会因所有不同的屏幕尺寸而变化,因为它会分裂整体屏幕宽度均匀).
我将4x4 imageView放入活动(BoardActivity),用户可以通过单击更改图像.使用HTC Desire(Android 2.2.2),我在大约30分钟的密集使用中获得了OOM(Out Of Memory)-EDIT:此活动的第16次开始 -但是没有其他设备产生这个(android 2.1和android 2.2.1) ).是否有可能,我在bitmap/imageview使用中犯了一些错误并导致此错误?首先,我将所有资源ID加载到地图中:
private Map<String, Integer> imageResourceMap;
imageResourceMap = new HashMap<String, Integer>();
imageResourceMap.put("a", R.drawable.a);
imageResourceMap.put("b", R.drawable.b);
imageResourceMap.put("c", R.drawable.c);
//... I store 55 drawable's resourceId in this map
Run Code Online (Sandbox Code Playgroud)
然后我调整大小并将每个图像保存到位图中,在Map中表示:
private static Map<String, Bitmap> imageBitmap;
private void loadBitmaps(int imagesSize) {
for (String s : imageResourceMap.keySet()) {
Bitmap tmp = getBitmapFromRes(imageResourceMap.get(s), imagesSize);
imageBitmap.put(s, tmp);
}
}
private Bitmap getBitmapFromRes(int resId, int imageSize) {
Bitmap b = null;
try {
// Decode image size
BitmapFactory.Options …Run Code Online (Sandbox Code Playgroud) 不能理解这段代码有什么问题:
HBITMAP bm = 0;
BITMAP Bitmap;
bm = (HBITMAP)LoadImage (0, path, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
int error = GetObject( &Bitmap, sizeof( BITMAP ), &bm );
Run Code Online (Sandbox Code Playgroud)
LoadImage函数返回非空指针.但GetObject返回0,表示出错.我想从HBITMAP指针获取大小信息和图像数据(指针可以作为参数传递,所以我不能改变我加载位图文件的方式).
我正在使用一个Image Loader,它从URL加载图像并缓存到我的文件系统中.我发现使用ACRA的手机很少有以下崩溃报告
错误:
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493)
at com.m7.nomad.utils.ImageLoader.decodeFile(ImageLoader.java:117)
at com.m7.nomad.utils.ImageLoader.getBitmap(ImageLoader.java:88)
at com.m7.nomad.utils.ImageLoader.access$0(ImageLoader.java:68)
at com.m7.nomad.utils.ImageLoader$PhotosLoader.run(ImageLoader.java:170)
Run Code Online (Sandbox Code Playgroud)
ImageLoader.java
package com.m7.nomad.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Collections;
import java.util.Map;
import java.util.Stack;
import java.util.WeakHashMap;
import com.m7.nomad.R;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.widget.ImageView;
public class ImageLoader {
MemoryCache memoryCache = new MemoryCache();
FileCache fileCache;
private Map<ImageView, String> imageViews = Collections …Run Code Online (Sandbox Code Playgroud)