我正在研究Android游戏,并且出现了一些问题,我想在位图对象上填充颜色,但我不能尝试bitmap.setPixel但我的图像是PNG格式(如圆形或不锐化,用透明色包围)和android不能getHeight()或getWidth(),即
ImageView i = new ImageView(mContext); Bitmap bMap = BitmapFactory.decodeResource(this.mContext.getResources(), mImageIds[position]);Run Code Online (Sandbox Code Playgroud)// for(int i1 = 0; i1 < bMap.getHeight();i1++) // for(int j = 0; j < bMap.getWidth(); j ++) // bMap.setPixel(i1, j, Color.RED); //can not set
i.setImageBitmap(bMap); i.setLayoutParams(new Gallery.LayoutParams(150, 100)); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setBackgroundResource(mGalleryItemBackground); i.setBackgroundColor(Color.TRANSPARENT);
1.我是Android编码的新手:)
我所做的是从res/drawable-mdpi加载一个Bitmap
BitmapFactory.decodeResource(getResources(), R.drawable.cat_ground_01);
Run Code Online (Sandbox Code Playgroud)
在我注销Bitmap的宽度/高度后,它告诉我另一个值,然后Bitmap真的是.
有点难以放置Bitmaps pixelperfect,例如将脸部的位图与嘴位图重叠.
也许我只是缺少一些关于这个主题的知识:9我希望你能提供帮助.
如何在C++中将窗口的屏幕截图作为位图对象?假设我已经有了窗口句柄.而且我想知道当窗口处于最小化状态时是否可以获取窗口的屏幕截图?
这里的C++意味着VC++包含与Windows XP +(win32)相关的所有库.
我正试图在C中创建一个位图,只是来自代码.我目前正在尝试制作一个非常简单的.bmp图像,高度为1像素,宽度为4像素,所有白色像素.我已阅读格式说明并尝试应用它.这导致以下代码:
char bitmap[1000];
void BMPmake()
{
// -- FILE HEADER -- //
// bitmap signature
bitmap[0] = 'B';
bitmap[1] = 'M';
// file size
bitmap[2] = 66; // 40 + 14 + 12
bitmap[3] = 0;
bitmap[4] = 0;
bitmap[5] = 0;
// reserved field (in hex. 00 00 00 00)
for(int i = 6; i < 10; i++) bitmap[i] = 0;
// offset of pixel data inside the image
for(int i = 10; i < 14; i++) bitmap[i] = …Run Code Online (Sandbox Code Playgroud) 以下是一个神奇的公式,它给出了一个数字中设置的位数(汉明重量).
/*Code to Calculate count of set bits in a number*/
int c;
int v = 7;
v = v - ((v >> 1) & 0x55555555); // reuse input as temporary
v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp
c = ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count
printf(" Number of Bits is %d",c);
/*-----------------------------------*/
Run Code Online (Sandbox Code Playgroud)
来自:http: //graphics.stanford.edu/~seander/bithacks.html
有谁能解释一下这背后的理由?
我有一个加载的位图,我想转换为将配置设置为Bitmap.Config.RGB_565.Bitmap在Bitmap已经加载到内存后,是否有一种简单的方法将a 转换为此配置?例如,下面我有一个从应用程序资源解码的位图,但是,我如何将已经加载的转换Bitmap为RGB_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) 我在这里有点失落.我必须将位图从裁剪图像转换为.jpeg文件.我已经查看了其他相关问题,但没有一个与我相关.(大多数都被恢复为文件到位图)
提前致谢
PS.第一次Android开发
我正在开发一个使用大图像(1390×870:150kb - 50kb)的应用程序.当我点击触发器/ ImageView时,我正在添加图像.
在某一点上,我得到一个内存不足的错误:
java.lang.OutOfMemoryError
E/AndroidRuntime(23369): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
E/AndroidRuntime(23369): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:613)
E/AndroidRuntime(23369): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:378)
Run Code Online (Sandbox Code Playgroud)
为了调整图像大小,我正在这样做:
Bitmap productIndex = null;
final String imageLoc = IMAGE_LOCATION;
InputStream imageStream;
try {
imageStream = new FileInputStream(imageLoc);
productIndex = decodeSampledBitmapFromResource(getResources(), imageLoc, 400, 400);
productIV.setImageBitmap(productIndex);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
public static Bitmap decodeSampledBitmapFromResource(Resources res, String resId, int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options(); …Run Code Online (Sandbox Code Playgroud)