标签: bitmap

如何在OCAML中读取位图?

我想使用OCAML读取位图文件(来自文件系统)并将像素(颜色)存储在具有位图的第二维的数组内,每个像素将占用数组中的一个单元.

我找到了函数Graphics.dump_image image - > color array array 但它不能从文件中读取.

ocaml bitmap image-processing

6
推荐指数
2
解决办法
4068
查看次数

Android - 读取没有alpha的PNG图像并解码为ARGB_8888

我尝试从sdcard(在模拟器中)读取图像,然后用.创建一个Bitmap图像

BitmapFactory.decodeByteArray

方法.我设置了选项:

options.inPrefferedConfig = Bitmap.Config.ARGB_8888
options.inDither = false

然后我将像素提取到ByteBuffer中.

ByteBuffer buffer = ByteBuffer.allocateDirect(width*height*4)
bitmap.copyPixelsToBuffer(buffer)

我在JNI中使用此ByteBuffer将其转换为RGB格式并想要计算它.

但总是我得到错误的数据 - 我在不修改ByteBuffer的情况下进行测试.我唯一要做的就是将它放入JNI的本机方法中.然后将其转换为a unsigned char*并将其转换回a,ByteBuffer然后将其返回到Java.

unsigned char* buffer = (unsinged char*)(env->GetDirectBufferAddress(byteBuffer))
jobject returnByteBuffer = env->NewDirectByteBuffer(buffer, length)

在显示图像之前,我得到了数据

bitmap.copyPixelsFromBuffer( buffer )

但其中有错误的数据.

我的问题是,如果这是因为图像内部转换为RGB 565或这里有什么问题?

.....

得到答案:

- >>>是的,它在内部转换为RGB565.

有人知道如何使用ARGB8888像素格式从PNG创建这样的位图图像吗?

如果有人有想法,那就太好了!

png android image bitmap argb

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

Python ctype help:使用C unsigned char指针

我的第一篇文章,请轻松一下.:)我对Python也有点新意,但我喜欢到目前为止看到的内容.我想要做的是访问ac库,允许我通过Python打印到收据打印机.我正在使用ctypes在Python中创建一个包装器,一切都很好,除了两个函数.在这里我们的原型:

int C56_api_printer_write(int printer, unsigned char * data, int size, unsigned long timeout_ms);
int C56_api_printer_read(int printer, unsigned char * data, int size, unsigned long timeout_ms);
Run Code Online (Sandbox Code Playgroud)

我的问题是使用ctypes写入和读取unsigned char指针.我必须在Python中读取位图文件并将数组传递给write函数,或者在读取的情况下,我需要将该指针作为整数数组读取.

在过去的几个小时里,我一直在为这个问题挣扎,所以我希望专家可以通过发布一个如何实现这一目标的简单例子来提供帮助.

谢谢!

python arrays ctypes pointers bitmap

6
推荐指数
2
解决办法
6502
查看次数

从资源中绘制位图而不是另一个

我有两个位图,背景和前景.如何在不使用其他Canvas的情况下在背景上绘制位图前景?

解:

1)首先使用附加选项ARGB_8888从资源创建位图

BitmapFactory.Options options = new BitmapFactory.Options();  
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Run Code Online (Sandbox Code Playgroud)

2)声明位图

Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.background, options);  
Bitmap foreground = BitmapFactory.decodeResource(getResources(), R.drawable.foreground, options);
Run Code Online (Sandbox Code Playgroud)

3)在onDraw()函数内部绘制图形

