canvas.drawBitmap坏的位置和大小(而不是放在正确的图像) [英] canvas.drawBitmap bad Location and size (not placing image correctly)

查看:676
本文介绍了canvas.drawBitmap坏的位置和大小(而不是放在正确的图像)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,并预先感谢,我希望是好写,因为我做了一个简单的应用程序,应只在一个团结两个以上的位图,问题是出在哪个位置的位图和尺寸辅错,真理不会找到为给我的逻辑背后这很好,实际上它是一个TENGO阙code已经在C#和Java的PASE明明是不同的罪恶,有相同的原则。

Hi everyone and beforehand thanks, I hope are well write because I am doing a simple application that should unite more than two bitmaps in only one, the problem is in which position bitmaps and size Side wrong, and the truth will not find the back for logic given to me that 's fine, in fact it is a Tengo Que code already in c # and PASE java obviously is different sin but have the same principle .

我不知道你必须让这些图像的位置和大小的出这句话在code,

I wonder if you have the way to make the position and size of these images out as this saying in the code,

对不起,我英文不好

CODIGO JAVA

CODIGO JAVA

漆mPaint;

    Bitmap image1=BitmapUtils.decodeBase64(Lie.GeFondo().GetImagen());
    Bitmap image2=BitmapUtils.decodeBase64(Utilidades.getImagenTomadabase64());
    Bitmap image3=BitmapUtils.decodeBase64(Lie.GetBanner().GetImagen());
    Bitmap result = Bitmap.createBitmap(image1.getWidth(), image1.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    Rect srcRect = new Rect(0, 0, image1.getWidth(), image1.getHeight());
    Rect dstRect = new Rect(srcRect);
    Rect srcRect1 = new Rect( Foto.GetPosicionDeItems().Getx(),Foto.GetPosicionDeItems().Gety(),Foto.GetTamano().GetWidth(), Foto.GetTamano().GeHeight());
    Rect srcRect3 = new Rect( Lie.GetBanner().GetPosicionDeItems().Getx(), Lie.GetBanner().GetPosicionDeItems().Gety() ,Lie.GetBanner().GetTamano().GetWidth(), Lie.GetBanner().GetTamano().GeHeight());


    Rect srcRect2 = new Rect(0,0,image2.getWidth(), image2.getHeight());
    Rect srcRect4 = new Rect(0,0,image3.getWidth(), image3.getHeight());

    dstRect.offset(0, 0);
    canvas.drawBitmap(image1, srcRect, dstRect, null);
    dstRect.offset(image1.getWidth(), 0);
    srcRect1.offset(0, 0);
    canvas.drawBitmap(image2,srcRect2 ,srcRect1 , null);

    srcRect1.offset(image2.getWidth(), 0);
    srcRect3.offset(0, 0);
    canvas.drawBitmap(image3,srcRect4 ,srcRect3 , null);
    srcRect3.offset(image3.getWidth(), 0);
    myImage = (ImageView) findViewById(R.id.imageView);
    myImage.setImageBitmap(result);

在Java中
请参阅Java图片 http://i58.tinypic.com/1zywm5u.jpg

C#code

忽略的foreach。

Ignore the foreach.

System.Drawing.Bitmap北=(System.Drawing.Bitmap)Lienzo.Fondo.Imagen;
            System.Drawing.Graphics R = System.Drawing.Graphics.FromImage(BAC);

System.Drawing.Bitmap Bac = (System.Drawing.Bitmap)Lienzo.Fondo.Imagen; System.Drawing.Graphics r = System.Drawing.Graphics.FromImage(Bac);

        if (Lienzo.Fotos != null)
        {
            if (Lienzo.Fotos.Count > 0)
            {
                int i = 0;
                foreach (RADMLIB.Items item in Lienzo.Fotos)
                {

                    System.Drawing.Bitmap img = (System.Drawing.Bitmap)Lista[i];
                    r.DrawImage(img, item.PosicionDeItems.X, item.PosicionDeItems.Y, item.Tamano.Width, item.Tamano.Height);
                    i++;
                }
            }
        }
        if (Lienzo.Banner != null)
        {
            r.DrawImage((System.Drawing.Bitmap)Lienzo.Banner.Imagen, Lienzo.Banner.PosicionDeItems.X, Lienzo.Banner.PosicionDeItems.Y, Lienzo.Banner.Tamano.Width, Lienzo.Banner.Tamano.Height);
        }

        return Bac;

看到C#图片 http://i61.tinypic.com/s61wlh.jpg

推荐答案

我找到了解决办法
采用矩阵集合地点和规模的x,y

I found the solution using Matrix for set location and scale x,y

    Bitmap image1=BitmapUtils.decodeBase64(Lie.GeFondo().GetImagen());
    Bitmap image2=BitmapUtils.getResizedBitmap(BitmapUtils.decodeBase64(Utilidades.getImagenTomadabase64()),Foto.GetTamano().GetWidth(),Foto.GetTamano().GeHeight());
    Bitmap image3=BitmapUtils.getResizedBitmap(BitmapUtils.decodeBase64(Lie.GetBanner().GetImagen()),Lie.GetBanner().GetTamano().GetWidth(),Lie.GetBanner().GetTamano().GeHeight());
    Bitmap result = Bitmap.createBitmap(image1.getWidth(), image1.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);//Create the canvas to your image
    Rect srcRect = new Rect(0, 0, image1.getWidth(), image1.getHeight());
    Rect dstRect = new Rect(srcRect);
    Matrix matrix = new Matrix ();
    Matrix matrix2 = new Matrix ();
    matrix.postTranslate( Foto.GetPosicionDeItems().Getx(),Foto.GetPosicionDeItems().Gety());
    matrix2.postTranslate( Lie.GetBanner().GetPosicionDeItems().Getx(),Lie.GetBanner().GetPosicionDeItems().Gety());
    canvas.drawBitmap(image1, srcRect, dstRect, null);
    dstRect.offset(image1.getWidth(), 0);
    canvas.drawBitmap(image2,matrix , null);
    canvas.drawBitmap(image3,matrix2 , null);

getResizedBitmap法

getResizedBitmap Method

公共静态位图getResizedBitmap(位图BM,诠释newHeight,诠释newWidth){

public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {

    int width = bm.getWidth();

    int height = bm.getHeight();

    float scaleWidth = ((float) newWidth) / width;

    float scaleHeight = ((float) newHeight) / height;



    Matrix matrix = new Matrix();



    matrix.postScale(scaleWidth, scaleHeight);



    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);

    return resizedBitmap;

}

看到图片

<一个href=\"https://lh4.ggpht.com/LXW8kVc3U8qQUHnORI-3H4H-A2hjq92y_oEDsKIs-iBDkVBFTgjGP03xFReCeuyLlg=h900-rw\" rel=\"nofollow\">https://lh4.ggpht.com/LXW8kVc3U8qQUHnORI-3H4H-A2hjq92y_oEDsKIs-iBDkVBFTgjGP03xFReCeuyLlg=h900-rw

这篇关于canvas.drawBitmap坏的位置和大小(而不是放在正确的图像)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