小编way*_*yzz的帖子

为什么db.transaction无法与indexeddb一起使用?

我是使用inxededdb的新手,正在尝试从存储中获取数据。存储中包含数据,但是由于某些原因,代码在尝试设置var tx之后停止。如果我有任何遗漏,请告诉我。这是我尝试获取该书的功能:

function getBook(){
    var tx = db.transaction("book", "readonly");
    var store = tx.objectStore("book");
    var index = store.index("by_getid");

    var request = index.get("<?php echo $_GET['book'] ?>");
    request.onsuccess = function() {
      var matching = request.result;
      if (matching !== undefined) {
         document.getElementById("text-container").innerHTML = matching.text;
      } else {
        alert('no match');
        report(null);
      }
    };
}
Run Code Online (Sandbox Code Playgroud)

解决的版本:

function getBook(){
    var db;
    var request = indexedDB.open("library", 1);  

    request.onsuccess = function (evt) {
    db = request.result; 
    var transaction = db.transaction(["book"]);
    var objectStore = transaction.objectStore("book");
    var requesttrans = objectStore.get(<?php echo …
Run Code Online (Sandbox Code Playgroud)

html php jquery indexeddb

4
推荐指数
1
解决办法
3334
查看次数

在using语句中返回后的位图ArgumentException

所以我目前正在开发一个工作/工作得非常好的图像缩放器,但是当我一次处理太多图像时崩溃程序时它给了我一个OutOfMemoryException.

所以为了解决这个问题,我已经将方法包装在using语句中,这样可以正确处理Bitmaps.

但是我注意到如果我在using语句中返回我的Bitmap,我得到这个"ArgumentException未处理"消息

这是我的ImageResize方法:

 public Bitmap ResizeImage(MemoryStream ms, Size size)
    {
        if (comboBox2.Text == "Pixel")
        {
            using (Bitmap img = new Bitmap(new Bitmap(ms, true), size.Width, size.Height))
            {
                var original = new Bitmap(ms, true);
                Graphics graphic = Graphics.FromImage(img);

                //IRRELEVANT CODE.....

                return img;
            }
        }
        else
        {
            return null;
        }
Run Code Online (Sandbox Code Playgroud)

在这里,当我尝试将图像保存在ImageResize方法之外时:

private void button1_Click(object sender, EventArgs e)
    {
    //IRRELEVANT CODE ...
    img = ResizeImage(memory, new Size(getX(), getY()));
    //IRRELEVANT CODE ...
    img.Save(outputFileName, codec, encoderParams); //<-Exception occurs here
    }
Run Code Online (Sandbox Code Playgroud)

当我删除using语句时,一切都工作得很好,但是我必须使用using块来处理Bitmap,以防止内存泄漏.此外,当我将图像保存在using语句中时,它也可以正常工作,但在我的情况下,这不是解决方案.

我究竟做错了什么?对我来说,似乎没有正确返回Bitmap.

我感谢任何帮助,并提前感谢Ravand

c# resize using bitmap argumentexception

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

标签 统计

argumentexception ×1

bitmap ×1

c# ×1

html ×1

indexeddb ×1

jquery ×1

php ×1

resize ×1

using ×1