我有一個需要旋轉位圖的項目,位圖處於灰度/黑白模式。當我旋轉該位圖時,它可以工作,但背景(位圖的白色部分)也會旋轉。無論如何只旋轉前景(位圖的非白色部分)?或者如果我必須創建一個新功能來做到這一點,你能解釋一下算法嗎?android:如何在不旋轉背景的情況下旋轉位圖前景
感謝您的幫助..
我編輯了相關代碼:
int i;
InputStream inStream = context.getResources().openRawResource(R.raw.register2);
BufferedInputStream bis = new BufferedInputStream(inStream, 8000);
DataInputStream dis=new DataInputStream(bis);
byte[] music=null;
try {
music = new byte[inStream.available()];
i=0;
while(dis.available()>0)
{
music[i]=dis.readByte();
i++;
}
dis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bitmap bm = Bitmap.createBitmap(260, 300, Bitmap.Config.ARGB_8888);
ByteBuffer byteBuff=ByteBuffer.allocate(260*300);
bm.setHasAlpha(false);
if(false)
byteBuff.put(music);
int[] intbuffer = new int[260*300];
for (int x=0; x<intbuffer.length; ++x)
intbuffer[x] = (int) music[x];
bm.setPixels(intbuffer, 0, 260, 0, 0, 260, 300);
//img1.setImageBitmap(bm);
//Canvas canvas=new Canvas(bm);
Matrix matrix=new Matrix();
matrix.postRotate(-90);
Bitmap rotated=Bitmap.createBitmap(bm, 0, 0, 260, 300, matrix, true);
//matrix.setRotate(4,bm.getWidth()/2,bm.getHeight()/2);
//canvas.drawBitmap(bm, matrix, new Paint());
img1.setImageBitmap(rotated);
請張貼相關的代碼 – Peshal
我會考慮使用帶alpha通道的圖像格式(例如png)和透明背景。這很容易 –
Peshal:我編輯了我的問題。 – user1290932