protected void onDraw(Canvas canvas)    
{  
    canvas.drawColor(Color.White);

    Paint paint = new Paint();
    canvas.drawBitmap(background, 0, 0, paint);
    paint.setXfermode( new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
    canvas.drawBitmap(foreground, 0, 0, paint); 
}
Run Code Online (Sandbox Code Playgroud)

正如Soxxeh所说,这是非常好的信息来源:http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Xfermodes.html

android bitmap draw android-canvas

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

在没有OutOfMemoryError或缩减的情况下在Android中旋转图像

基本上我正在尝试在Android应用程序中旋转位图(来自图像).我想这样做的原因是,即使垂直拍摄,从相机拍摄的照片(通过意图)也会水平显示,并且方向在图像上保留为元数据.如果错了,请纠正我.然而问题是,如果在装有相当好的相机的手机上拍摄时,图像将占用大量内存,而且我没有找到旋转和保存它的方法而没有获得OutOfMemoryError的风险.下面的代码是我的地方:

  1. 加载图像
  2. 检查是否需要旋转
  3. 加载缩小版本以在ImageView中显示
  4. 如有必要,旋转小图像
  5. 在一个单独的线程; 加载,旋转和保存图像,以便将来不需要

对于应用程序而言,保持图像的分辨率非常重要,但欢迎任何带编码的技巧.我已经在互联网上搜索了几天,找不到比我已经实现的更多的内容.这里有另一个主题,但似乎没有任何解决方案.希望你能帮忙.

    public Bitmap getBitmap(final Context c) {
    if (bitmap != null)
        return bitmap;

    final int rotate = necessaryRotation(c, file);
    // if(rotate != 0) rotateImageFile(c, rotate);

    try {
        // Get scaled version
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(file, options);
        options.inSampleSize = calcInSampleSize(options, 1024, 1024);
        options.inJustDecodeBounds = false;
        bitmap = BitmapFactory.decodeFile(file, options);

        // rotate?
        bitmap = rotateImage(c,bitmap,rotate);

        System.out.println("Bitmap loaded from file: size="
                + bitmap.getWidth() + "," + bitmap.getHeight());

        System.gc();
    } catch (Exception …
Run Code Online (Sandbox Code Playgroud)

android bitmap rotation out-of-memory

6
推荐指数
1
解决办法
3348
查看次数

将位图写入/读取到tfilestream

我搜索和搜索,似乎找不到任何描述我在delphi代码中做什么的东西.solutins有时很接近,但不够接近,我无法弄明白.所以我在这里问...

我有很多位图,我正在从屏幕截图中退回.我一直在做的是保存到bitmaps_001.bmp,但它需要很多存储空间,所以我升级了例程以保存为bitmaps_001.png,这样可以节省更多空间,但现在我想保存到一个文件,一个tfilestream,并使用tprogressbar从中读取,我可以在屏幕上显示图像时左/右拖动.

基本上,我试图完成以下内容:

procedure SaveBMPtoStream(st: tfilestream; bmp: tbitmap);
procedure ReadBMPfrStream(st: tfilestream; bmp: tbitmap; bnum: integer);
Run Code Online (Sandbox Code Playgroud)

到目前为止,代码(下面)按原样工作,(它在按下tbutton时写入和读取一个位图图像)但我只能写一个位图图像.我需要将每个会话所需的尽可能多的图像实时写入tfilestream,可能使用ttimer控件并让它写入尽可能多的图像直到我按下停止按钮.我该怎么做才能修改下面的代码来解决这个问题?谢谢.

我正在运行Windows XP,附加到具有NTFS文件系统的外部usb3.0 1tb驱动器.

type
  TMS = TFileStream; 
var
  MS:  TMS; 
  pos: int64;   // bnum for 0-99,999 images.
  sz:  integer; // size of the image/stream ?

//write bitmaps to stream
procedure SaveBMPtoStream(ms: TMS; Bmp: TBitmap; bnum: integer);
begin
  // create (or append to) stream
  if fileexists('d:\streams\s.stm') then MS := TFileStream.Create('d:\streams\s.stm', fmOpenReadWrite)
    else MS := TFileStream.Create('d:\streams\s.stm', fmCreate);
  //sz:=MS.Size; pos:=ms.Position;
  bmp.SaveToStream(MS); 
  // free stream
  ms.free;
end;

//read …
Run Code Online (Sandbox Code Playgroud)

delphi bitmap tfilestream

6
推荐指数
1
解决办法
5161
查看次数

使用蓝牙热敏打印机从Android应用程序打印图像?


我一直试图获得一张图片,但到目前为止我还没有成功.

该打印机是本地制造的2英寸热敏打印机,打印分辨率为8点/ mm,384点/线,203 dpi.
该打印机基于具有"NXP 2388 ARM v7 Microproc."的板,其内存闪存大小为512 KB,RAM:128 KB,接收缓冲区大小为16KB.

我一直关注这个问题.

问题:我尝试打印的图像是576x95 res. 在此输入图像描述

打印图像(有一些错误LED点亮并调试蜂鸣器噪音:D)但图像的方向是垂直的而不是水平打印; 也是在页面的最左侧,图像的顶部被截断

假设在这里我没有通过一些标志(同时使"数据包")与我拥有的打印机兼容.

我之前没有从事蓝牙打印,所以任何帮助都很明显:)

我现有的主要活动:

public class MainActivity extends Activity 
    {
    // will show the statuses
    TextView myLabel;
    // will enable user to enter any text to be printed
    EditText myTextbox;
    EditText devName;
    public TableLayout tl2; 
    String devid;
    String[] pName;
    String[] LODQTY;
    String[] rte;
    String[] stk;
    String[] oQty;
    String[] oVal;
    String[] fQty;

    BitSet dots;
    int mWidth;
    int mHeight;
    String mStatus;
    String TAG = …
Run Code Online (Sandbox Code Playgroud)

java android bytearray bitmap bitmapfactory

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

如何从VectorDrawable获取位图

馅饼

我还在努力解决几天前我遇到的问题,但我还没有找到解决方案.但是,我一步一步到达那里.现在我遇到了另一个障碍.

我试图Bitmap.getpixel(int x, int y)返回Color用户使用的内容OnTouchListener.馅饼是一种VectorDrawable资源,vectordrawable.xml我不需要对像素数据做任何事情,我只需要测试它.所以我做了一个TextView会吐了出来的Color.

public class MainActivity extends AppCompatActivity {
    ImageView imageView;
    TextView textView;

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

        imageView = (ImageView) findViewById(R.id.imageView);
        textView = (TextView) findViewById(R.id.textView);

        imageView.setOnTouchListener(imageViewOnTouchListener);
    }

    View.OnTouchListener imageViewOnTouchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent event) {

            Drawable drawable = ((ImageView)view).getDrawable();
            //Bitmap bitmap = BitmapFactory.decodeResource(imageView.getResources(),R.drawable.vectordrawable);
            Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();

            int x = (int)event.getX();
            int y = …
Run Code Online (Sandbox Code Playgroud)

android bitmap getpixel ontouchlistener android-vectordrawable

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

如何使用不同屏幕尺寸的油漆在位图上写出像素完美文本

其实我要创建名片.我有不同的名片样本.用户可以选择卡片及其颜色.我在位图上写文字时遇到了麻烦.文本未根据不同的屏幕尺寸进行调整.我在Samasung galaxy s5和nexus 5上进行了测试.两款设备的分辨率都是1080x1920.但是有不同的ppi.Sampe图片:

在此输入图像描述

我正在使用此代码:

     private void customCard(int drawableId, int color) {

    bm1 = null;
    newBitmap = null;
    try {
        bm1 = BitmapFactory.decodeResource(getResources(), drawableId);
        Bitmap.Config config = bm1.getConfig();
        if (config == null) {
            config = Bitmap.Config.ARGB_8888;
        }
        newBitmap = Bitmap.createBitmap(bm1.getWidth(), bm1.getHeight(), config);

        paintText = new Paint(Paint.ANTI_ALIAS_FLAG);

        newCanvas = new Canvas(newBitmap);
        newCanvas.drawBitmap(bm1, 0, 0, null);
        rectText = new Rect();


        ivCard.setImageBitmap(newBitmap);
    } catch (Exception e) {
        e.printStackTrace();
    }


    if (theme == 0) {
        //Set First Name
        if (firstName != null && !firstName.equals("")) …
Run Code Online (Sandbox Code Playgroud)

android bitmap

6
推荐指数
0
解决办法
146
查看次数

保存位图并使用graphics.copyFromScreen parallel-y时出现InvalidOperationException

我正在编写一个应用程序来捕获使用该CopyFromScreen方法的屏幕,并且还想保存我捕获的图像以通过我的本地网络发送.所以,我正在尝试将捕获的屏幕存储在一个位图上,并在两个线程上保存另一个位图,即先前捕获的屏幕.

然而,这是抛出一个InvalidOperationException,说对象目前在其他地方使用.System.Drawing.dll抛出异常.
我尝试过锁定,并使用单独的位图来保存和捕获屏幕.我如何阻止这种情况发生?相关代码:

Bitmap ScreenCapture(Rectangle rctBounds)
{
    Bitmap resultImage = new Bitmap(rctBounds.Width, rctBounds.Height);

    using (Graphics grImage = Graphics.FromImage(resultImage))
    {
        try
        {
            grImage.CopyFromScreen(rctBounds.Location, Point.Empty, rctBounds.Size);
        }
        catch (System.InvalidOperationException)
        {
            return null;
        }
    }
    return resultImage;
}

void ImageEncode(Bitmap bmpSharedImage)
{
    // other encoding tasks
    pictureBox1.Image = bmpSharedImage;
    try
    {
        Bitmap temp = (Bitmap)bmpSharedImage.Clone();
        temp.Save("peace.jpeg");
    }
    catch (System.InvalidOperationException)
    {
        return;
    }
}

private void button1_Click(object sender, EventArgs e)
{
    timer1.Interval = 30;
    timer1.Start();
}

Bitmap newImage = null; …
Run Code Online (Sandbox Code Playgroud)

c# graphics multithreading bitmap

6
推荐指数
1
解决办法
386
查看次数