1.Bitmap使ç¨è¯¦è§£
2.BitMapåçä¸å®ç°
3.BMP图像解码器源代码?C++编的源码滚动 画册 源码
Bitmap使ç¨è¯¦è§£
ç¨å°çå¾çä¸ä» ä» å æ¬.pngã.gifã.9.pngã.jpgååç§Drawable系对象ï¼è¿å æ¬ä½å¾Bitmap
å¾ççå¤çä¹ç»å¸¸æ¯å½±åçä¸ä¸ªç¨åºçé«ææ§åå¥å£®æ§ã
为ä»ä¹ä¸ç´æ¥ç¨Bitmapä¼ è¾ï¼
ä½å¾æ件è½å¥½ï¼ä½æ¯éåç¼©æ ¼å¼ï¼å ç¨è¾å¤§åå¨ç©ºé´ã
Bitmap主è¦æ¹æ³æï¼è·åå¾å宽é«ãéæ¾ï¼å¤ææ¯å¦å·²éæ¾åæ¯å¦å¯ä¿®æ¹ï¼å缩ãå建å¶å®ä½å¾çåè½
ç¨äºä»ä¸åçæ°æ®æº(å¦æ件ãè¾å ¥æµãèµæºæ件ãåèæ°ç»ãæ件æ述符ç)解æãå建Bitmap对象
å 许æ们å®ä¹å¾ç以ä½ç§æ¹å¼å¦ä½è¯»å°å åã
æ¨èé è¯»ï¼ Android - Bitmap-å ååæ
注æäºé¡¹ï¼
decodeFileDescriptoræ¯decodeFileé«æ
æ¥çæºç å¯ä»¥ç¥é
æ¿æ¢æ
建议éç¨decodeStream代æ¿decodeResourceã
å 为BitmapFactory.decodeResource å è½½çå¾çå¯è½ä¼ç»è¿ç¼©æ¾ï¼è¯¥ç¼©æ¾ç®åæ¯æ¾å¨ java å±åçï¼æçæ¯è¾ä½ï¼èä¸éè¦æ¶è java å±çå åãå æ¤ï¼å¦æ大é使ç¨è¯¥æ¥å£å è½½å¾çï¼å®¹æ导è´OOMé误ï¼BitmapFactory.decodeStream ä¸ä¼å¯¹æå è½½çå¾çè¿è¡ç¼©æ¾ï¼ç¸æ¯ä¹ä¸å ç¨å åå°ï¼æçæ´é«ã
è¿ä¸¤ä¸ªæ¥å£åæç¨å¤ï¼å¦æ对æ§è½è¦æ±è¾é«ï¼ååºè¯¥ä½¿ç¨ decodeStreamï¼å¦æ对æ§è½è¦æ±ä¸é«ï¼ä¸éè¦ Android èªå¸¦çå¾çèªéåºç¼©æ¾åè½ï¼åå¯ä»¥ä½¿ç¨ decodeResourceã
æ¨èé 读ï¼[ BitmapFactory.decodeResourceå è½½å¾ç缩å°çåå å解å³æ¹æ³
canvasåMatrixå¯å¯¹Bitmapè¿è¡æ转ãæ¾ç¼©ã平移ãåéçæä½
å¯ä»¥ç¨Bitmap.onCreateBitmapãCanvasçclipRectåclipPathççæ¹å¼
æ¨èé è¯»ï¼ androidèªå®ä¹Viewå¦ä¹ 4--å¾ååªåä¸åæ¢
对åå§åBitmap对象è¿ç¨ä¸å¯è½åççOutOfMemoryå¼å¸¸è¿è¡äºæè·ãå¦æåçäºOutOfMemoryå¼å¸¸ï¼åºç¨ä¸ä¼å´©æºï¼èæ¯å¾å°äºä¸ä¸ªé»è®¤çBitmapå¾ã
å¦æä¸è¿è¡ç¼åï¼å°½ç®¡çå°çæ¯åä¸å¼ å¾çæ件ï¼ä½æ¯ä½¿ç¨BitmapFactoryç±»çæ¹æ³æ¥å®ä¾ååºæ¥çBitmapï¼æ¯ä¸åçBitmap对象ãç¼åå¯ä»¥é¿å æ°å»ºå¤ä¸ªBitmap对象ï¼é¿å å åç浪费ã
å¦æå¾çåç´ è¿å¤§ï¼ä½¿ç¨BitmapFactoryç±»çæ¹æ³å®ä¾åBitmapçè¿ç¨ä¸ï¼éè¦å¤§äº8Mçå å空é´ï¼å°±å¿ å®ä¼åçOutOfMemoryå¼å¸¸ã
å¯ä»¥å°å¾ç缩å°ï¼ä»¥åå°è½½å ¥å¾çè¿ç¨ä¸çå åç使ç¨ï¼é¿å å¼å¸¸åçã
æ¨èé 读ï¼
Bitmap详解ä¸Bitmapçå åä¼å
BitMapåçä¸å®ç°
æ¯è¾ç»å ¸çé®é¢æ¯ï¼ å¨åªè½å¤ä½¿ç¨2Gçå åä¸ï¼å¦ä½å®æ以ä¸æä½ï¼â ï¼å¯¹äº¿ä¸ªä¸éå¤çæ´æ°è¿è¡æåºã
â¡ï¼æ¾åºäº¿ä¸ªæ°åä¸éå¤çæ°åã
æ 论æ¯æåºè¿æ¯æ¾éå¤çæ°åé½éè¦å°è¿äº¿ä¸ªæ°åå å ¥å°å åä¸å¨å»è¿è¡æä½ï¼å¾ææ¾ï¼é¢ç®ç»åºç2Gå åéå¶è¯´æäºå¨è¿æ ·çåºæ¯ä¸æ¯ä¸è½å¤å°æææ°é½å å ¥å°å åä¸ç
* 4/ï¼* * ï¼ = 3.G
é£ä¹è¿æ¶åå°±éè¦ç¨å° BitMapç»æäº
bitMap使ç¨ä¸ä¸ªbit为0/1ä½ä¸ºmapçvalueæ¥æ è®°ä¸ä¸ªæ°åæ¯å¦åå¨,èmapçkeyå¼æ£æ¯è¿ä¸ªæ°åæ¬èº«ã
ç¸æ¯äºä¸è¬çæ°æ®ç»æéè¦ç¨4个byteå»åå¨æ°å¼æ¬èº«ï¼ç¸å½äºæ¯èçäº 4*8ï¼1 = åçå å空é´
bitMapä¸ä¸å®è¦ç¨bitæ°ç»,å¯ä»¥ä½¿ç¨ int,longçççåºæ¬æ°æ®ç±»åå®ç°ï¼å ä¸ºå ¶å®è´¨é½æ¯å¨bitä½ä¸åæ°æ®ï¼ç¨åªç§ç±»ååªæ¯å³å®äºæç»å®ç°åºæ¥çBitMapçå ç½®æ°ç»ä¸å个å ç´ åæ¾æ°æ®çå¤å°
ä¾å¦ï¼javaä¸çBitSet使ç¨Longæ°ç»
BitMapçå®ç°å½ç¶å°ä¸äºä½è¿ç®ï¼å æ¥æç¡®å 个常è§ä½è¿ç®ï¼è¿æ¯å®ç°BitMapçåºç¡ï¼
set(bitIndex): æ·»å æä½
1 .ç¡®å®è¯¥æ°å¤äºæ°ç»ä¸çåªä¸ªå ç´ çä½ä¸
int wordIndex = bitIndex >> 5;
å 为æç¨çæ¯int[]å®ç°ï¼æ以è¿éå³ç§» 5 ä½ï¼2^5 = ï¼
2 .ç¡®å®ç¸å¯¹äºè¯¥å ç´ ä¸çä½ç½®å移
int bitPosition = bitIndex & ((1 << 5) - 1);
è¿éç¸å½äºæ¯ bitIndex % ï¼1<<5ï¼çå模è¿ç®ï¼å 为å½å模è¿ç®çé¤æ°æ¯2ç次å¹ï¼æ以å¯ä»¥ä½¿ç¨ä»¥ä¸çä½è¿ç®æ¥è®¡ç®ï¼æåæçï¼å¯¹æ¯HashMapç容é为ä»ä¹æ»æ¯2çå¹æ¬¡æ¹çé®é¢ï¼HashMapæ±ä¸æ æ¶ä¹æ¯ä½¿ç¨ hash&(n-1)ï¼
tips: ä½è¿ç®çä¼å 级æ¯ä½äº+,-çççï¼æ以è¦å ä¸æ¬å·,é²æ¢åçä¸å¯æè¿°çé误
3 .å°è¯¥ä½ç½®1
bits[wordIndex] |= 1 << bitPosition;
ç¸å½äºæ¯å°æå®ä½ç½®å¤çbitå¼ç½®1ï¼å ¶ä»ä½ç½®ä¿æä¸åï¼ä¹å°±æ¯å°ä»¥è¿ä¸ªbitIndex为keyçä½ç½®ä¸º1
tips: è¿éæ¯åèäºç½ä¸çåä½å¤§ä½¬çæç« ,åä½ + æä½æï¼å对æ¯äºä¸BitSetçæºç ï¼
words[wordIndex] |= (1L << bitIndex);
没æåä½æä½ï¼ç´æ¥|ï¼è¿ä¸¤ä¸ªä¸æ ·åï¼çæ¡å½ç¶æ¯ä¸æ ·ç
举个æ åï¼
1 << == 1<<
1L << ==1L<<
å³å¯¹äºintålongåæ°æ®ï¼ç´æ¥å·¦ç§»å ¶ä½æ°ç¸å½äºæ¯é带äºå¯¹å ¶çå模æä½
æ»ç»ï¼ä½¿ç¨Bit-mapçææ³ï¼æ们å¯ä»¥å°åå¨ç©ºé´è¿è¡å缩ï¼èä¸å¯ä»¥å¯¹æ°åè¿è¡å¿«éæåºãå»éåæ¥è¯¢çæä½ã
Bloom Fliteræ¯Bit-mapææ³çä¸ç§æ©å±ï¼å®å¯ä»¥å¨å 许ä½é误ççåºæ¯ä¸ï¼å¤§å¤§å°è¿è¡ç©ºé´å缩ï¼æ¯ä¸ç§æ¿é误çæ¢å空é´çæ°æ®ç»æ
å½ä¸ä¸ªå ç´ å å ¥å¸éè¿æ»¤å¨ä¸çæ¶åï¼ä¼è¿è¡åªäºæä½ï¼
å½æ们éè¦å¤æä¸ä¸ªå ç´ æ¯å¦åå¨äºå¸éè¿æ»¤å¨çæ¶åï¼ä¼è¿è¡åªäºæä½ï¼
ç¶åï¼ä¸å®ä¼åºç°è¿æ ·ä¸ç§æ åµï¼ä¸åçå符串å¯è½åå¸åºæ¥çä½ç½®ç¸åï¼å¯ä»¥éå½å¢å ä½æ°ç»å¤§å°æè è°æ´æ们çåå¸å½æ°æ¥éä½æ¦çï¼,å æ¤ï¼å¸éè¿æ»¤å¨å¯è½ä¼åå¨è¯¯å¤çæ åµ
æ»ç»æ¥è¯´å°±æ¯ï¼ å¸éè¿æ»¤å¨è¯´æ个å ç´ åå¨ï¼å°æ¦çä¼è¯¯å¤ãå¸éè¿æ»¤å¨è¯´æ个å ç´ ä¸å¨ï¼é£ä¹è¿ä¸ªå ç´ ä¸å®ä¸å¨ã
Bloom Filterçåºç¨: 常ç¨äºè§£å³ç¼åç©¿éçåºæ¯ã
BMP图像解码器源代码?C++编的
#include <jpeg.hpp>
void Bitmap2Jpeg(AnsiString bmpFile, AnsiString jpegFile)
{
Graphics::TBitmap *bitmap = new Graphics::TBitmap();
bitmap->LoadFromFile(bmpFile);
TJPEGImage *jpeg = new TJPEGImage();
try {
jpeg->Assign(bitmap);
jpeg->SaveToFile(jpegFile);
}
__finally {
delete jpeg;
}
delete bitmap;
}
void Jpeg2Bitmap(AnsiString jpegFile, AnsiString bmpFile)
{
Graphics::TBitmap *bmp = new Graphics::TBitmap();
TJPEGImage *jpeg = new TJPEGImage();
jpeg->LoadFromFile(jpegFile);
bmp->Assign(jpeg);
bmp->SaveToFile(bmpFile);
delete jpeg;
delete bmp;
}