我正在尝试从现有URI创建一个位图,旋转位图并将其保存到与JPEG文件相同的位置.在尝试了几个解决方案之后,这是我当前的代码:
try {
// Get the Bitmap from the known URI. This seems to work.
Bitmap bmp = MediaStore.Images.Media.getBitmap(this.getContentResolver(), this.currUserImgUri);
// Rotate the Bitmap thanks to a rotated matrix. This seems to work.
Matrix matrix = new Matrix();
matrix.postRotate(-90);
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
// Create an output stream which will write the Bitmap bytes to the file located at the URI path.
File imageFile = new File(this.currUserImgUri.getPath());
FileOutputStream fOut = new FileOutputStream(imageFile); // --> here …Run Code Online (Sandbox Code Playgroud) 我想从byte []创建一个位图。我的问题是我无法BitmapSource在Unity中使用,如果我使用Unity,则会MemoryStream收到错误消息。
我尝试了这个:
Bitmap bitmap = new Bitmap(512, 424);
var data = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size),
ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Marshal.Copy(arrayData, 0, data.Scan0, arrayData.Length);
bitmap.UnlockBits(data);
Run Code Online (Sandbox Code Playgroud)
它可以工作,但是我得到的位图是错误的。有人可以向我解释原因并为我找到解决方案吗?
我正在开发一个我使用过画布的项目,用户可以触摸将一个位图叠加移动到另一个位图.当用户按下保存按钮时,两个位图都应合并并成为单个位图.我做了所有的事情,现在合并两个位图在XY位置仍然存在.在我的研究中,我发现了以下代码.
private Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, new Matrix(), null);
canvas.drawBitmap(bmp2, new Matrix(), null);
return bmOverlay;
}
Run Code Online (Sandbox Code Playgroud)
但是这段代码在(0,0)位置覆盖了位图.我想在我给定的位置叠加位图.请提出一些解决方案.提前致谢.
在firemonkey xe5中,当我将透明PNG图像保存到位图时,其透明度变为黑色.我怎么能变成白色?
我只是用:
Image1.bitmap.loadfromfile('IMG.png');
image1.bitmap.Savetofile('image.BMP');
Run Code Online (Sandbox Code Playgroud) 我刚刚创建了一些函数来从相机拍摄照片并将结果图像放入imageview.而我发现我的拍摄质量非常糟糕.
以下是一些代码:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
picture.setImageBitmap(photo);
}
}
View.OnClickListener camerabtnlistener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_help_3);
btnPicture = (Button) findViewById(R.id.btnPicture);
picture= (ImageView) findViewById(R.id.picture);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
layoutPic = (RelativeLayout) findViewById(R.id.layoutPic);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME, ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
btnPicture.setOnClickListener(camerabtnlistener);
} …Run Code Online (Sandbox Code Playgroud) 我的应用程序的一部分是绘制图形表单的草稿,主要是用户输入表单,有许多编辑框.我绘制位图并保存为PNG,报告过程的所有部分,因此没有任何内容被绘制到应用程序表单.我绘制所有控件,编辑框,单选按钮,复选框......
绘图的最长部分当然是绘制编辑框,因为它们数量巨大.我有一个典型的过程,在大约70K表格上绘制1M编辑框.
我画了一个非常简单的编辑框:
我附加了一个简单的Edit控件的屏幕截图,其中包含Zoomed,因此可以看到额外的左侧和顶部线条.
这是DrawEdit的代码,它绘制了1M Edit框,需要20秒.反正是为了加快这个过程吗?
procedure DrawEdit(myCanvas:TCanvas; vLeft, vTop, vWidth, vHeight: integer; const vText: string; vCenterText:boolean=false);
begin
// basic rectangle
pPoint.x := vLeft; pPoint.Y := vTop;
myCanvas.Pen.Width := 1;
myCanvas.PenPos := pPoint;
myCanvas.Pen.Color := $0099A8AC;
myCanvas.LineTo(vLeft + vWidth, vTop);
myCanvas.LineTo(vLeft + vWidth, vTop + 1);
myCanvas.Pen.Color := $00E2EFF1;
myCanvas.LineTo(vLeft + vWidth, vTop + vHeight - 1);
myCanvas.LineTo(vLeft, vTop + vHeight - 1);
myCanvas.Pen.Color := $0099A8AC;
myCanvas.LineTo(vLeft, vTop);
// again top border
pPoint.x := vLeft …Run Code Online (Sandbox Code Playgroud) 我想将我的Linearlayout保存为bmp.
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout_QrCode" >
<Space
android:layout_width="15dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Space
android:layout_width="match_parent"
android:layout_height="15dp" />
<ImageView
android:layout_width="185dp"
android:layout_height="185dp"
android:id="@+id/imageView_qrcode" />
<Space
android:layout_width="match_parent"
android:layout_height="15dp" />
</LinearLayout>
<RelativeLayout
android:layout_width="417dp"
android:layout_height="match_parent" >
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:id="@+id/space2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/textView_QrSticker_label"
android:layout_alignParentStart="true"
android:layout_above="@+id/space2"
android:textStyle="bold"
android:textSize="40sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/textView_QrSticker_serial"
android:layout_below="@+id/space2"
android:layout_alignParentStart="true"
android:textSize="30sp" />
</RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
因此,我使用以下代码执行此操作:
public Bitmap viewToBitmap(View view) {
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用开发LPR系统Aforge.net,我想对图像应用滤镜,如下所示:
Bitmap a = new Bitmap(@"C:\Users\Public\Pictures\Sample Pictures\1.png");
SobelEdgeDetector filter = new SobelEdgeDetector();
filter.ApplyInPlace(a);
pictureBox1.Image = a;
Run Code Online (Sandbox Code Playgroud)
但是运行后我得到了这个错误:
Source pixel format is not supported by the filter.
Run Code Online (Sandbox Code Playgroud)
我在aforge.net中是新手。
SqliteDatabase我的申请中有一个。在此数据库中,我保存了Sting和Blob(用于保存图像)。该图像使用byte []保存在应用程序中。我借助以下代码将该图像转换为Bitmap:
byte[] Recycler_imageByte;
Bitmap Recycler_theImage;
holder.Recycler_imageByte = data.get(position).getKey_image();
ByteArrayInputStream imageStream = new ByteArrayInputStream(holder.Recycler_imageByte);
holder.Recycler_theImage = BitmapFactory.decodeStream(imageStream);
Run Code Online (Sandbox Code Playgroud)
我想在Glidelibary中显示此图像,我编写了以下代码:
Glide.with(context).load(holder.Recycler_theImage).asBitmap().into(holder.Recycler_adapter_image);
Run Code Online (Sandbox Code Playgroud)
但是,当我运行应用程序时,显示以下错误:
03-15 10:23:14.311 22440-22440/com.tellfa.dastanak E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tellfa.dastanak, PID: 22440
java.lang.IllegalArgumentException: Unknown type class android.graphics.Bitmap. You must provide a Model of a type for which there is a registered ModelLoader, if you are using a custom model, you must first call Glide#register with a ModelLoaderFactory for your custom model class …Run Code Online (Sandbox Code Playgroud) 我在互联网上找到这个功能来裁剪图像,如果pictureBox源sizeMode是正常的,它会很好.但是当pictureBox sizeMode被缩放时,它仍然像普通的sizeMode一样被克隆.
如何克隆与缩放的pictureBox相同?不是原始普通位图的大小?
public static Bitmap CropBitmap(Bitmap bitmap, int x, int y, int w, int h)
{
Rectangle rect = new Rectangle(x, y, w, h);
Bitmap cropped = bitmap.Clone(rect, bitmap.PixelFormat);
return cropped;
}
Run Code Online (Sandbox Code Playgroud)
并使用这样的
pictureBox2.Image = CropBitmap((Bitmap)pictureBox1.Image.Clone(), 35, 0, 110, 150);
Run Code Online (Sandbox Code Playgroud)