Bitmap XML和BitmapDrawable应用实例

bitmap_xml.xml

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:src="@drawable/beauty1"
    android:tileMode="disabled" >
</bitmap>
activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:background="@drawable/bitmap_xml" >
</RelativeLayout>

MainActivity.java

package com.sean.bitmapxml;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}
}

这里值得注意的有应用性的是android:tileMode这一属性。它的四个值效果图如下:

repeatmirrorclampdisabled

再来解释下android:dither的作用——图像的抖动处理,当每个颜色值以低于8位表示时,对应图像做抖动处理可以实现在可显示颜色总数比较低(比如256色)时还保持较好的显示效果。

以上是用bitmap XML应用bitmap资源,下面演示了代码实现,则要应用到BitmapDrawable:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.beauty1);
BitmapDrawable bd = new BitmapDrawable(bitmap);
bd.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
bd.setDither(true);
view.setBackgroundDrawable(bd);



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
BITMAP调度算法是一种常用的内存管理算法,用于管理分配和释放内存块。下面是一个使用C语言实现BITMAP调度算法的示例代码: ```c #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #define MAX_BLOCKS 1024 #define BLOCK_SIZE 4096 typedef struct { unsigned char* bitmap; unsigned char* memory; } BitmapScheduler; BitmapScheduler* createScheduler() { BitmapScheduler* scheduler = (BitmapScheduler*)malloc(sizeof(BitmapScheduler)); scheduler->bitmap = (unsigned char*)calloc(MAX_BLOCKS / 8, sizeof(unsigned char)); scheduler->memory = (unsigned char*)malloc(MAX_BLOCKS * BLOCK_SIZE * sizeof(unsigned char)); return scheduler; } void destroyScheduler(BitmapScheduler* scheduler) { free(scheduler->bitmap); free(scheduler->memory); free(scheduler); } void* allocateBlock(BitmapScheduler* scheduler) { for (int i = 0; i < MAX_BLOCKS; i++) { int byteIndex = i / 8; int bitIndex = i % 8; if ((scheduler->bitmap[byteIndex] & (1 << bitIndex)) == 0) { scheduler->bitmap[byteIndex] |= (1 << bitIndex); return scheduler->memory + (i * BLOCK_SIZE); } } return NULL; } void freeBlock(BitmapScheduler* scheduler, void* block) { int blockIndex = ((unsigned char*)block - scheduler->memory) / BLOCK_SIZE; int byteIndex = blockIndex / 8; int bitIndex = blockIndex % 8; scheduler->bitmap[byteIndex] &= ~(1 << bitIndex); } void printBitmap(BitmapScheduler* scheduler) { printf("Bitmap:\n"); for (int i = 0; i < MAX_BLOCKS; i++) { int byteIndex = i / 8; int bitIndex = i % 8; bool allocated = (scheduler->bitmap[byteIndex] & (1 << bitIndex)) != 0; printf("%d ", allocated); if ((i + 1) % 32 == 0) { printf("\n"); } } } int main() { BitmapScheduler* scheduler = createScheduler(); // 分配内存块 void* block1 = allocateBlock(scheduler); void* block2 = allocateBlock(scheduler); void* block3 = allocateBlock(scheduler); // 释放内存块 freeBlock(scheduler, block2); // 打印位图 printBitmap(scheduler); destroyScheduler(scheduler); return 0; } ``` 这个示例代码实现了BITMAP调度算法的内存分配和释放功能。通过`allocateBlock`函数可以分配一个内存块,通过`freeBlock`函数可以释放一个内存块。`printBitmap`函数用于打印当前的位图情况。 希望对你有帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值