标签: bitmap

使用Delphi XE从资源加载时如何保留PNGImage掩码

我正在将我的代码升级到Delphi XE(来自Delphi 7),并试图消除所有不必要的库.我已经使用了PNGComponents很多年了,但现在是时候继续使用原生的TImageList和TPNGImage了.

我的部分代码在运行时从链接的资源中加载图像列表.我的工作PNGComponents代码是:

function CreateAndLoadImageList( ASize : integer ) : TPngImageList;
var
  PngObject : TPngObject;
  I : integer;
begin
  Result := TPngImageList.Create( nil );

  Result.BeginUpdate;
  try

    Result.Width := ASize;
    Result.Height := ASize;

    PngObject := TPngObject.create;
    try

      For I := 0 to Length( ArtImageNames ) -1 do
        begin
        PngObject.LoadFromResourceName( hInstance, Format( 'AImg%d_%d', [ASize, I]));

        Result.PngImages.Add( False).PngImage := PngObject;
        end;

    finally
      PngObject.Free;
    end;


  finally
    Result.EndUpdate;
  end;

end;
Run Code Online (Sandbox Code Playgroud)

在这个问题中使用答案我现在正在尝试下面的代码,其中显示了图像,但是背景为黑色,大概是因为蒙版丢失了.我想我需要一个掩码位图来传递给ImageList_Add,其中'0'但是我对这个东西很差.有谁知道我怎么会这样工作?

function CreateAndLoadImageList( ASize : integer ) : TImageList;
var
  PngImage : …
Run Code Online (Sandbox Code Playgroud)

delphi png bitmap timagelist

5
推荐指数
1
解决办法
1843
查看次数

Bitmap.getPixels()中的IllegalArgumentException

我想将数据从Bitmap复制到int[]using getPixels(),这是我目前的代码:

int[] pixels = new int[myBitmap.getHeight() * myBitmap.getWidth()];
myBitmap.getPixels(pixels, 0, myBitmap.getWidth(), 0, 0,
        myBitmap.getHeight(), myBitmap.getWidth());

for(int i = 0; i < myBitmap.getHeight() * myBitmap.getWidth(); i++) {
    Log.e(TAG, "pixel"+i+"" +pixels[i]);
}
Run Code Online (Sandbox Code Playgroud)

但这是一个例外:

05-04 20:24:08.281: ERROR/AndroidRuntime(5700): Uncaught handler: thread main exiting due to uncaught exception
05-04 20:24:08.296: ERROR/AndroidRuntime(5700): java.lang.IllegalArgumentException: y + height must be <= bitmap.height()
05-04 20:24:08.296: ERROR/AndroidRuntime(5700):     at android.graphics.Bitmap.checkPixelsAccess(Bitmap.java:818)
05-04 20:24:08.296: ERROR/AndroidRuntime(5700):     at android.graphics.Bitmap.getPixels(Bitmap.java:771)
05-04 20:24:08.296: ERROR/AndroidRuntime(5700):     at com.tecmark.Jjilapp$TouchView.onDraw(Jjilapp.java:206)
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?我刚刚将y参数指定为0.

android bitmap pixels

5
推荐指数
2
解决办法
2万
查看次数

在2D转换后获得在画布上测量的位图大小和位置

我在Canvas上绘制了一堆位图,应用了2D变换(android.graphics.Camera和android.graphics.Matrix).如何在Canvas上获取位图的大小/位置?大小将是在Canvas上渲染的位图的边界,位置将是边界的上/左角的坐标.所有位图都是没有alpha通道的常规矩形.

android canvas bitmap

5
推荐指数
1
解决办法
1462
查看次数

在android中结合图像

如何通过在java中编程并在外部SD卡或其他地方保存来合并android中的两个图像.

android image bitmap

5
推荐指数
2
解决办法
9073
查看次数

为什么我得到java.io.IOException:Mark已失效?

我正在尝试从网址下载imags然后解码它们.问题是,我不知道它们有多大,如果我立即解码它们,应用程序会因太大的图像而崩溃.

我正在做以下操作,它适用于大多数图像,但是对于其中一些图像,它会抛出java.io.IOException: Mark has been invalidated异常.这不是一个大小问题,因为它发生在75KB或120KB的图像上,而不是20MB或45KB的图像.此格式也不重要,因为它可能发生在jpg或png图像上.

pis是一个InputStream.

    Options opts = new BitmapFactory.Options();
    BufferedInputStream bis = new BufferedInputStream(pis);
    bis.mark(1024 * 1024);
    opts.inJustDecodeBounds = true;
    Bitmap bmImg=BitmapFactory.decodeStream(bis,null,opts);

    Log.e("optwidth",opts.outWidth+"");
    try {
        bis.reset();
        opts.inJustDecodeBounds = false;
        int ratio = opts.outWidth/800; 
        Log.e("ratio",String.valueOf(ratio));
        if (opts.outWidth>=800)opts.inSampleSize = ratio;

        return BitmapFactory.decodeStream(bis,null,opts);

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }
Run Code Online (Sandbox Code Playgroud)

android inputstream bitmap bufferedinputstream

5
推荐指数
1
解决办法
6660
查看次数

如何在Android中的LayerDrawable中调整Drawables的大小和位置

我有一个LayerDrawable,它应该显示5个位图.1个背景和4个图标(对于每个LayerDrawable可以是不同的),如Grid.不幸的是,这些图标的宽度与高度不同.我的问题是调整它们的大小,同时保持它们的比例并将它们置于其位置(1-4个图标,5个背景):

==================
|      |  |      |
|   1  |  |   2  |
|------.5 .------|
|------.  .------|
|   3  |  |   4  |
|      |  |      |
==================
Run Code Online (Sandbox Code Playgroud)

如果我调整这些位图的大小,给它们Gravity.CENTER它们将不再适合背景矩形的边界.如果我离开,Gravity.CENTER他们似乎会在我打电话后立即重新调整layerDrawable.setLayerInset(numlayer, left, top, right, bottom).做正确的方法是什么?如何在正确放置时保持比例?到目前为止我还无法理解的是为什么来自BitmapDrawable的getIntrinsicWidth/Height返回的东西(小于)来自原始Bitmap的getWidth/Height.
我尝试了什么:
1.从XML中获取它们,在内部放置一个"虚拟绘图"并用上述结果替换它.2.在我的程序中创建LayerDrawable,传递所有drawables.似乎setLayerInset没有任何影响,或者我只看到背景(我的可绘制数组中的元素0)
3.扩展LayerDrawable并尝试自己跟踪任何事情而没有合理的结果

java android bitmap layer drawable

5
推荐指数
1
解决办法
3884
查看次数

android绘图触摸事件

我正在尝试制作一个应用程序,使用户可以触摸屏幕并根据用户的手指坐标绘制图像.这是我的代码:

public class DrawingBoard extends View {

        Drawable editIcon = getResources().getDrawable(R.drawable.icon);
        Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.background);

        float xPos = 0;
        float yPos = 0; 

        public DrawingBoard (Context context) {
            // TODO Auto-generated constructor stub
            super (context);            
        }
        @Override
        protected void onDraw (Canvas canvas) {
            super.onDraw(canvas);

            canvas.save();
            canvas.drawBitmap(mBitmap, 0, 0, null);
            canvas.translate(xPos, yPos);
            editIcon.draw(canvas);
            canvas.restore();

            invalidate();
        }
        @Override
        public boolean onTouchEvent (MotionEvent event) {

            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN : 
                    xPos = event.getX();
                    yPos = event.getY();
                    break;
            }

            return true;

        } …
Run Code Online (Sandbox Code Playgroud)

android canvas bitmap touch-event

5
推荐指数
1
解决办法
2万
查看次数

Android位图压缩效果不佳

我得到以下输出流代码:

        String output_file = APP_FILE_PATH + "/AudienceSignatures/" + CaptureSignature.this.sessionNumber + ".png";

        final FileOutputStream out = new FileOutputStream(new File( output_file ));
        nBitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
        out.flush();
        out.close();
Run Code Online (Sandbox Code Playgroud)

但似乎结果图像不是我所期待的.你可以看到它有某种线条,我想摆脱那些水平的白线.这可能是什么原因?

在此输入图像描述

非常感谢你给予的任何帮助!:)

更新:这是CaptureSignature.java类,其中'我认为'我遇到了问题:

package com.first.MyApp.drawings;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;

import com.first.Engagia.Camera;
import com.first.Engagia.R;
import com.first.Engagia.R.id;
import com.first.Engagia.R.layout;
import com.first.Engagia.drawings.brush.Brush;
import com.first.Engagia.drawings.brush.CircleBrush; …
Run Code Online (Sandbox Code Playgroud)

compression android bitmap

5
推荐指数
1
解决办法
3399
查看次数

在没有压缩方法的情况下将Bitmap转换为Byte数组

我想通过我的Android应用程序将图像上传到我的网站,所以我想将我的图像转换为Byte [].

我使用了以下代码但不适合我..

    ByteArrayOutputStream bos=new ByteArrayOutputStream();
    bm.compress(CompressFormat.JPEG,0, bos);
    byte[] data=bos.toByteArray();
Run Code Online (Sandbox Code Playgroud)

所以请与我分享任何其他方式将图像转换为字节[] ..

arrays android bitmap

5
推荐指数
1
解决办法
3702
查看次数

为什么有时Bitmaps是相同的对象?

在我的代码中,我正在做这样的事情:

public void doStuff() {
    Bitmap scaledBitmap = decodeFileAndResize(captureFile);
    saveResizedAndCompressedBitmap(scaledBitmap);

    Bitmap rotatedBitmap = convertToRotatedBitmap(scaledBitmap);
    driverPhoto.setImageBitmap(rotatedBitmap);

    if (rotatedBitmap != scaledBitmap) {
        scaledBitmap.recycle();
        scaledBitmap = null;
        System.gc();
    }
}

private Bitmap convertToRotatedBitmap(Bitmap scaledBitmap) throws IOException {
    ExifInterface exifInterface = new ExifInterface(getCaptureFilePath());
    int exifOrientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
    float orientationDegree = getRotationDegree(exifOrientation);
    Matrix rotateMatrix = new Matrix();
    rotateMatrix.postRotate(orientationDegree);

    return Bitmap.createBitmap(scaledBitmap, 0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight(), rotateMatrix, true);
}
Run Code Online (Sandbox Code Playgroud)

一切正常,但是当我发表评论时,if (rotatedBitmap != scaledBitmap) {我有一个关于使用再生Bitmap的错误.

Android是否会在每次Bitmap.createBitmap调用时创建新的Bitmap ,如何避免位图之间的比较?

java android bitmap matrix

5
推荐指数
1
解决办法
665
查看次数